@solidx/checkbox 0.7.0 → 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.
- package/LICENSE +21 -0
- package/NuGet.config +11 -0
- package/RNCCheckbox.podspec +3 -3
- package/android/build.gradle +19 -8
- package/android/src/main/AndroidManifest.xml +1 -2
- package/android/src/main/java/com/reactnativecommunity/checkbox/ReactCheckBoxEvent.java +3 -8
- package/android/src/main/java/com/reactnativecommunity/checkbox/ReactCheckBoxManager.java +7 -13
- package/dist/js/AndroidCheckBoxNativeComponent.d.ts +2 -0
- package/dist/{AndroidCheckBoxNativeComponent.js → js/AndroidCheckBoxNativeComponent.js} +1 -1
- package/dist/{CheckBox.android.d.ts → js/CheckBox.android.d.ts} +13 -13
- package/dist/{CheckBox.android.js → js/CheckBox.android.js} +7 -5
- package/dist/js/CheckBox.d.ts +5 -0
- package/dist/{CheckBox.ios.d.ts → js/CheckBox.ios.d.ts} +25 -25
- package/dist/{CheckBox.ios.js → js/CheckBox.ios.js} +11 -5
- package/dist/js/CheckBox.js +27 -0
- package/dist/js/CheckBox.windows.d.ts +95 -0
- package/dist/{CheckBox.windows.js → js/CheckBox.windows.js} +20 -21
- package/dist/js/CheckboxNativeComponent.d.ts +11 -0
- package/dist/js/CheckboxNativeComponent.js +22 -0
- package/dist/js/IOSCheckBoxNativeComponent.d.ts +2 -0
- package/dist/{IOSCheckBoxNativeComponent.js → js/IOSCheckBoxNativeComponent.js} +1 -1
- package/dist/js/NativeCheckboxModule.d.ts +11 -0
- package/dist/js/NativeCheckboxModule.js +10 -0
- package/dist/js/RNCCheckboxNativeComponent.d.ts +48 -0
- package/dist/js/RNCCheckboxNativeComponent.js +12 -0
- package/dist/js/index.d.ts +11 -0
- package/dist/js/index.js +34 -0
- package/dist/{setAndForwardRef.d.ts → js/setAndForwardRef.d.ts} +1 -1
- package/dist/{setAndForwardRef.js → js/setAndForwardRef.js} +2 -1
- package/jest.config.windows.js +3 -0
- package/js/AndroidCheckBoxNativeComponent.ts +12 -0
- package/js/CheckBox.android.tsx +217 -0
- package/js/CheckBox.ios.tsx +175 -0
- package/js/CheckBox.ts +9 -0
- package/js/CheckBox.windows.tsx +158 -0
- package/js/CheckboxNativeComponent.ts +25 -0
- package/js/IOSCheckBoxNativeComponent.ts +12 -0
- package/js/NativeCheckboxModule.ts +15 -0
- package/js/RNCCheckboxNativeComponent.ts +68 -0
- package/js/index.ts +17 -0
- package/js/setAndForwardRef.ts +64 -0
- package/metro.config.js +45 -0
- package/package.json +61 -53
- package/react-native.config.js +22 -0
- package/typings/index.d.ts +5 -5
- package/windows/Checkbox/Checkbox.cpp +20 -0
- package/windows/Checkbox/Checkbox.h +26 -0
- package/windows/Checkbox/Checkbox.rc +0 -0
- package/windows/Checkbox/Checkbox.vcxproj +146 -0
- package/windows/Checkbox/Checkbox.vcxproj.filters +56 -0
- package/windows/Checkbox/CheckboxView.cpp +186 -0
- package/windows/Checkbox/CheckboxView.h +59 -0
- package/windows/Checkbox/ReactPackageProvider.cpp +24 -0
- package/windows/Checkbox/ReactPackageProvider.h +24 -0
- package/windows/Checkbox/ReactPackageProvider.idl +9 -0
- package/windows/Checkbox/codegen/.clang-format +2 -0
- package/windows/Checkbox/codegen/NativeCheckboxModuleSpec.g.h +31 -0
- package/windows/Checkbox/codegen_manual/react/components/RNCCheckboxSpec/RNCCheckbox.g.h +232 -0
- package/windows/Checkbox/packages.lock.json +151 -0
- package/windows/Checkbox/pch.cpp +1 -0
- package/windows/Checkbox/pch.h +43 -0
- package/windows/Checkbox/resource.h +5 -0
- package/windows/Checkbox/targetver.h +8 -0
- package/windows/Checkbox.sln +43 -0
- package/windows/ExperimentalFeatures.props +33 -0
- package/dist/AndroidCheckBoxNativeComponent.d.ts +0 -2
- package/dist/CheckBox.d.ts +0 -1
- package/dist/CheckBox.js +0 -2
- package/dist/CheckBox.windows.d.ts +0 -77
- package/dist/IOSCheckBoxNativeComponent.d.ts +0 -2
- package/dist/WindowsCheckBoxComponent.d.ts +0 -2
- package/dist/WindowsCheckBoxComponent.js +0 -6
- package/windows/CheckboxWindows/CheckboxView.cpp +0 -116
- package/windows/CheckboxWindows/CheckboxView.h +0 -33
- package/windows/CheckboxWindows/CheckboxView.idl +0 -11
- package/windows/CheckboxWindows/CheckboxViewManager.cpp +0 -73
- package/windows/CheckboxWindows/CheckboxViewManager.h +0 -44
- package/windows/CheckboxWindows/CheckboxWindows.rc +0 -0
- package/windows/CheckboxWindows/CheckboxWindows.vcxproj +0 -189
- package/windows/CheckboxWindows/CheckboxWindows.vcxproj.filters +0 -43
- package/windows/CheckboxWindows/PropertySheet.props +0 -16
- package/windows/CheckboxWindows/ReactPackageProvider.cpp +0 -18
- package/windows/CheckboxWindows/ReactPackageProvider.h +0 -23
- package/windows/CheckboxWindows/ReactPackageProvider.idl +0 -9
- package/windows/CheckboxWindows/packages.config +0 -4
- package/windows/CheckboxWindows/pch.cpp +0 -1
- package/windows/CheckboxWindows/pch.h +0 -4
- package/windows/CheckboxWindows/readme.txt +0 -23
- package/windows/CheckboxWindows/resource.h +0 -14
- package/windows/CheckboxWindows.sln +0 -226
- package/windows/CheckboxWindows62.sln +0 -254
- /package/windows/{CheckboxWindows/CheckboxWindows.def → Checkbox/Checkbox.def} +0 -0
|
@@ -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';
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Microsoft Corporation.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*
|
|
5
|
+
* @format
|
|
6
|
+
*/
|
|
7
|
+
'use strict';
|
|
8
|
+
|
|
9
|
+
import React from 'react';
|
|
10
|
+
import {
|
|
11
|
+
StyleSheet,
|
|
12
|
+
ViewProps,
|
|
13
|
+
HostInstance,
|
|
14
|
+
NativeSyntheticEvent,
|
|
15
|
+
} from 'react-native';
|
|
16
|
+
import RNCCheckboxNativeComponent from './RNCCheckboxNativeComponent';
|
|
17
|
+
// @ts-ignore setAndForwardRef type does not exist in @types/react-native
|
|
18
|
+
import setAndForwardRef from './setAndForwardRef';
|
|
19
|
+
|
|
20
|
+
type CheckBoxEvent = NativeSyntheticEvent<
|
|
21
|
+
Readonly<{
|
|
22
|
+
value: boolean;
|
|
23
|
+
}>
|
|
24
|
+
>;
|
|
25
|
+
|
|
26
|
+
type CheckBoxNativeType = HostInstance;
|
|
27
|
+
|
|
28
|
+
export type Props = Readonly<
|
|
29
|
+
ViewProps & {
|
|
30
|
+
/**
|
|
31
|
+
* Used to get the ref for the native checkbox
|
|
32
|
+
*/
|
|
33
|
+
forwardedRef?: React.Ref<CheckBoxNativeType>;
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* The value of the checkbox. If true the checkbox will be turned on.
|
|
37
|
+
* Default value is false.
|
|
38
|
+
*/
|
|
39
|
+
value?: boolean;
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* If true the user won't be able to toggle the checkbox.
|
|
43
|
+
* Default value is false.
|
|
44
|
+
*/
|
|
45
|
+
disabled?: boolean;
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Used in case the props change removes the component.
|
|
49
|
+
*/
|
|
50
|
+
onChange?: (event: CheckBoxEvent) => void;
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Invoked with the new value when the value changes.
|
|
54
|
+
*/
|
|
55
|
+
onValueChange?: (value: boolean) => void;
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Used to set the color of the box when unchecked.
|
|
59
|
+
*/
|
|
60
|
+
tintColor?: string;
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Used to set the color of the check mark when the checkbox is checked.
|
|
64
|
+
*/
|
|
65
|
+
onCheckColor?: string;
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Used to set the tint color of the checkbox border when it is checked.
|
|
69
|
+
*/
|
|
70
|
+
onTintColor?: string;
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Used to set the fill color of the checkbox when it is checked.
|
|
74
|
+
*/
|
|
75
|
+
onFillColor?: string;
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Used to locate this view in end-to-end tests.
|
|
79
|
+
*/
|
|
80
|
+
testID?: string;
|
|
81
|
+
}
|
|
82
|
+
>;
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Renders a boolean checkbox input (Windows).
|
|
86
|
+
*
|
|
87
|
+
* This is a controlled component that requires an `onValueChange` callback that
|
|
88
|
+
* updates the `value` prop in order for the component to reflect user actions.
|
|
89
|
+
* If the `value` prop is not updated, the component will continue to render
|
|
90
|
+
* the supplied `value` prop instead of the expected result of any user actions.
|
|
91
|
+
*/
|
|
92
|
+
class CheckBox extends React.Component<Props> {
|
|
93
|
+
_nativeRef: React.Ref<CheckBoxNativeType> | null = null;
|
|
94
|
+
_setNativeRef = setAndForwardRef({
|
|
95
|
+
getForwardedRef: () => this.props.forwardedRef,
|
|
96
|
+
setLocalRef: (ref: any) => {
|
|
97
|
+
this._nativeRef = ref;
|
|
98
|
+
},
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
_onChange = (event: CheckBoxEvent) => {
|
|
102
|
+
const {onChange, onValueChange} = this.props;
|
|
103
|
+
|
|
104
|
+
onChange && onChange(event);
|
|
105
|
+
onValueChange && onValueChange(event.nativeEvent.value);
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
render() {
|
|
109
|
+
const {
|
|
110
|
+
style,
|
|
111
|
+
value,
|
|
112
|
+
disabled,
|
|
113
|
+
tintColor,
|
|
114
|
+
onCheckColor,
|
|
115
|
+
onTintColor,
|
|
116
|
+
onFillColor,
|
|
117
|
+
testID,
|
|
118
|
+
...props
|
|
119
|
+
} = this.props;
|
|
120
|
+
|
|
121
|
+
return (
|
|
122
|
+
<RNCCheckboxNativeComponent
|
|
123
|
+
{...props}
|
|
124
|
+
testID={testID}
|
|
125
|
+
value={value ?? false}
|
|
126
|
+
disabled={disabled ?? false}
|
|
127
|
+
tintColor={tintColor}
|
|
128
|
+
onCheckColor={onCheckColor}
|
|
129
|
+
onTintColor={onTintColor}
|
|
130
|
+
onFillColor={onFillColor}
|
|
131
|
+
style={[styles.rctCheckBox, style]}
|
|
132
|
+
ref={this._setNativeRef}
|
|
133
|
+
onChange={this._onChange}
|
|
134
|
+
/>
|
|
135
|
+
);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
const styles = StyleSheet.create({
|
|
140
|
+
rctCheckBox: {
|
|
141
|
+
height: 32,
|
|
142
|
+
width: 32,
|
|
143
|
+
},
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* Can't use CheckBoxNativeType because it has different props
|
|
148
|
+
*/
|
|
149
|
+
type CheckBoxType = HostInstance;
|
|
150
|
+
|
|
151
|
+
const CheckBoxWithRef = React.forwardRef(function CheckBoxWithRef(
|
|
152
|
+
props: Props,
|
|
153
|
+
ref: React.Ref<CheckBoxType>,
|
|
154
|
+
) {
|
|
155
|
+
return <CheckBox {...props} forwardedRef={ref} />;
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
export default CheckBoxWithRef;
|
|
@@ -0,0 +1,25 @@
|
|
|
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
|
+
|
|
10
|
+
'use strict';
|
|
11
|
+
|
|
12
|
+
import type {HostComponent} from 'react-native';
|
|
13
|
+
import {Platform} from 'react-native';
|
|
14
|
+
|
|
15
|
+
let CheckboxNativeComponent: HostComponent<any>;
|
|
16
|
+
|
|
17
|
+
if (Platform.OS === 'android') {
|
|
18
|
+
CheckboxNativeComponent = require('./AndroidCheckBoxNativeComponent').default;
|
|
19
|
+
} else if (Platform.OS === 'windows') {
|
|
20
|
+
CheckboxNativeComponent = require('./RNCCheckboxNativeComponent').default;
|
|
21
|
+
} else {
|
|
22
|
+
CheckboxNativeComponent = require('./IOSCheckBoxNativeComponent').default;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export default CheckboxNativeComponent;
|
|
@@ -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('RNCCheckbox');
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*
|
|
5
|
+
* @format
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
'use strict';
|
|
9
|
+
|
|
10
|
+
import type {TurboModule} from 'react-native';
|
|
11
|
+
import {TurboModuleRegistry} from 'react-native';
|
|
12
|
+
|
|
13
|
+
export interface Spec extends TurboModule {}
|
|
14
|
+
|
|
15
|
+
export default TurboModuleRegistry.get<Spec>('Checkbox') as Spec | null;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*
|
|
5
|
+
* @format
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
'use strict';
|
|
9
|
+
|
|
10
|
+
import type {
|
|
11
|
+
ViewProps,
|
|
12
|
+
ColorValue,
|
|
13
|
+
HostComponent,
|
|
14
|
+
CodegenTypes,
|
|
15
|
+
} from 'react-native';
|
|
16
|
+
import {codegenNativeComponent} from 'react-native';
|
|
17
|
+
|
|
18
|
+
type CheckBoxChangeEvent = Readonly<{
|
|
19
|
+
value: boolean;
|
|
20
|
+
}>;
|
|
21
|
+
|
|
22
|
+
export interface RNCCheckboxNativeProps extends ViewProps {
|
|
23
|
+
/**
|
|
24
|
+
* If true the user won't be able to toggle the checkbox.
|
|
25
|
+
* Default value is false.
|
|
26
|
+
*/
|
|
27
|
+
disabled?: CodegenTypes.WithDefault<boolean, false>;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* The value of the checkbox. If true the checkbox will be turned on.
|
|
31
|
+
* Default value is false.
|
|
32
|
+
*/
|
|
33
|
+
value?: CodegenTypes.WithDefault<boolean, false>;
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Used to set the color of the checkbox when it is disabled.
|
|
37
|
+
*/
|
|
38
|
+
tintColor?: ColorValue;
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Used to set the color of the check mark when the checkbox is checked.
|
|
42
|
+
*/
|
|
43
|
+
onCheckColor?: ColorValue;
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Used to set the tint color of the checkbox when it is checked.
|
|
47
|
+
*/
|
|
48
|
+
onTintColor?: ColorValue;
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Used to set the fill color of the checkbox when it is checked.
|
|
52
|
+
*/
|
|
53
|
+
onFillColor?: ColorValue;
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* The label to display next to the checkbox.
|
|
57
|
+
*/
|
|
58
|
+
label?: string;
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Called when the checkbox value changes.
|
|
62
|
+
*/
|
|
63
|
+
onChange?: CodegenTypes.BubblingEventHandler<CheckBoxChangeEvent>;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export default codegenNativeComponent<RNCCheckboxNativeProps>('RNCCheckbox', {
|
|
67
|
+
excludedPlatforms: ['iOS', 'android'],
|
|
68
|
+
}) as HostComponent<RNCCheckboxNativeProps>;
|
package/js/index.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Microsoft Corporation.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*
|
|
5
|
+
* @format
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
// Re-export everything from CheckBox.ts
|
|
9
|
+
export * from './CheckBox';
|
|
10
|
+
|
|
11
|
+
// Export the native component and its types (for Windows/New Architecture)
|
|
12
|
+
export {default as RNCCheckbox} from './RNCCheckboxNativeComponent';
|
|
13
|
+
export type {RNCCheckboxNativeProps} from './RNCCheckboxNativeComponent';
|
|
14
|
+
|
|
15
|
+
// Re-export the native module for direct access
|
|
16
|
+
export {default as NativeCheckboxModule} from './NativeCheckboxModule';
|
|
17
|
+
export type {Spec as NativeCheckboxModuleSpec} from './NativeCheckboxModule';
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Imported from RN .71
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import type {ElementRef} from 'react';
|
|
6
|
+
|
|
7
|
+
type Args = {
|
|
8
|
+
getForwardedRef: () => React.Ref<any> | undefined;
|
|
9
|
+
setLocalRef: (ref: ElementRef<any>) => any;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* This is a helper function for when a component needs to be able to forward a ref
|
|
14
|
+
* to a child component, but still needs to have access to that component as part of
|
|
15
|
+
* its implementation.
|
|
16
|
+
*
|
|
17
|
+
* Its main use case is in wrappers for native components.
|
|
18
|
+
*
|
|
19
|
+
* Usage:
|
|
20
|
+
*
|
|
21
|
+
* class MyView extends React.Component {
|
|
22
|
+
* _nativeRef = null;
|
|
23
|
+
*
|
|
24
|
+
* _setNativeRef = setAndForwardRef({
|
|
25
|
+
* getForwardedRef: () => this.props.forwardedRef,
|
|
26
|
+
* setLocalRef: ref => {
|
|
27
|
+
* this._nativeRef = ref;
|
|
28
|
+
* },
|
|
29
|
+
* });
|
|
30
|
+
*
|
|
31
|
+
* render() {
|
|
32
|
+
* return <View ref={this._setNativeRef} />;
|
|
33
|
+
* }
|
|
34
|
+
* }
|
|
35
|
+
*
|
|
36
|
+
* const MyViewWithRef = React.forwardRef((props, ref) => (
|
|
37
|
+
* <MyView {...props} forwardedRef={ref} />
|
|
38
|
+
* ));
|
|
39
|
+
*
|
|
40
|
+
* module.exports = MyViewWithRef;
|
|
41
|
+
*/
|
|
42
|
+
|
|
43
|
+
function setAndForwardRef({
|
|
44
|
+
getForwardedRef,
|
|
45
|
+
setLocalRef,
|
|
46
|
+
}: Args): (ref: ElementRef<any>) => void {
|
|
47
|
+
return function forwardRef(ref: ElementRef<any>) {
|
|
48
|
+
const forwardedRef = getForwardedRef();
|
|
49
|
+
|
|
50
|
+
setLocalRef(ref);
|
|
51
|
+
|
|
52
|
+
// Forward to user ref prop (if one has been specified)
|
|
53
|
+
if (typeof forwardedRef === 'function') {
|
|
54
|
+
// Handle function-based refs. String-based refs are handled as functions.
|
|
55
|
+
forwardedRef(ref);
|
|
56
|
+
} else if (typeof forwardedRef === 'object' && forwardedRef != null) {
|
|
57
|
+
// Handle createRef-based refs
|
|
58
|
+
// @ts-ignore - We need to set current even though it's readonly
|
|
59
|
+
forwardedRef.current = ref;
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export default setAndForwardRef;
|
package/metro.config.js
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
const {getDefaultConfig, mergeConfig} = require('@react-native/metro-config');
|
|
2
|
+
|
|
3
|
+
const fs = require('fs');
|
|
4
|
+
const path = require('path');
|
|
5
|
+
const exclusionList = require('metro-config/src/defaults/exclusionList');
|
|
6
|
+
|
|
7
|
+
const rnwPath = fs.realpathSync(
|
|
8
|
+
path.resolve(require.resolve('react-native-windows/package.json'), '..'),
|
|
9
|
+
);
|
|
10
|
+
|
|
11
|
+
//
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Metro configuration
|
|
15
|
+
* https://facebook.github.io/metro/docs/configuration
|
|
16
|
+
*
|
|
17
|
+
* @type {import('metro-config').MetroConfig}
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
const config = {
|
|
21
|
+
//
|
|
22
|
+
resolver: {
|
|
23
|
+
blockList: exclusionList([
|
|
24
|
+
// This stops "npx @react-native-community/cli run-windows" from causing the metro server to crash if its already running
|
|
25
|
+
new RegExp(
|
|
26
|
+
`${path.resolve(__dirname, 'windows').replace(/[/\\]/g, '/')}.*`,
|
|
27
|
+
),
|
|
28
|
+
// This prevents "npx @react-native-community/cli run-windows" from hitting: EBUSY: resource busy or locked, open msbuild.ProjectImports.zip or other files produced by msbuild
|
|
29
|
+
new RegExp(`${rnwPath}/build/.*`),
|
|
30
|
+
new RegExp(`${rnwPath}/target/.*`),
|
|
31
|
+
/.*\.ProjectImports\.zip/,
|
|
32
|
+
]),
|
|
33
|
+
//
|
|
34
|
+
},
|
|
35
|
+
transformer: {
|
|
36
|
+
getTransformOptions: async () => ({
|
|
37
|
+
transform: {
|
|
38
|
+
experimentalImportSupport: false,
|
|
39
|
+
inlineRequires: true,
|
|
40
|
+
},
|
|
41
|
+
}),
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
module.exports = mergeConfig(getDefaultConfig(__dirname), config);
|