Skip to content

Commit 911db96

Browse files
committed
add support for theming the Switches we put in tableview cells
1 parent 3d302f6 commit 911db96

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

source/views/components/cells/toggle.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import * as React from 'react'
33
import {Switch} from 'react-native'
44
import {Cell} from 'react-native-tableview-simple'
5+
import * as c from '../colors'
56

67
type PropsType = {
78
label: string,
@@ -10,10 +11,13 @@ type PropsType = {
1011
}
1112

1213
export function CellToggle({value, onChange, label}: PropsType) {
13-
return (
14-
<Cell
15-
cellAccessoryView={<Switch onValueChange={onChange} value={value} />}
16-
title={label}
14+
let toggle = (
15+
<Switch
16+
onTintColor={c.switchTintOn}
17+
onValueChange={onChange}
18+
value={value}
19+
tintColor={c.switchTintOff}
1720
/>
1821
)
22+
return <Cell cellAccessoryView={toggle} title={label} />
1923
}

source/views/components/colors.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,22 @@ export const iosPushButtonCellForeground = firstReadable(
270270
[accent, sto.black, sto.white],
271271
)
272272

273+
// Background color when the switch is turned on.
274+
export const switchTintOn = Platform.select({
275+
ios: accent,
276+
// don't set on Android so the platform can pick the right shades from the theming system
277+
android: undefined,
278+
})
279+
// Border color on iOS and background color on Android when the switch is turned off.
280+
export const switchTintOff = undefined
281+
// Color of the foreground switch grip. If this is set on iOS, the switch grip will lose its drop shadow.
282+
export const switchThumbTint = Platform.select({
283+
// don't set on ios so we keep the drop shadow
284+
ios: undefined,
285+
// don't set on Android so the platform can pick the right shades from the theming system
286+
android: undefined,
287+
})
288+
273289
export const androidListHeaderBackground = sto.white
274290
export const androidListHeaderForeground = firstReadable(
275291
androidListHeaderBackground,

0 commit comments

Comments
 (0)