Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Standalone for NativeComponents] AndroidCheckBox #23003

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions Libraries/Components/CheckBox/AndroidCheckBoxNativeComponent.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/**
* 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('requireNativeComponent');

import type {ViewProps} from 'ViewPropTypes';
import type {SyntheticEvent} from 'CoreEventTypes';
import type {NativeComponent} from '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,
|}>;

type CheckBoxNativeType = Class<NativeComponent<NativeProps>>;

module.exports = ((requireNativeComponent(
'AndroidCheckBox',
): any): CheckBoxNativeType);
10 changes: 3 additions & 7 deletions Libraries/Components/CheckBox/CheckBox.android.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
* @flow strict-local
* @format
*/
'use strict';

const React = require('React');
const StyleSheet = require('StyleSheet');

const requireNativeComponent = require('requireNativeComponent');
const AndroidCheckBoxNativeComponent = require('AndroidCheckBoxNativeComponent');
const nullthrows = require('nullthrows');
const setAndForwardRef = require('setAndForwardRef');

Expand Down Expand Up @@ -76,10 +76,6 @@ type Props = $ReadOnly<{|
forwardedRef?: ?React.Ref<CheckBoxNativeType>,
|}>;

const RCTCheckBox = ((requireNativeComponent(
'AndroidCheckBox',
): any): CheckBoxNativeType);

/**
* Renders a boolean input (Android only).
*
Expand Down Expand Up @@ -169,7 +165,7 @@ class CheckBox extends React.Component<Props> {
};

return (
<RCTCheckBox
<AndroidCheckBoxNativeComponent
{...nativeProps}
ref={this._setNativeRef}
onChange={this._onChange}
Expand Down