Skip to content

Commit

Permalink
fix: use new Switch API from RN >= 0.57. fixes #571
Browse files Browse the repository at this point in the history
  • Loading branch information
satya164 committed Nov 5, 2018
1 parent dcc5bf1 commit 4aa7add
Showing 1 changed file with 21 additions and 6 deletions.
27 changes: 21 additions & 6 deletions src/components/Switch.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
/* @flow */
import * as React from 'react';

import * as React from 'react';
import { grey400, grey800, grey50, white, black } from '../styles/colors';
import { Switch as NativeSwitch, Platform } from 'react-native';
import setColor from 'color';
import { withTheme } from '../core/theming';
import type { Theme } from '../types';

// eslint-disable-next-line import/no-unresolved
const { version } = require('ReactNativeVersion');

type Props = React.ElementProps<NativeSwitch> & {
/**
* Disable toggling the switch.
Expand Down Expand Up @@ -85,12 +88,12 @@ class Switch extends React.Component<Props> {
onValueChange,
color,
theme,
...props
...rest
} = this.props;

const checkedColor = color || theme.colors.accent;

const trackTintColor =
const onTintColor =
Platform.OS === 'ios'
? checkedColor
: disabled
Expand Down Expand Up @@ -121,14 +124,26 @@ class Switch extends React.Component<Props> {
? grey400
: grey50;

const props =
version.major === 0 && version.minor <= 56
? {
onTintColor,
thumbTintColor,
}
: {
thumbColor: thumbTintColor,
trackColor: {
true: onTintColor,
},
};

return (
<NativeSwitch
{...props}
value={value}
disabled={disabled}
onTintColor={trackTintColor}
thumbTintColor={thumbTintColor}
onValueChange={disabled ? undefined : onValueChange}
{...props}
{...rest}
/>
);
}
Expand Down

0 comments on commit 4aa7add

Please sign in to comment.