Switch.js 1.0 KB

12345678910111213141516171819202122232425262728293031323334
  1. /**
  2. * 自定义Switch组件
  3. * @邠心vbe on 2023/08/30
  4. */
  5. import React from 'react';
  6. import { Switch, SwitchProps, Text, View } from 'react-native';
  7. import Animated from 'react-native-reanimated';
  8. import utils from '../utils/utils';
  9. //const switchStyle = { false: "#B2B2B2", true: colorAccent };
  10. export default SwitchBase = (props, {...SwitchProps}) => {
  11. const colors = utils.hexColorToRgb(colorAccent);
  12. var thumbColor = null;
  13. var trackColor = { false: "#B2B2B2", true: colorAccent }
  14. if (!isIOS) {
  15. thumbColor = (props.value ? utils.getRgbaColor(colors, 0.9) : "#EBEDEC")
  16. trackColor = {false: "#B2B2B2", true: utils.getRgbaColor(colors, 0.3)}
  17. }
  18. return (
  19. <Animated.View style={ui.flexc}>
  20. <Switch
  21. {...props}
  22. trackColor={trackColor}
  23. thumbColor={thumbColor}
  24. />
  25. {/* <Switch
  26. {...props}
  27. />
  28. <Text style={{color: utils.getRgbaColor(colors, 0.9)}}>■■■</Text>
  29. <Text style={{color: utils.getRgbaColor(colors, 0.3)}}>■■■</Text> */}
  30. </Animated.View>
  31. );
  32. }