mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
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:
committed by
Facebook Github Bot
parent
b6a23d8793
commit
4eb8a951ff
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user