@solidx/checkbox 0.0.0-stage → 0.7.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (85) hide show
  1. package/LICENSE +21 -0
  2. package/NuGet.config +11 -0
  3. package/RNCCheckbox.podspec +22 -0
  4. package/android/build.gradle +65 -0
  5. package/android/gradle/wrapper/gradle-wrapper.jar +0 -0
  6. package/android/gradle/wrapper/gradle-wrapper.properties +6 -0
  7. package/android/gradle.properties +4 -0
  8. package/android/gradlew +172 -0
  9. package/android/gradlew.bat +84 -0
  10. package/android/src/main/AndroidManifest.xml +5 -0
  11. package/android/src/main/java/com/reactnativecommunity/checkbox/ReactCheckBox.java +43 -0
  12. package/android/src/main/java/com/reactnativecommunity/checkbox/ReactCheckBoxEvent.java +47 -0
  13. package/android/src/main/java/com/reactnativecommunity/checkbox/ReactCheckBoxManager.java +128 -0
  14. package/android/src/main/java/com/reactnativecommunity/checkbox/ReactCheckBoxPackage.java +29 -0
  15. package/dist/js/AndroidCheckBoxNativeComponent.d.ts +2 -0
  16. package/dist/js/AndroidCheckBoxNativeComponent.js +11 -0
  17. package/dist/js/CheckBox.android.d.ts +83 -0
  18. package/dist/js/CheckBox.android.js +162 -0
  19. package/dist/js/CheckBox.d.ts +5 -0
  20. package/dist/js/CheckBox.ios.d.ts +92 -0
  21. package/dist/js/CheckBox.ios.js +109 -0
  22. package/dist/js/CheckBox.js +27 -0
  23. package/dist/js/CheckBox.windows.d.ts +95 -0
  24. package/dist/js/CheckBox.windows.js +95 -0
  25. package/dist/js/CheckboxNativeComponent.d.ts +11 -0
  26. package/dist/js/CheckboxNativeComponent.js +22 -0
  27. package/dist/js/IOSCheckBoxNativeComponent.d.ts +2 -0
  28. package/dist/js/IOSCheckBoxNativeComponent.js +11 -0
  29. package/dist/js/NativeCheckboxModule.d.ts +11 -0
  30. package/dist/js/NativeCheckboxModule.js +10 -0
  31. package/dist/js/RNCCheckboxNativeComponent.d.ts +48 -0
  32. package/dist/js/RNCCheckboxNativeComponent.js +12 -0
  33. package/dist/js/index.d.ts +11 -0
  34. package/dist/js/index.js +34 -0
  35. package/dist/js/setAndForwardRef.d.ts +40 -0
  36. package/dist/js/setAndForwardRef.js +53 -0
  37. package/ios/Podfile +3 -0
  38. package/ios/Podfile.lock +16 -0
  39. package/ios/RNCCheckbox.h +16 -0
  40. package/ios/RNCCheckbox.m +13 -0
  41. package/ios/RNCCheckbox.xcodeproj/project.pbxproj +322 -0
  42. package/ios/RNCCheckbox.xcodeproj/xcshareddata/xcschemes/RNCCheckbox.xcscheme +67 -0
  43. package/ios/RNCCheckbox.xcworkspace/contents.xcworkspacedata +10 -0
  44. package/ios/RNCCheckbox.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +8 -0
  45. package/ios/RNCCheckbox.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings +10 -0
  46. package/ios/RNCCheckboxManager.h +12 -0
  47. package/ios/RNCCheckboxManager.m +86 -0
  48. package/jest.config.windows.js +3 -0
  49. package/js/AndroidCheckBoxNativeComponent.ts +12 -0
  50. package/js/CheckBox.android.tsx +217 -0
  51. package/js/CheckBox.ios.tsx +175 -0
  52. package/js/CheckBox.ts +9 -0
  53. package/js/CheckBox.windows.tsx +158 -0
  54. package/js/CheckboxNativeComponent.ts +25 -0
  55. package/js/IOSCheckBoxNativeComponent.ts +12 -0
  56. package/js/NativeCheckboxModule.ts +15 -0
  57. package/js/RNCCheckboxNativeComponent.ts +68 -0
  58. package/js/index.ts +17 -0
  59. package/js/setAndForwardRef.ts +64 -0
  60. package/metro.config.js +45 -0
  61. package/package.json +84 -4
  62. package/react-native.config.js +22 -0
  63. package/typings/index.d.ts +14 -0
  64. package/windows/Checkbox/Checkbox.cpp +20 -0
  65. package/windows/Checkbox/Checkbox.def +3 -0
  66. package/windows/Checkbox/Checkbox.h +26 -0
  67. package/windows/Checkbox/Checkbox.rc +0 -0
  68. package/windows/Checkbox/Checkbox.vcxproj +146 -0
  69. package/windows/Checkbox/Checkbox.vcxproj.filters +56 -0
  70. package/windows/Checkbox/CheckboxView.cpp +186 -0
  71. package/windows/Checkbox/CheckboxView.h +59 -0
  72. package/windows/Checkbox/ReactPackageProvider.cpp +24 -0
  73. package/windows/Checkbox/ReactPackageProvider.h +24 -0
  74. package/windows/Checkbox/ReactPackageProvider.idl +9 -0
  75. package/windows/Checkbox/codegen/.clang-format +2 -0
  76. package/windows/Checkbox/codegen/NativeCheckboxModuleSpec.g.h +31 -0
  77. package/windows/Checkbox/codegen_manual/react/components/RNCCheckboxSpec/RNCCheckbox.g.h +232 -0
  78. package/windows/Checkbox/packages.lock.json +151 -0
  79. package/windows/Checkbox/pch.cpp +1 -0
  80. package/windows/Checkbox/pch.h +43 -0
  81. package/windows/Checkbox/resource.h +5 -0
  82. package/windows/Checkbox/targetver.h +8 -0
  83. package/windows/Checkbox.sln +43 -0
  84. package/windows/ExperimentalFeatures.props +33 -0
  85. package/README.md +0 -3
@@ -0,0 +1,67 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <Scheme
3
+ LastUpgradeVersion = "1140"
4
+ version = "1.3">
5
+ <BuildAction
6
+ parallelizeBuildables = "NO"
7
+ buildImplicitDependencies = "YES">
8
+ <BuildActionEntries>
9
+ <BuildActionEntry
10
+ buildForTesting = "YES"
11
+ buildForRunning = "YES"
12
+ buildForProfiling = "YES"
13
+ buildForArchiving = "YES"
14
+ buildForAnalyzing = "YES">
15
+ <BuildableReference
16
+ BuildableIdentifier = "primary"
17
+ BlueprintIdentifier = "58B511DA1A9E6C8500147676"
18
+ BuildableName = "libRNCCheckbox.a"
19
+ BlueprintName = "RNCCheckbox"
20
+ ReferencedContainer = "container:RNCCheckbox.xcodeproj">
21
+ </BuildableReference>
22
+ </BuildActionEntry>
23
+ </BuildActionEntries>
24
+ </BuildAction>
25
+ <TestAction
26
+ buildConfiguration = "Debug"
27
+ selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
28
+ selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
29
+ shouldUseLaunchSchemeArgsEnv = "YES">
30
+ <Testables>
31
+ </Testables>
32
+ </TestAction>
33
+ <LaunchAction
34
+ buildConfiguration = "Debug"
35
+ selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
36
+ selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
37
+ launchStyle = "0"
38
+ useCustomWorkingDirectory = "NO"
39
+ ignoresPersistentStateOnLaunch = "NO"
40
+ debugDocumentVersioning = "YES"
41
+ debugServiceExtension = "internal"
42
+ allowLocationSimulation = "YES">
43
+ </LaunchAction>
44
+ <ProfileAction
45
+ buildConfiguration = "Release"
46
+ shouldUseLaunchSchemeArgsEnv = "YES"
47
+ savedToolIdentifier = ""
48
+ useCustomWorkingDirectory = "NO"
49
+ debugDocumentVersioning = "YES">
50
+ <MacroExpansion>
51
+ <BuildableReference
52
+ BuildableIdentifier = "primary"
53
+ BlueprintIdentifier = "58B511DA1A9E6C8500147676"
54
+ BuildableName = "libRNCCheckbox.a"
55
+ BlueprintName = "RNCCheckbox"
56
+ ReferencedContainer = "container:RNCCheckbox.xcodeproj">
57
+ </BuildableReference>
58
+ </MacroExpansion>
59
+ </ProfileAction>
60
+ <AnalyzeAction
61
+ buildConfiguration = "Debug">
62
+ </AnalyzeAction>
63
+ <ArchiveAction
64
+ buildConfiguration = "Release"
65
+ revealArchiveInOrganizer = "YES">
66
+ </ArchiveAction>
67
+ </Scheme>
@@ -0,0 +1,10 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <Workspace
3
+ version = "1.0">
4
+ <FileRef
5
+ location = "group:RNCCheckbox.xcodeproj">
6
+ </FileRef>
7
+ <FileRef
8
+ location = "group:Pods/Pods.xcodeproj">
9
+ </FileRef>
10
+ </Workspace>
@@ -0,0 +1,8 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3
+ <plist version="1.0">
4
+ <dict>
5
+ <key>IDEDidComputeMac32BitWarning</key>
6
+ <true/>
7
+ </dict>
8
+ </plist>
@@ -0,0 +1,10 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3
+ <plist version="1.0">
4
+ <dict>
5
+ <key>BuildSystemType</key>
6
+ <string>Original</string>
7
+ <key>PreviewsEnabled</key>
8
+ <false/>
9
+ </dict>
10
+ </plist>
@@ -0,0 +1,12 @@
1
+ // Created by on 2020/05/07.
2
+ // Copyright © 2020 Facebook. All rights reserved.
3
+
4
+ // This source code is licensed under the MIT license found in the
5
+ // LICENSE file in the root directory of this source tree.
6
+
7
+ #import <React/RCTViewManager.h>
8
+ #import "BEMCheckBox.h"
9
+
10
+ @interface RNCCheckboxManager : RCTViewManager <BEMCheckBoxDelegate>
11
+
12
+ @end
@@ -0,0 +1,86 @@
1
+ // Created by Nicholas Lee <nicholaslee@gmail.com> on 2020/05/07.
2
+ // Copyright © 2020 Facebook. All rights reserved.
3
+
4
+ // This source code is licensed under the MIT license found in the
5
+ // LICENSE file in the root directory of this source tree.
6
+
7
+ #import "BEMCheckBox.h"
8
+ #import "RNCCheckboxManager.h"
9
+ #import "RNCCheckbox.h"
10
+
11
+ #import <React/RCTBridge.h>
12
+ #import <React/RCTEventDispatcher.h>
13
+ #import <React/UIView+React.h>
14
+ #import <React/RCTConvert.h>
15
+
16
+ @implementation RNCCheckboxManager
17
+
18
+ RCT_EXPORT_MODULE();
19
+
20
+ RCT_CUSTOM_VIEW_PROPERTY(value, BOOL, BEMCheckBox) {
21
+ [view setOn:[RCTConvert BOOL:json] animated:YES];
22
+ }
23
+
24
+ RCT_EXPORT_VIEW_PROPERTY(lineWidth, CGFloat);
25
+ RCT_EXPORT_VIEW_PROPERTY(hideBox, BOOL);
26
+ RCT_EXPORT_VIEW_PROPERTY(tintColor, UIColor);
27
+ RCT_EXPORT_VIEW_PROPERTY(onCheckColor, UIColor);
28
+ RCT_EXPORT_VIEW_PROPERTY(onFillColor, UIColor);
29
+ RCT_EXPORT_VIEW_PROPERTY(onTintColor, UIColor);
30
+ RCT_EXPORT_VIEW_PROPERTY(animationDuration, CGFloat);
31
+ RCT_EXPORT_VIEW_PROPERTY(onAnimationDidStop, RCTBubblingEventBlock)
32
+ RCT_EXPORT_VIEW_PROPERTY(onValueChange, RCTBubblingEventBlock)
33
+
34
+ RCT_REMAP_VIEW_PROPERTY(boxType, boxType, BEMBoxType);
35
+ RCT_REMAP_VIEW_PROPERTY(onAnimationType, onAnimationType, BEMAnimationType);
36
+ RCT_REMAP_VIEW_PROPERTY(offAnimationType, offAnimationType, BEMAnimationType);
37
+
38
+ - (UIView *)view
39
+ {
40
+ RNCCheckbox *checkbox = [RNCCheckbox new];
41
+ checkbox.delegate = self;
42
+ return checkbox;
43
+ }
44
+
45
+ - (void)didTapCheckBox:(RNCCheckbox *) checkbox {
46
+ if (!checkbox.onValueChange) {
47
+ return;
48
+ }
49
+ checkbox.onValueChange(@{
50
+ @"target": checkbox.reactTag,
51
+ @"value": @(checkbox.on),
52
+ @"name": @"tap",
53
+ });
54
+ }
55
+
56
+ - (void)animationDidStopForCheckBox:(RNCCheckbox *) checkbox {
57
+ if (!checkbox.onAnimationDidStop) {
58
+ return;
59
+ }
60
+ checkbox.onAnimationDidStop(@{
61
+ @"target": checkbox.reactTag,
62
+ @"value": @(checkbox.on),
63
+ @"name": @"animation",
64
+ });
65
+ }
66
+
67
+ @end
68
+
69
+ @implementation RCTConvert (BEMCheckBox)
70
+
71
+ RCT_ENUM_CONVERTER(BEMBoxType, (@{
72
+ @"circle": @(BEMBoxTypeCircle),
73
+ @"square": @(BEMBoxTypeSquare),
74
+ }), BEMBoxTypeCircle, integerValue);
75
+
76
+
77
+ RCT_ENUM_CONVERTER(BEMAnimationType, (@{
78
+ @"stroke": @(BEMAnimationTypeStroke),
79
+ @"fill": @(BEMAnimationTypeFill),
80
+ @"bounce": @(BEMAnimationTypeBounce),
81
+ @"flat": @(BEMAnimationTypeFlat),
82
+ @"one-stroke": @(BEMAnimationTypeOneStroke),
83
+ @"fade": @(BEMAnimationTypeFade),
84
+ }), BEMAnimationTypeStroke, integerValue);
85
+
86
+ @end
@@ -0,0 +1,3 @@
1
+ const config = {};
2
+
3
+ module.exports = require('@rnx-kit/jest-preset')('windows', config);
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Copyright (c) Facebook, Inc. and its affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ */
8
+ 'use strict';
9
+
10
+ import {requireNativeComponent} from 'react-native';
11
+
12
+ export default requireNativeComponent('AndroidCheckBox');
@@ -0,0 +1,217 @@
1
+ /**
2
+ * Copyright (c) Facebook, Inc. and its affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ */
8
+ 'use strict';
9
+
10
+ import nullthrows from 'nullthrows';
11
+ import React from 'react';
12
+ import {
13
+ StyleSheet,
14
+ processColor,
15
+ ViewProps,
16
+ HostInstance,
17
+ NativeSyntheticEvent,
18
+ } from 'react-native';
19
+ // @ts-ignore setAndForwardRef type does not exist in @types/react-native
20
+ import setAndForwardRef from './setAndForwardRef';
21
+
22
+ import AndroidCheckBoxNativeComponent from './AndroidCheckBoxNativeComponent';
23
+
24
+ type CheckBoxEvent = NativeSyntheticEvent<
25
+ Readonly<{
26
+ target: number;
27
+ value: boolean;
28
+ }>
29
+ >;
30
+
31
+ type CommonProps = Readonly<
32
+ ViewProps & {
33
+ /**
34
+ * Used in case the props change removes the component.
35
+ */
36
+ onChange?: (event: CheckBoxEvent) => void;
37
+
38
+ /**
39
+ * Invoked with the new value when the value changes.
40
+ */
41
+ onValueChange?: (value: boolean) => void;
42
+
43
+ /**
44
+ * If true the user won't be able to toggle the checkbox.
45
+ * Default value is false.
46
+ */
47
+ disabled?: boolean;
48
+
49
+ /**
50
+ * Used to locate this view in end-to-end tests.
51
+ */
52
+ testID?: string;
53
+ }
54
+ >;
55
+
56
+ type NativeProps = Readonly<
57
+ CommonProps & {
58
+ on?: boolean;
59
+ enabled?: boolean;
60
+ tintColors: {true?: any; false?: any} | undefined;
61
+ }
62
+ >;
63
+
64
+ type CheckBoxNativeType = HostInstance;
65
+
66
+ export type Props = Readonly<
67
+ CommonProps & {
68
+ /**
69
+ * The value of the checkbox. If true the checkbox will be turned on.
70
+ * Default value is false.
71
+ */
72
+ value?: boolean;
73
+
74
+ /**
75
+ * Used to get the ref for the native checkbox
76
+ */
77
+ forwardedRef?: React.Ref<CheckBoxNativeType>;
78
+
79
+ /**
80
+ * Controls the colors the checkbox has in checked and unchecked states.
81
+ * TODO: improve this type
82
+ */
83
+ tintColors?: {true?: any; false?: any};
84
+ }
85
+ >;
86
+
87
+ /**
88
+ * Renders a boolean input (Android only).
89
+ *
90
+ * This is a controlled component that requires an `onValueChange` callback that
91
+ * updates the `value` prop in order for the component to reflect user actions.
92
+ * If the `value` prop is not updated, the component will continue to render
93
+ * the supplied `value` prop instead of the expected result of any user actions.
94
+ *
95
+ * ```
96
+ * import React from 'react';
97
+ * import { AppRegistry, StyleSheet, Text, View, CheckBox } from 'react-native';
98
+ *
99
+ * export default class App extends React.Component {
100
+ * constructor(props) {
101
+ * super(props);
102
+ * this.state = {
103
+ * checked: false
104
+ * }
105
+ * }
106
+ *
107
+ * toggle() {
108
+ * this.setState(({checked}) => {
109
+ * return {
110
+ * checked: !checked
111
+ * };
112
+ * });
113
+ * }
114
+ *
115
+ * render() {
116
+ * const {checked} = this.state;
117
+ * return (
118
+ * <View style={styles.container}>
119
+ * <Text>Checked</Text>
120
+ * <CheckBox value={checked} onChange={this.toggle.bind(this)} />
121
+ * </View>
122
+ * );
123
+ * }
124
+ * }
125
+ *
126
+ * const styles = StyleSheet.create({
127
+ * container: {
128
+ * flex: 1,
129
+ * flexDirection: 'row',
130
+ * alignItems: 'center',
131
+ * justifyContent: 'center',
132
+ * },
133
+ * });
134
+ *
135
+ * // skip this line if using Create React Native App
136
+ * AppRegistry.registerComponent('App', () => App);
137
+ * ```
138
+ *
139
+ * @keyword checkbox
140
+ * @keyword toggle
141
+ */
142
+ class CheckBox extends React.Component<Props> {
143
+ _nativeRef: React.Ref<CheckBoxNativeType> | null = null;
144
+ _setNativeRef = setAndForwardRef({
145
+ getForwardedRef: () => this.props.forwardedRef,
146
+ setLocalRef: (ref: any) => {
147
+ this._nativeRef = ref;
148
+ },
149
+ });
150
+
151
+ _onChange = (event: CheckBoxEvent) => {
152
+ const value = this.props.value || false;
153
+
154
+ // @ts-ignore
155
+ nullthrows(this._nativeRef).setNativeProps({on: value});
156
+
157
+ // Change the props after the native props are set in case the props
158
+ // change removes the component
159
+ this.props.onChange && this.props.onChange(event);
160
+ this.props.onValueChange &&
161
+ this.props.onValueChange(event.nativeEvent.value);
162
+ };
163
+
164
+ getTintColors(tintColors: {true?: any; false?: any} | undefined) {
165
+ return tintColors
166
+ ? {
167
+ true: processColor(tintColors.true),
168
+ false: processColor(tintColors.false),
169
+ }
170
+ : undefined;
171
+ }
172
+
173
+ render() {
174
+ const {tintColors, style, ...props} = this.props;
175
+ const disabled = this.props.disabled || false;
176
+ const value = this.props.value || false;
177
+
178
+ const nativeProps = {
179
+ ...props,
180
+ onStartShouldSetResponder: () => true,
181
+ onResponderTerminationRequest: () => false,
182
+ enabled: !disabled,
183
+ on: value,
184
+ tintColors: this.getTintColors(tintColors),
185
+ style: [styles.rctCheckBox, style],
186
+ };
187
+ return (
188
+ <AndroidCheckBoxNativeComponent
189
+ {...nativeProps}
190
+ ref={this._setNativeRef}
191
+ // @ts-ignore TODO: implement the type of AndroidCheckBoxNativeComponent
192
+ onChange={this._onChange}
193
+ />
194
+ );
195
+ }
196
+ }
197
+
198
+ const styles = StyleSheet.create({
199
+ rctCheckBox: {
200
+ height: 32,
201
+ width: 32,
202
+ },
203
+ });
204
+
205
+ /**
206
+ * Can't use CheckBoxNativeType because it has different props
207
+ */
208
+ type CheckBoxType = HostInstance;
209
+
210
+ const CheckBoxWithRef = React.forwardRef(function CheckBoxWithRef(
211
+ props: Props,
212
+ ref: React.Ref<CheckBoxType>,
213
+ ) {
214
+ return <CheckBox {...props} forwardedRef={ref} />;
215
+ });
216
+
217
+ export default CheckBoxWithRef;
@@ -0,0 +1,175 @@
1
+ /**
2
+ * Copyright (c) Facebook, Inc. and its affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ * @format
8
+ */
9
+ 'use strict';
10
+
11
+ import nullthrows from 'nullthrows';
12
+ import React from 'react';
13
+ import {
14
+ StyleSheet,
15
+ ViewProps,
16
+ HostInstance,
17
+ NativeSyntheticEvent,
18
+ View,
19
+ } from 'react-native';
20
+ import IOSCheckBoxNativeComponent from './IOSCheckBoxNativeComponent';
21
+ // @ts-ignore setAndForwardRef type does not exist in @types/react-native
22
+ import setAndForwardRef from './setAndForwardRef';
23
+
24
+ type CheckBoxEvent = NativeSyntheticEvent<
25
+ Readonly<{
26
+ target: number;
27
+ value: boolean;
28
+ name: 'animation' | 'tap';
29
+ }>
30
+ >;
31
+
32
+ type CommonProps = Readonly<
33
+ ViewProps & {
34
+ /**
35
+ * Used to get the ref for the native checkbox
36
+ */
37
+ forwardedRef?: React.Ref<CheckBoxNativeType>;
38
+
39
+ /**
40
+ * The value of the checkbox. If true the checkbox will be turned on.
41
+ * Default value is false.
42
+ */
43
+ value?: boolean;
44
+
45
+ /**
46
+ * Used in case the props change removes the component.
47
+ */
48
+ onChange?: (event: CheckBoxEvent) => void;
49
+
50
+ /**
51
+ * Invoked with the new value when the value changes.
52
+ */
53
+ onValueChange?: (value: boolean) => void;
54
+
55
+ /**
56
+ * If true the user won't be able to toggle the checkbox.
57
+ * Default value is false.
58
+ */
59
+ disabled?: boolean;
60
+
61
+ /**
62
+ * Used to locate this view in end-to-end tests.
63
+ */
64
+ testID?: string;
65
+ }
66
+ >;
67
+
68
+ type CheckBoxNativeType = HostInstance;
69
+
70
+ type BoxType = 'circle' | 'square';
71
+ type AnimationType =
72
+ | 'stroke'
73
+ | 'fill'
74
+ | 'bounce'
75
+ | 'flat'
76
+ | 'one-stroke'
77
+ | 'fade';
78
+
79
+ export type Props = Readonly<
80
+ CommonProps & {
81
+ onAnimationDidStop?: Function;
82
+ lineWidth?: number;
83
+ hideBox?: boolean;
84
+ boxType?: BoxType;
85
+ tintColor?: string;
86
+ onCheckColor?: string;
87
+ onFillColor?: string;
88
+ onTintColor?: string;
89
+ animationDuration?: number;
90
+ onAnimationType?: AnimationType;
91
+ offAnimationType?: AnimationType;
92
+ }
93
+ >;
94
+
95
+ class CheckBox extends React.Component<Props> {
96
+ _nativeRef: React.Ref<CheckBoxNativeType> | null = null;
97
+ _setNativeRef = setAndForwardRef({
98
+ getForwardedRef: () => this.props.forwardedRef,
99
+ setLocalRef: (ref: any) => {
100
+ this._nativeRef = ref;
101
+ },
102
+ });
103
+
104
+ _onChange = (event: CheckBoxEvent) => {
105
+ const {onValueChange, onChange} = this.props;
106
+
107
+ // Reset the native checkbox back to the controlled `value` prop so the
108
+ // component behaves as a controlled input. Without this, iOS would keep
109
+ // whatever state the native tap produced, ignoring the `value` prop.
110
+ // This mirrors the Android implementation.
111
+ const value = this.props.value || false;
112
+ // @ts-ignore
113
+ nullthrows(this._nativeRef).setNativeProps({value});
114
+ onChange && onChange(event);
115
+ onValueChange && onValueChange(event.nativeEvent.value);
116
+ };
117
+
118
+ render() {
119
+ const {
120
+ accessible,
121
+ style,
122
+ // Do not use onValueChange directly from props
123
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
124
+ onValueChange,
125
+ disabled,
126
+ value,
127
+ testID,
128
+ ...props
129
+ } = this.props;
130
+ return (
131
+ <View
132
+ testID={testID}
133
+ pointerEvents={disabled ? 'none' : 'auto'}
134
+ accessible={accessible != null ? accessible : true}
135
+ accessibilityRole="checkbox"
136
+ accessibilityState={{
137
+ checked: value || false,
138
+ disabled: disabled || false,
139
+ }}
140
+ accessibilityValue={{text: value || false ? 'on' : 'off'}}>
141
+ <IOSCheckBoxNativeComponent
142
+ {...props}
143
+ // @ts-ignore TODO: implement the value type of IOSCheckBoxNativeComponent
144
+ value={value}
145
+ // @ts-ignore TODO: implement the style type of IOSCheckBoxNativeComponent
146
+ style={[styles.rctCheckBox, style]}
147
+ ref={this._setNativeRef}
148
+ onValueChange={this._onChange}
149
+ />
150
+ </View>
151
+ );
152
+ }
153
+ }
154
+
155
+ const styles = StyleSheet.create({
156
+ rctCheckBox: {
157
+ height: 32,
158
+ width: 32,
159
+ backgroundColor: 'transparent',
160
+ },
161
+ });
162
+
163
+ /**
164
+ * Can't use CheckBoxNativeType because it has different props
165
+ */
166
+ type CheckBoxType = HostInstance;
167
+
168
+ const CheckBoxWithRef = React.forwardRef(function CheckBoxWithRef(
169
+ props: Props,
170
+ ref: React.Ref<CheckBoxType>,
171
+ ) {
172
+ return <CheckBox {...props} forwardedRef={ref} />;
173
+ });
174
+
175
+ export default CheckBoxWithRef;
package/js/CheckBox.ts ADDED
@@ -0,0 +1,9 @@
1
+ export * from './CheckBox';
2
+
3
+ // Export the native component and its types (for Windows/New Architecture)
4
+ export {default as RNCCheckbox} from './RNCCheckboxNativeComponent';
5
+ export type {RNCCheckboxNativeProps} from './RNCCheckboxNativeComponent';
6
+
7
+ // Re-export the native module for direct access
8
+ export {default as NativeCheckboxModule} from './NativeCheckboxModule';
9
+ export type {Spec as NativeCheckboxModuleSpec} from './NativeCheckboxModule';