Use Switch command from JavaScript

Summary: Changelog: Switch on iOS now uses command instead of `setNativeProps`.

Reviewed By: lunaleaps

Differential Revision: D17714895

fbshipit-source-id: 0e8784fc1d0a57c563b0a4c038febdc0320af11e
This commit is contained in:
Samuel Susla
2019-11-04 07:44:10 -08:00
committed by Facebook Github Bot
parent b6a23d8793
commit 4eb8a951ff
2 changed files with 19 additions and 4 deletions
+5 -3
View File
@@ -18,11 +18,13 @@ const StyleSheet = require('../../StyleSheet/StyleSheet');
import AndroidSwitchNativeComponent, {
Commands as AndroidSwitchCommands,
} from './AndroidSwitchNativeComponent';
import SwitchNativeComponent, {
Commands as SwitchCommands,
} from './SwitchNativeComponent';
import type {ColorValue} from '../../StyleSheet/StyleSheetTypes';
import type {SyntheticEvent} from '../../Types/CoreEventTypes';
import type {ViewProps} from '../View/ViewPropTypes';
import SwitchNativeComponent from './SwitchNativeComponent';
type SwitchChangeEvent = SyntheticEvent<
$ReadOnly<{|
@@ -208,7 +210,7 @@ class Switch extends React.Component<Props> {
const nativeProps = {};
const value = this.props.value === true;
if (this._lastNativeValue !== value && typeof value === 'boolean') {
if (this._lastNativeValue !== value) {
nativeProps.value = value;
}
@@ -223,7 +225,7 @@ class Switch extends React.Component<Props> {
nativeProps.value,
);
} else {
this._nativeSwitchRef.setNativeProps(nativeProps);
SwitchCommands.setValue(this._nativeSwitchRef, nativeProps.value);
}
}
}
@@ -13,8 +13,10 @@
import type {BubblingEventHandler, WithDefault} from '../../Types/CodegenTypes';
import type {ColorValue} from '../../StyleSheet/StyleSheetTypes';
import type {ViewProps} from '../View/ViewPropTypes';
import * as React from 'react';
import codegenNativeComponent from '../../Utilities/codegenNativeComponent';
import codegenNativeCommands from 'react-native/Libraries/Utilities/codegenNativeCommands';
import type {HostComponent} from '../../Renderer/shims/ReactNativeTypes';
type SwitchChangeEvent = $ReadOnly<{|
@@ -40,6 +42,17 @@ type NativeProps = $ReadOnly<{|
onChange?: ?BubblingEventHandler<SwitchChangeEvent>,
|}>;
type ComponentType = HostComponent<NativeProps>;
interface NativeCommands {
+setValue: (viewRef: React.ElementRef<ComponentType>, value: boolean) => void;
}
export const Commands: NativeCommands = codegenNativeCommands<NativeCommands>({
supportedCommands: ['setValue'],
});
export default (codegenNativeComponent<NativeProps>('Switch', {
paperComponentName: 'RCTSwitch',
}): HostComponent<NativeProps>);
excludedPlatform: 'android',
}): ComponentType);