Skip to content

Commit 795014b

Browse files
authored
Inline native Switch props in JSX (#59481)
Summary: Remove the intermediate platform prop objects so native Switch prop overrides are explicit in the JSX on both platforms. Behaviour is unchanged. Changelog: [Internal] Reviewed By: christophpurrer Differential Revision: D127565462 Pull Request resolved: #59481
1 parent 3d3a339 commit 795014b

1 file changed

Lines changed: 26 additions & 34 deletions

File tree

  • packages/react-native/Libraries/Components/Switch

‎packages/react-native/Libraries/Components/Switch/Switch.js‎

Lines changed: 26 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -238,59 +238,51 @@ const Switch: component(
238238
if (Platform.OS === 'android') {
239239
const {onTintColor, tintColor, ...androidProps} = restProps;
240240

241-
const platformProps = {
242-
accessibilityState: _accessibilityState,
243-
enabled: _disabled !== true,
244-
on: value === true,
245-
style,
246-
thumbTintColor: thumbColor,
247-
trackColorForFalse: trackColorForFalse,
248-
trackColorForTrue: trackColorForTrue,
249-
trackTintColor: value === true ? trackColorForTrue : trackColorForFalse,
250-
};
251-
252241
return (
253242
<AndroidSwitchNativeComponent
254243
{...androidProps}
255-
{...platformProps}
256244
accessibilityRole={props.accessibilityRole ?? 'switch'}
245+
accessibilityState={_accessibilityState}
246+
enabled={_disabled !== true}
247+
on={value === true}
257248
onChange={handleChange}
258249
onResponderTerminationRequest={returnsFalse}
259250
onStartShouldSetResponder={returnsTrue}
260251
ref={ref}
252+
style={style}
253+
thumbTintColor={thumbColor}
254+
trackColorForFalse={trackColorForFalse}
255+
trackColorForTrue={trackColorForTrue}
256+
trackTintColor={value === true ? trackColorForTrue : trackColorForFalse}
261257
/>
262258
);
263259
} else {
264-
const platformProps = {
265-
accessibilityState: _accessibilityState,
266-
disabled,
267-
onTintColor: trackColorForTrue,
268-
style: StyleSheet.compose(
269-
{alignSelf: 'flex-start' as const},
270-
StyleSheet.compose(
271-
style,
272-
ios_backgroundColor == null
273-
? null
274-
: {
275-
backgroundColor: ios_backgroundColor,
276-
borderRadius: 16,
277-
},
278-
),
279-
),
280-
thumbTintColor: thumbColor,
281-
tintColor: trackColorForFalse,
282-
value: value === true,
283-
};
284-
285260
return (
286261
<SwitchNativeComponent
287262
{...restProps}
288-
{...platformProps}
289263
accessibilityRole={props.accessibilityRole ?? 'switch'}
264+
accessibilityState={_accessibilityState}
265+
disabled={disabled}
290266
onChange={handleChange}
291267
onResponderTerminationRequest={returnsFalse}
292268
onStartShouldSetResponder={returnsTrue}
269+
onTintColor={trackColorForTrue}
293270
ref={ref}
271+
style={StyleSheet.compose(
272+
{alignSelf: 'flex-start' as const},
273+
StyleSheet.compose(
274+
style,
275+
ios_backgroundColor == null
276+
? null
277+
: {
278+
backgroundColor: ios_backgroundColor,
279+
borderRadius: 16,
280+
},
281+
),
282+
)}
283+
thumbTintColor={thumbColor}
284+
tintColor={trackColorForFalse}
285+
value={value === true}
294286
/>
295287
);
296288
}

0 commit comments

Comments
 (0)