您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

Switch.tsx 1.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. import React from 'react';
  2. import { ColorValue, StyleProp } from 'react-native';
  3. import { Switch as NativeSwitch } from 'react-native-paper';
  4. import { ISwitchProps } from '../types';
  5. import {
  6. DISABLED_TRACK_COLOR,
  7. ENABLED_TRACK_COLOR,
  8. THUMB_COLOR
  9. } from './switchStyles';
  10. interface IProps extends ISwitchProps {
  11. /**
  12. * Id for the switch.
  13. */
  14. id?: string;
  15. /**
  16. * Custom styles for the switch.
  17. */
  18. style?: Object;
  19. /**
  20. * Color of the switch button.
  21. */
  22. thumbColor?: ColorValue;
  23. /**
  24. * Color of the switch background.
  25. */
  26. trackColor?: Object;
  27. }
  28. const Switch = ({
  29. checked,
  30. disabled,
  31. id,
  32. onChange,
  33. thumbColor = THUMB_COLOR,
  34. trackColor = {
  35. true: ENABLED_TRACK_COLOR,
  36. false: DISABLED_TRACK_COLOR
  37. },
  38. style
  39. }: IProps) => (
  40. <NativeSwitch
  41. disabled = { disabled }
  42. id = { id }
  43. ios_backgroundColor = { DISABLED_TRACK_COLOR }
  44. onValueChange = { onChange }
  45. style = { style as StyleProp<object> }
  46. thumbColor = { thumbColor }
  47. trackColor = { trackColor }
  48. value = { checked } />
  49. );
  50. export default Switch;