diff --git a/Libraries/Components/CheckBox/AndroidCheckBoxNativeComponent.js b/Libraries/Components/CheckBox/AndroidCheckBoxNativeComponent.js deleted file mode 100644 index 097cba176009..000000000000 --- a/Libraries/Components/CheckBox/AndroidCheckBoxNativeComponent.js +++ /dev/null @@ -1,52 +0,0 @@ -/** - * 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. - * - * @flow - * @format - */ -'use strict'; - -const requireNativeComponent = require('../../ReactNative/requireNativeComponent'); - -import type {ViewProps} from '../View/ViewPropTypes'; -import type {SyntheticEvent} from '../../Types/CoreEventTypes'; -import type {NativeComponent} from '../../Renderer/shims/ReactNative'; - -type CheckBoxEvent = SyntheticEvent< - $ReadOnly<{| - target: number, - value: boolean, - |}>, ->; - -type NativeProps = $ReadOnly<{| - ...ViewProps, - - /** - * Used in case the props change removes the component. - */ - onChange?: ?(event: CheckBoxEvent) => mixed, - - /** - * Invoked with the new value when the value changes. - */ - onValueChange?: ?(value: boolean) => mixed, - - /** - * Used to locate this view in end-to-end tests. - */ - testID?: ?string, - - on?: ?boolean, - enabled?: boolean, - tintColors: {|true: ?number, false: ?number|} | typeof undefined, -|}>; - -type CheckBoxNativeType = Class>; - -module.exports = ((requireNativeComponent( - 'AndroidCheckBox', -): any): CheckBoxNativeType); diff --git a/Libraries/Components/CheckBox/CheckBox.android.js b/Libraries/Components/CheckBox/CheckBox.android.js deleted file mode 100644 index 07d20cb53320..000000000000 --- a/Libraries/Components/CheckBox/CheckBox.android.js +++ /dev/null @@ -1,220 +0,0 @@ -/** - * 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. - * - * @flow strict-local - * @format - */ -'use strict'; - -const React = require('react'); -const StyleSheet = require('../../StyleSheet/StyleSheet'); -const processColor = require('../../StyleSheet/processColor'); - -const AndroidCheckBoxNativeComponent = require('./AndroidCheckBoxNativeComponent'); -const nullthrows = require('nullthrows'); -const setAndForwardRef = require('../../Utilities/setAndForwardRef'); - -import type {ViewProps} from '../View/ViewPropTypes'; -import type {SyntheticEvent} from '../../Types/CoreEventTypes'; -import type {NativeComponent} from '../../Renderer/shims/ReactNative'; -import type {ColorValue} from '../../StyleSheet/StyleSheetTypes'; - -type CheckBoxEvent = SyntheticEvent< - $ReadOnly<{| - target: number, - value: boolean, - |}>, ->; - -type CommonProps = $ReadOnly<{| - ...ViewProps, - - /** - * Used in case the props change removes the component. - */ - onChange?: ?(event: CheckBoxEvent) => mixed, - - /** - * Invoked with the new value when the value changes. - */ - onValueChange?: ?(value: boolean) => mixed, - - /** - * Used to locate this view in end-to-end tests. - */ - testID?: ?string, -|}>; - -type NativeProps = $ReadOnly<{| - ...CommonProps, - - on?: ?boolean, - enabled?: boolean, - tintColors: {|true: ?number, false: ?number|} | typeof undefined, -|}>; - -type CheckBoxNativeType = Class>; - -type Props = $ReadOnly<{| - ...CommonProps, - - /** - * The value of the checkbox. If true the checkbox will be turned on. - * Default value is false. - */ - value?: ?boolean, - - /** - * If true the user won't be able to toggle the checkbox. - * Default value is false. - */ - disabled?: ?boolean, - - /** - * Used to get the ref for the native checkbox - */ - forwardedRef?: ?React.Ref, - - /** - * Controls the colors the checkbox has in checked and unchecked states. - */ - tintColors?: {|true?: ?ColorValue, false?: ?ColorValue|}, -|}>; - -/** - * Renders a boolean input (Android only). - * - * This is a controlled component that requires an `onValueChange` callback that - * updates the `value` prop in order for the component to reflect user actions. - * If the `value` prop is not updated, the component will continue to render - * the supplied `value` prop instead of the expected result of any user actions. - * - * ``` - * import React from 'react'; - * import { AppRegistry, StyleSheet, Text, View, CheckBox } from 'react-native'; - * - * export default class App extends React.Component { - * constructor(props) { - * super(props); - * this.state = { - * checked: false - * } - * } - * - * toggle() { - * this.setState(({checked}) => { - * return { - * checked: !checked - * }; - * }); - * } - * - * render() { - * const {checked} = this.state; - * return ( - * - * Checked - * - * - * ); - * } - * } - * - * const styles = StyleSheet.create({ - * container: { - * flex: 1, - * flexDirection: 'row', - * alignItems: 'center', - * justifyContent: 'center', - * }, - * }); - * - * // skip this line if using Create React Native App - * AppRegistry.registerComponent('App', () => App); - * ``` - * - * @keyword checkbox - * @keyword toggle - */ -class CheckBox extends React.Component { - _nativeRef: ?React.ElementRef = null; - _setNativeRef = setAndForwardRef({ - getForwardedRef: () => this.props.forwardedRef, - setLocalRef: ref => { - this._nativeRef = ref; - }, - }); - - _onChange = (event: CheckBoxEvent) => { - const value = this.props.value ?? false; - nullthrows(this._nativeRef).setNativeProps({value: value}); - // Change the props after the native props are set in case the props - // change removes the component - this.props.onChange && this.props.onChange(event); - this.props.onValueChange && - this.props.onValueChange(event.nativeEvent.value); - }; - - getTintColors(tintColors) { - return tintColors - ? { - true: processColor(tintColors.true), - false: processColor(tintColors.false), - } - : undefined; - } - - render() { - const { - disabled: _, - value: __, - tintColors, - style, - forwardedRef, - ...props - } = this.props; - const disabled = this.props.disabled ?? false; - const value = this.props.value ?? false; - - const nativeProps = { - ...props, - onStartShouldSetResponder: () => true, - onResponderTerminationRequest: () => false, - enabled: !disabled, - on: value, - tintColors: this.getTintColors(tintColors), - style: [styles.rctCheckBox, style], - }; - return ( - - ); - } -} - -const styles = StyleSheet.create({ - rctCheckBox: { - height: 32, - width: 32, - }, -}); - -/** - * Can't use CheckBoxNativeType because it has different props - */ -type CheckBoxType = Class>; - -const CheckBoxWithRef = React.forwardRef(function CheckBoxWithRef(props, ref) { - return ; -}); - -/* $FlowFixMe(>=0.89.0 site=react_native_android_fb) This comment suppresses an - * error found when Flow v0.89 was deployed. To see the error, delete this - * comment and run Flow. */ -module.exports = (CheckBoxWithRef: CheckBoxType); diff --git a/Libraries/Components/CheckBox/CheckBox.ios.js b/Libraries/Components/CheckBox/CheckBox.ios.js deleted file mode 100644 index f6ce4003efa6..000000000000 --- a/Libraries/Components/CheckBox/CheckBox.ios.js +++ /dev/null @@ -1,12 +0,0 @@ -/** - * 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. - * - * @flow strict-local - * @format - */ -'use strict'; - -module.exports = require('../UnimplementedViews/UnimplementedView'); diff --git a/Libraries/Components/View/ViewAccessibility.js b/Libraries/Components/View/ViewAccessibility.js index ef003c407046..27e9eb52192a 100644 --- a/Libraries/Components/View/ViewAccessibility.js +++ b/Libraries/Components/View/ViewAccessibility.js @@ -26,7 +26,6 @@ export type AccessibilityRole = | 'header' | 'summary' | 'alert' - | 'checkbox' | 'combobox' | 'menu' | 'menubar' diff --git a/Libraries/DeprecatedPropTypes/DeprecatedViewAccessibility.js b/Libraries/DeprecatedPropTypes/DeprecatedViewAccessibility.js index 77c4146a865f..bb244b1f7bc0 100644 --- a/Libraries/DeprecatedPropTypes/DeprecatedViewAccessibility.js +++ b/Libraries/DeprecatedPropTypes/DeprecatedViewAccessibility.js @@ -25,7 +25,6 @@ module.exports = { 'header', 'summary', 'alert', - 'checkbox', 'combobox', 'menu', 'menubar', diff --git a/Libraries/DeprecatedPropTypes/DeprecatedViewPropTypes.js b/Libraries/DeprecatedPropTypes/DeprecatedViewPropTypes.js index 8cb8ceddfb20..4abe100198cc 100644 --- a/Libraries/DeprecatedPropTypes/DeprecatedViewPropTypes.js +++ b/Libraries/DeprecatedPropTypes/DeprecatedViewPropTypes.js @@ -84,7 +84,6 @@ module.exports = { | 'header' | 'summary' | 'alert' - | 'checkbox' | 'combobox' | 'menu' | 'menubar' diff --git a/RNTester/js/examples/CheckBox/CheckBoxExample.js b/RNTester/js/examples/CheckBox/CheckBoxExample.js deleted file mode 100644 index c9e795f638db..000000000000 --- a/RNTester/js/examples/CheckBox/CheckBoxExample.js +++ /dev/null @@ -1,148 +0,0 @@ -/** - * 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. - * - * @flow - * @format - */ - -'use strict'; - -const React = require('react'); -const {CheckBox, Text, View, StyleSheet} = require('react-native'); - -type BasicState = {| - trueCheckBoxIsOn: boolean, - falseCheckBoxIsOn: boolean, -|}; - -type BasicProps = $ReadOnly<{||}>; -class BasicCheckBoxExample extends React.Component { - state = { - trueCheckBoxIsOn: true, - falseCheckBoxIsOn: false, - }; - - render() { - return ( - - this.setState({falseCheckBoxIsOn: value})} - style={styles.checkbox} - value={this.state.falseCheckBoxIsOn} - tintColors={{false: 'red'}} - /> - this.setState({trueCheckBoxIsOn: value})} - value={this.state.trueCheckBoxIsOn} - tintColors={{true: 'green'}} - /> - - ); - } -} - -type DisabledProps = $ReadOnly<{||}>; -class DisabledCheckBoxExample extends React.Component { - render() { - return ( - - - - - ); - } -} - -type EventProps = $ReadOnly<{||}>; -type EventState = {| - eventCheckBoxIsOn: boolean, - eventCheckBoxRegressionIsOn: boolean, -|}; - -class EventCheckBoxExample extends React.Component { - state = { - eventCheckBoxIsOn: false, - eventCheckBoxRegressionIsOn: true, - }; - - render() { - return ( - - - this.setState({eventCheckBoxIsOn: value})} - style={styles.checkbox} - value={this.state.eventCheckBoxIsOn} - /> - this.setState({eventCheckBoxIsOn: value})} - style={styles.checkbox} - value={this.state.eventCheckBoxIsOn} - /> - {this.state.eventCheckBoxIsOn ? 'On' : 'Off'} - - - - this.setState({eventCheckBoxRegressionIsOn: value}) - } - style={styles.checkbox} - value={this.state.eventCheckBoxRegressionIsOn} - /> - - this.setState({eventCheckBoxRegressionIsOn: value}) - } - style={styles.checkbox} - value={this.state.eventCheckBoxRegressionIsOn} - /> - {this.state.eventCheckBoxRegressionIsOn ? 'On' : 'Off'} - - - ); - } -} - -const styles = StyleSheet.create({ - container: { - flexDirection: 'row', - justifyContent: 'space-around', - }, - checkbox: { - marginBottom: 10, - }, -}); - -exports.title = ''; -exports.displayName = 'CheckBoxExample'; -exports.description = 'Native boolean input'; -exports.examples = [ - { - title: - 'CheckBoxes can be set to true or false, and the color of both states can be specified.', - render(): React.Element { - return ; - }, - }, - { - title: 'CheckBoxes can be disabled', - render(): React.Element { - return ; - }, - }, - { - title: 'Change events can be detected', - render(): React.Element { - return ; - }, - }, - { - title: 'CheckBoxes are controlled components', - render(): React.Element { - return ; - }, - }, -]; diff --git a/RNTester/js/utils/RNTesterList.android.js b/RNTester/js/utils/RNTesterList.android.js index 10fcbe09a4e3..61b83356933e 100644 --- a/RNTester/js/utils/RNTesterList.android.js +++ b/RNTester/js/utils/RNTesterList.android.js @@ -21,10 +21,6 @@ const ComponentExamples: Array = [ key: 'ButtonExample', module: require('../examples/Button/ButtonExample'), }, - { - key: 'CheckBoxExample', - module: require('../examples/CheckBox/CheckBoxExample'), - }, { key: 'FlatListExample', module: require('../examples/FlatList/FlatListExample'), diff --git a/React/Views/RCTView.m b/React/Views/RCTView.m index 579c2d17a0b5..ead9cc655556 100644 --- a/React/Views/RCTView.m +++ b/React/Views/RCTView.m @@ -219,7 +219,6 @@ - (NSString *)accessibilityValue dispatch_once(&onceToken1, ^{ roleDescriptions = @{ @"alert" : @"alert", - @"checkbox" : @"checkbox", @"combobox" : @"combo box", @"menu" : @"menu", @"menubar" : @"menu bar", diff --git a/React/Views/RCTViewManager.m b/React/Views/RCTViewManager.m index 771caf6084c7..983dd7f467ed 100644 --- a/React/Views/RCTViewManager.m +++ b/React/Views/RCTViewManager.m @@ -47,7 +47,6 @@ @implementation RCTConvert(UIAccessibilityTraits) @"allowsDirectInteraction": @(UIAccessibilityTraitAllowsDirectInteraction), @"pageTurn": @(UIAccessibilityTraitCausesPageTurn), @"alert": @(UIAccessibilityTraitNone), - @"checkbox": @(UIAccessibilityTraitNone), @"combobox": @(UIAccessibilityTraitNone), @"menu": @(UIAccessibilityTraitNone), @"menubar": @(UIAccessibilityTraitNone), diff --git a/ReactAndroid/src/main/java/com/facebook/react/shell/BUCK b/ReactAndroid/src/main/java/com/facebook/react/shell/BUCK index 5acd40190d59..33e86fa8eeee 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/shell/BUCK +++ b/ReactAndroid/src/main/java/com/facebook/react/shell/BUCK @@ -51,7 +51,6 @@ rn_android_library( react_native_target("java/com/facebook/react/modules/websocket:websocket"), react_native_target("java/com/facebook/react/uimanager:uimanager"), react_native_target("java/com/facebook/react/views/art:art"), - react_native_target("java/com/facebook/react/views/checkbox:checkbox"), react_native_target("java/com/facebook/react/views/drawer:drawer"), react_native_target("java/com/facebook/react/views/image:image"), react_native_target("java/com/facebook/react/views/modal:modal"), diff --git a/ReactAndroid/src/main/java/com/facebook/react/shell/MainReactPackage.java b/ReactAndroid/src/main/java/com/facebook/react/shell/MainReactPackage.java index 66ff5d2d8b6a..d52699f3a08d 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/shell/MainReactPackage.java +++ b/ReactAndroid/src/main/java/com/facebook/react/shell/MainReactPackage.java @@ -43,7 +43,6 @@ import com.facebook.react.uimanager.ViewManager; import com.facebook.react.views.art.ARTRenderableViewManager; import com.facebook.react.views.art.ARTSurfaceViewManager; -import com.facebook.react.views.checkbox.ReactCheckBoxManager; import com.facebook.react.views.drawer.ReactDrawerLayoutManager; import com.facebook.react.views.image.ReactImageManager; import com.facebook.react.views.modal.ReactModalHostManager; @@ -176,7 +175,6 @@ public List createViewManagers(ReactApplicationContext reactContext viewManagers.add(ARTRenderableViewManager.createARTGroupViewManager()); viewManagers.add(ARTRenderableViewManager.createARTShapeViewManager()); viewManagers.add(ARTRenderableViewManager.createARTTextViewManager()); - viewManagers.add(new ReactCheckBoxManager()); viewManagers.add(new ReactDialogPickerManager()); viewManagers.add(new ReactDrawerLayoutManager()); viewManagers.add(new ReactDropdownPickerManager()); diff --git a/ReactAndroid/src/main/java/com/facebook/react/uimanager/ReactAccessibilityDelegate.java b/ReactAndroid/src/main/java/com/facebook/react/uimanager/ReactAccessibilityDelegate.java index 9f7b2591575a..a6dd58df5eb3 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/uimanager/ReactAccessibilityDelegate.java +++ b/ReactAndroid/src/main/java/com/facebook/react/uimanager/ReactAccessibilityDelegate.java @@ -85,7 +85,6 @@ public enum AccessibilityRole { SUMMARY, HEADER, ALERT, - CHECKBOX, COMBOBOX, MENU, MENUBAR, @@ -117,8 +116,6 @@ public static String getValue(AccessibilityRole role) { return "android.widget.TextView"; case ADJUSTABLE: return "android.widget.SeekBar"; - case CHECKBOX: - return "android.widget.CheckBox"; case RADIO: return "android.widget.RadioButton"; case SPINBUTTON: diff --git a/ReactAndroid/src/main/java/com/facebook/react/views/checkbox/BUCK b/ReactAndroid/src/main/java/com/facebook/react/views/checkbox/BUCK deleted file mode 100644 index 3e2f34a0960d..000000000000 --- a/ReactAndroid/src/main/java/com/facebook/react/views/checkbox/BUCK +++ /dev/null @@ -1,25 +0,0 @@ -load("//tools/build_defs/oss:rn_defs.bzl", "react_native_dep", "react_native_target", "rn_android_library") - -rn_android_library( - name = "checkbox", - srcs = glob(["*.java"]), - is_androidx = True, - provided_deps = [ - react_native_dep("third-party/android/androidx:annotation"), - react_native_dep("third-party/android/androidx:appcompat"), - react_native_dep("third-party/android/androidx:core"), - react_native_dep("third-party/android/androidx:fragment"), - react_native_dep("third-party/android/androidx:legacy-support-core-ui"), - react_native_dep("third-party/android/androidx:legacy-support-core-utils"), - ], - visibility = [ - "PUBLIC", - ], - deps = [ - react_native_dep("third-party/java/jsr-305:jsr-305"), - react_native_target("java/com/facebook/react/bridge:bridge"), - react_native_target("java/com/facebook/react/common:common"), - react_native_target("java/com/facebook/react/uimanager:uimanager"), - react_native_target("java/com/facebook/react/uimanager/annotations:annotations"), - ], -) diff --git a/ReactAndroid/src/main/java/com/facebook/react/views/checkbox/ReactCheckBox.java b/ReactAndroid/src/main/java/com/facebook/react/views/checkbox/ReactCheckBox.java deleted file mode 100644 index 54bfdbd32151..000000000000 --- a/ReactAndroid/src/main/java/com/facebook/react/views/checkbox/ReactCheckBox.java +++ /dev/null @@ -1,37 +0,0 @@ -/** - * 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. - */ -package com.facebook.react.views.checkbox; - -import android.content.Context; -import androidx.appcompat.widget.AppCompatCheckBox; - -/** CheckBox that has its value controlled by JS. */ -/*package*/ class ReactCheckBox extends AppCompatCheckBox { - - private boolean mAllowChange; - - public ReactCheckBox(Context context) { - super(context); - mAllowChange = true; - } - - @Override - public void setChecked(boolean checked) { - if (mAllowChange) { - mAllowChange = false; - super.setChecked(checked); - } - } - - /*package*/ void setOn(boolean on) { - // If the checkbox has a different value than the value sent by JS, we must change it. - if (isChecked() != on) { - super.setChecked(on); - } - mAllowChange = true; - } -} diff --git a/ReactAndroid/src/main/java/com/facebook/react/views/checkbox/ReactCheckBoxEvent.java b/ReactAndroid/src/main/java/com/facebook/react/views/checkbox/ReactCheckBoxEvent.java deleted file mode 100644 index 34b4bc560f60..000000000000 --- a/ReactAndroid/src/main/java/com/facebook/react/views/checkbox/ReactCheckBoxEvent.java +++ /dev/null @@ -1,52 +0,0 @@ -/** - * 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. - */ -package com.facebook.react.views.checkbox; - -import com.facebook.react.bridge.Arguments; -import com.facebook.react.bridge.WritableMap; -import com.facebook.react.uimanager.events.Event; -import com.facebook.react.uimanager.events.RCTEventEmitter; - -/** Event emitted by a ReactCheckBoxManager once a checkbox is manipulated. */ -/*package*/ class ReactCheckBoxEvent extends Event { - - public static final String EVENT_NAME = "topChange"; - - private final boolean mIsChecked; - - public ReactCheckBoxEvent(int viewId, boolean isChecked) { - super(viewId); - mIsChecked = isChecked; - } - - public boolean getIsChecked() { - return mIsChecked; - } - - @Override - public String getEventName() { - return EVENT_NAME; - } - - @Override - public short getCoalescingKey() { - // All checkbox events for a given view can be coalesced. - return 0; - } - - @Override - public void dispatch(RCTEventEmitter rctEventEmitter) { - rctEventEmitter.receiveEvent(getViewTag(), getEventName(), serializeEventData()); - } - - private WritableMap serializeEventData() { - WritableMap eventData = Arguments.createMap(); - eventData.putInt("target", getViewTag()); - eventData.putBoolean("value", getIsChecked()); - return eventData; - } -} diff --git a/ReactAndroid/src/main/java/com/facebook/react/views/checkbox/ReactCheckBoxManager.java b/ReactAndroid/src/main/java/com/facebook/react/views/checkbox/ReactCheckBoxManager.java deleted file mode 100644 index 4213ebc4dab1..000000000000 --- a/ReactAndroid/src/main/java/com/facebook/react/views/checkbox/ReactCheckBoxManager.java +++ /dev/null @@ -1,122 +0,0 @@ -/** - * 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. - */ -package com.facebook.react.views.checkbox; - -import android.content.Context; -import android.content.res.ColorStateList; -import android.util.TypedValue; -import android.widget.CompoundButton; -import androidx.annotation.Nullable; -import androidx.appcompat.widget.TintContextWrapper; -import androidx.core.widget.CompoundButtonCompat; -import com.facebook.react.bridge.ReactContext; -import com.facebook.react.bridge.ReadableMap; -import com.facebook.react.uimanager.SimpleViewManager; -import com.facebook.react.uimanager.ThemedReactContext; -import com.facebook.react.uimanager.UIManagerModule; -import com.facebook.react.uimanager.ViewProps; -import com.facebook.react.uimanager.annotations.ReactProp; - -/** View manager for {@link ReactCheckBox} components. */ -public class ReactCheckBoxManager extends SimpleViewManager { - - public static final String REACT_CLASS = "AndroidCheckBox"; - - private static final CompoundButton.OnCheckedChangeListener ON_CHECKED_CHANGE_LISTENER = - new CompoundButton.OnCheckedChangeListener() { - @Override - public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { - ReactContext reactContext = getReactContext(buttonView); - reactContext - .getNativeModule(UIManagerModule.class) - .getEventDispatcher() - .dispatchEvent(new ReactCheckBoxEvent(buttonView.getId(), isChecked)); - } - - private ReactContext getReactContext(CompoundButton buttonView) { - ReactContext reactContext; - Context ctx = buttonView.getContext(); - if (ctx instanceof TintContextWrapper) { - reactContext = (ReactContext) ((TintContextWrapper) ctx).getBaseContext(); - } else { - reactContext = (ReactContext) buttonView.getContext(); - } - return reactContext; - } - }; - - @Override - public String getName() { - return REACT_CLASS; - } - - @Override - protected void addEventEmitters(final ThemedReactContext reactContext, final ReactCheckBox view) { - view.setOnCheckedChangeListener(ON_CHECKED_CHANGE_LISTENER); - } - - @Override - protected ReactCheckBox createViewInstance(ThemedReactContext context) { - ReactCheckBox view = new ReactCheckBox(context); - return view; - } - - @ReactProp(name = ViewProps.ENABLED, defaultBoolean = true) - public void setEnabled(ReactCheckBox view, boolean enabled) { - view.setEnabled(enabled); - } - - @ReactProp(name = ViewProps.ON) - public void setOn(ReactCheckBox view, boolean on) { - // we set the checked change listener to null and then restore it so that we don't fire an - // onChange event to JS when JS itself is updating the value of the checkbox - view.setOnCheckedChangeListener(null); - view.setOn(on); - view.setOnCheckedChangeListener(ON_CHECKED_CHANGE_LISTENER); - } - - private static int getThemeColor(final Context context, String colorId) { - final TypedValue value = new TypedValue(); - context.getTheme().resolveAttribute(getIdentifier(context, colorId), value, true); - return value.data; - } - - /** - * The appcompat-v7 BUCK dep is listed as a provided_dep, which complains that - * com.facebook.react.R doesn't exist. Since the attributes are provided from a parent, we can - * access those attributes dynamically. - */ - private static int getIdentifier(Context context, String name) { - return context.getResources().getIdentifier(name, "attr", context.getPackageName()); - } - - @ReactProp(name = "tintColors") - public void setTintColors(ReactCheckBox view, @Nullable ReadableMap colorsMap) { - String defaultColorIdOfCheckedState = "colorAccent"; - int trueColor = - colorsMap == null || !colorsMap.hasKey("true") - ? getThemeColor(view.getContext(), defaultColorIdOfCheckedState) - : colorsMap.getInt("true"); - - String defaultColorIdOfUncheckedState = "colorPrimaryDark"; - int falseColor = - colorsMap == null || !colorsMap.hasKey("false") - ? getThemeColor(view.getContext(), defaultColorIdOfUncheckedState) - : colorsMap.getInt("false"); - - ColorStateList csl = - new ColorStateList( - new int[][] { - new int[] {android.R.attr.state_checked}, new int[] {-android.R.attr.state_checked} - }, - new int[] { - trueColor, falseColor, - }); - - CompoundButtonCompat.setButtonTintList(view, csl); - } -} diff --git a/ReactAndroid/src/main/res/devsupport/xml/rn_dev_preferences.xml b/ReactAndroid/src/main/res/devsupport/xml/rn_dev_preferences.xml index f057bff21a03..abb52d0f46d6 100644 --- a/ReactAndroid/src/main/res/devsupport/xml/rn_dev_preferences.xml +++ b/ReactAndroid/src/main/res/devsupport/xml/rn_dev_preferences.xml @@ -27,6 +27,8 @@ android:key="pref_key_catalyst_debug" android:title="Debugging" > + case CHECKBOX: + return "android.widget.CheckBox";