diff --git a/Libraries/Components/Switch/AndroidSwitchNativeComponent.js b/Libraries/Components/Switch/AndroidSwitchNativeComponent.js index c8c9bba9ada..e02fa8115eb 100644 --- a/Libraries/Components/Switch/AndroidSwitchNativeComponent.js +++ b/Libraries/Components/Switch/AndroidSwitchNativeComponent.js @@ -10,39 +10,39 @@ 'use strict'; -const {NativeComponent} = require('../../Renderer/shims/ReactNative'); +import type { + WithDefault, + BubblingEventHandler, +} from 'react-native/Libraries/Types/CodegenTypes'; -const requireNativeComponent = require('../../ReactNative/requireNativeComponent'); +import codegenNativeComponent from 'react-native/Libraries/Utilities/codegenNativeComponent'; +import type {NativeComponentType} from 'react-native/Libraries/Utilities/codegenNativeComponent'; -import type {SyntheticEvent} from '../../Types/CoreEventTypes'; +import type {ColorValue} from '../../StyleSheet/StyleSheetTypes'; import type {ViewProps} from '../View/ViewPropTypes'; -type SwitchChangeEvent = SyntheticEvent< - $ReadOnly<{| - value: boolean, - |}>, ->; +type SwitchChangeEvent = $ReadOnly<{| + value: boolean, +|}>; type NativeProps = $ReadOnly<{| ...ViewProps, // Props - disabled?: ?boolean, - enabled?: ?boolean, - thumbColor?: ?string, - trackColorForFalse?: ?string, - trackColorForTrue?: ?string, - value?: ?boolean, - on?: ?boolean, - thumbTintColor?: ?string, - trackTintColor?: ?string, + disabled?: WithDefault, + enabled?: WithDefault, + thumbColor?: ?ColorValue, + trackColorForFalse?: ?ColorValue, + trackColorForTrue?: ?ColorValue, + value?: WithDefault, + on?: WithDefault, + thumbTintColor?: ?ColorValue, + trackTintColor?: ?ColorValue, // Events - onChange?: ?(event: SwitchChangeEvent) => mixed, + onChange?: BubblingEventHandler, |}>; -type SwitchNativeComponentType = Class>; - -module.exports = ((requireNativeComponent( +export default (codegenNativeComponent( 'AndroidSwitch', -): any): SwitchNativeComponentType); +): NativeComponentType); diff --git a/Libraries/Components/Switch/Switch.js b/Libraries/Components/Switch/Switch.js index 71abfeb8276..8a915a02f35 100644 --- a/Libraries/Components/Switch/Switch.js +++ b/Libraries/Components/Switch/Switch.js @@ -11,7 +11,6 @@ 'use strict'; -const AndroidSwitchNativeComponent = require('./AndroidSwitchNativeComponent'); const Platform = require('../../Utilities/Platform'); const React = require('react'); const StyleSheet = require('../../StyleSheet/StyleSheet'); @@ -20,6 +19,7 @@ import type {ColorValue} from '../../StyleSheet/StyleSheetTypes'; import type {SyntheticEvent} from '../../Types/CoreEventTypes'; import type {ViewProps} from '../View/ViewPropTypes'; import SwitchNativeComponent from './SwitchNativeComponent'; +import AndroidSwitchNativeComponent from './AndroidSwitchNativeComponent'; type SwitchChangeEvent = SyntheticEvent< $ReadOnly<{| diff --git a/ReactAndroid/src/main/java/com/facebook/react/viewmanagers/AndroidSwitchManagerDelegate.java b/ReactAndroid/src/main/java/com/facebook/react/viewmanagers/AndroidSwitchManagerDelegate.java new file mode 100644 index 00000000000..0d877317a10 --- /dev/null +++ b/ReactAndroid/src/main/java/com/facebook/react/viewmanagers/AndroidSwitchManagerDelegate.java @@ -0,0 +1,56 @@ +/** +* Copyright (c) Facebook, Inc. and its affiliates. +* +* This source code is licensed under the MIT license found in the +* LICENSE file in the root directory of this source tree. +* +* @generated by codegen project: GeneratePropsJavaDelegate.js +*/ + +package com.facebook.react.viewmanagers; + +import android.view.View; +import androidx.annotation.Nullable; +import com.facebook.react.uimanager.BaseViewManagerDelegate; +import com.facebook.react.uimanager.BaseViewManagerInterface; +import com.facebook.react.uimanager.LayoutShadowNode; + +public class AndroidSwitchManagerDelegate & AndroidSwitchManagerInterface> extends BaseViewManagerDelegate { + public AndroidSwitchManagerDelegate(U viewManager) { + super(viewManager); + } + @Override + public void setProperty(T view, String propName, @Nullable Object value) { + switch (propName) { + case "disabled": + mViewManager.setDisabled(view, value == null ? false : (boolean) value); + break; + case "enabled": + mViewManager.setEnabled(view, value == null ? false : (boolean) value); + break; + case "thumbColor": + mViewManager.setThumbColor(view, value == null ? null : ((Double) value).intValue()); + break; + case "trackColorForFalse": + mViewManager.setTrackColorForFalse(view, value == null ? null : ((Double) value).intValue()); + break; + case "trackColorForTrue": + mViewManager.setTrackColorForTrue(view, value == null ? null : ((Double) value).intValue()); + break; + case "value": + mViewManager.setValue(view, value == null ? false : (boolean) value); + break; + case "on": + mViewManager.setOn(view, value == null ? false : (boolean) value); + break; + case "thumbTintColor": + mViewManager.setThumbTintColor(view, value == null ? null : ((Double) value).intValue()); + break; + case "trackTintColor": + mViewManager.setTrackTintColor(view, value == null ? null : ((Double) value).intValue()); + break; + default: + super.setProperty(view, propName, value); + } + } +} diff --git a/ReactAndroid/src/main/java/com/facebook/react/viewmanagers/AndroidSwitchManagerInterface.java b/ReactAndroid/src/main/java/com/facebook/react/viewmanagers/AndroidSwitchManagerInterface.java new file mode 100644 index 00000000000..565c9ead11d --- /dev/null +++ b/ReactAndroid/src/main/java/com/facebook/react/viewmanagers/AndroidSwitchManagerInterface.java @@ -0,0 +1,25 @@ +/** +* Copyright (c) Facebook, Inc. and its affiliates. +* +* This source code is licensed under the MIT license found in the +* LICENSE file in the root directory of this source tree. +* +* @generated by codegen project: GeneratePropsJavaInterface.js +*/ + +package com.facebook.react.viewmanagers; + +import android.view.View; +import androidx.annotation.Nullable; + +public interface AndroidSwitchManagerInterface { + void setDisabled(T view, boolean value); + void setEnabled(T view, boolean value); + void setThumbColor(T view, @Nullable Integer value); + void setTrackColorForFalse(T view, @Nullable Integer value); + void setTrackColorForTrue(T view, @Nullable Integer value); + void setValue(T view, boolean value); + void setOn(T view, boolean value); + void setThumbTintColor(T view, @Nullable Integer value); + void setTrackTintColor(T view, @Nullable Integer value); +}