@react-native-oh/react-native-harmony 0.72.82 → 0.77.18
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/LICENSE-Meta +21 -0
- package/Libraries/Alert/delegates/AlertDelegate.harmony.ts +84 -0
- package/Libraries/Alert/{AlertManager.ts → delegates/AlertManager.harmony.ts} +10 -4
- package/Libraries/Animated/shouldUseTurboAnimatedModule.harmony.ts +10 -0
- package/Libraries/Components/AccessibilityInfo/delegates/AccessibilityInfoDelegate.harmony.ts +44 -0
- package/Libraries/Components/AccessibilityInfo/{NativeAccessibilityInfoHarmony.ts → delegates/NativeAccessibilityInfoHarmony.harmony.ts} +9 -2
- package/Libraries/Components/Keyboard/delegates/KeyboardAvoidingViewDelegate.harmony.ts +42 -0
- package/Libraries/Components/RefreshControl/delegates/RefreshControlDelegate.harmony.tsx +29 -0
- package/Libraries/Components/SafeAreaView/SafeAreaView.harmony.tsx +93 -31
- package/Libraries/Components/ScrollView/delegates/ScrollViewDelegate.harmony.tsx +41 -0
- package/Libraries/Components/ScrollView/delegates/ScrollViewNativeComponentDelegate.harmony.ts +89 -0
- package/Libraries/Components/ScrollView/processDecelerationRate.harmony.ts +19 -0
- package/Libraries/Components/StatusBar/delegates/NativeStatusBarManagerHarmony.harmony.ts +53 -0
- package/Libraries/Components/StatusBar/delegates/StatusBarDelegate.harmony.ts +83 -0
- package/Libraries/Components/TextInput/delegates/TextInputDelegate.harmony.tsx +98 -0
- package/Libraries/Components/TextInput/delegates/TextInputStateDelegate.harmony.tsx +20 -0
- package/Libraries/Components/Touchable/delegates/TouchableHighlightDelegate.harmony.ts +14 -0
- package/Libraries/Components/Touchable/delegates/TouchableNativeFeedbackDelegate.harmony.ts +14 -0
- package/Libraries/Components/Touchable/delegates/TouchableWithoutFeedbackDelegate.harmony.ts +14 -0
- package/Libraries/Components/delegates/ButtonDelegate.harmony.ts +41 -0
- package/Libraries/Core/setUpPlatform.harmony.js +30 -0
- package/Libraries/Image/AssetSourceResolver.harmony.ts +75 -29
- package/Libraries/Image/Image.harmony.ts +17 -0
- package/Libraries/NativeComponent/BaseViewConfig.harmony.js +12 -326
- package/Libraries/NativeComponent/delegates/ViewConfigIgnoreDelegate.harmony.ts +13 -0
- package/Libraries/ReactNative/delegates/BridgelessUIManagerDelegate.harmony.ts +14 -0
- package/Libraries/ReactNative/delegates/I18nManagerDelegate.harmony.ts +22 -0
- package/Libraries/Settings/Settings.harmony.ts +20 -0
- package/Libraries/Share/delegates/ShareDelegate.harmony.ts +42 -0
- package/Libraries/StyleSheet/NativePlatformColor.harmony.ts +15 -0
- package/Libraries/StyleSheet/PlatformColorValueTypes.harmony.ts +8 -1
- package/Libraries/Utilities/BackHandler.harmony.ts +10 -0
- package/Libraries/Utilities/NativePlatformConstantsHarmony.harmony.ts +17 -0
- package/Libraries/Utilities/Platform.harmony.ts +38 -13
- package/Libraries/Vibration/delegates/VibrationDelegate.harmony.ts +14 -0
- package/NOTICE.md +846 -0
- package/README.md +2 -2
- package/index.js +53 -63
- package/jest.config.js +0 -7
- package/metro.config.d.ts +17 -0
- package/metro.config.js +398 -115
- package/package.json +58 -37
- package/react-native.config.js +57 -9
- package/react_native_openharmony.har +0 -0
- package/tsconfig.json +10 -4
- package/types/index.harmony.d.ts +99 -0
- package/Libraries/Alert/Alert.harmony.js +0 -77
- package/Libraries/Animated/NativeAnimatedHelper.harmony.js +0 -601
- package/Libraries/Components/AccessibilityInfo/AccessibilityInfo.harmony.js +0 -441
- package/Libraries/Components/Button/Button.harmony.js +0 -451
- package/Libraries/Components/Image/Image.flow.harmony.js +0 -53
- package/Libraries/Components/Image/Image.harmony.js +0 -317
- package/Libraries/Components/Image/NativeImageLoaderHarmony.js +0 -38
- package/Libraries/Components/Keyboard/KeyboardAvoidingView.harmony.js +0 -256
- package/Libraries/Components/RefreshControl/RefreshControl.harmony.js +0 -210
- package/Libraries/Components/ScrollView/ScrollView.harmony.js +0 -1951
- package/Libraries/Components/ScrollView/processDecelerationRate.harmony.js +0 -24
- package/Libraries/Components/StatusBar/NativeStatusBarManagerHarmony.js +0 -71
- package/Libraries/Components/StatusBar/StatusBar.harmony.js +0 -447
- package/Libraries/Components/TextInput/TextInput.harmony.js +0 -1716
- package/Libraries/Components/TextInput/TextInputState.harmony.js +0 -220
- package/Libraries/Components/Touchable/TouchableHighlight.harmony.js +0 -396
- package/Libraries/Components/Touchable/TouchableNativeFeedback.harmony.js +0 -364
- package/Libraries/Components/Touchable/TouchableWithoutFeedback.harmony.js +0 -227
- package/Libraries/Components/View/View.harmony.js +0 -149
- package/Libraries/Core/setUpReactDevTools.harmony.js +0 -93
- package/Libraries/ReactNative/I18nManager.harmony.js +0 -78
- package/Libraries/ReactNative/UIManager.harmony.js +0 -210
- package/Libraries/Settings/Settings.harmony.js +0 -15
- package/Libraries/Share/Share.harmony.js +0 -174
- package/Libraries/StyleSheet/NativePlatformColor.ts +0 -8
- package/Libraries/Utilities/BackHandler.harmony.js +0 -109
- package/Libraries/Utilities/NativePlatformConstants.harmony.ts +0 -8
- package/Libraries/Utilities/Platform.d.ts +0 -117
- package/Libraries/Utilities/createPerformanceLogger.harmony.js +0 -328
- package/Libraries/Vibration/Vibration.harmony.js +0 -88
- package/harmony/.keep +0 -0
- package/harmony/rnoh-hvigor-plugin-0.2.0.tgz +0 -0
- package/react_native_openharmony_release.har +0 -0
- package/types/index.d.ts +0 -108
|
@@ -1,220 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (c) Meta Platforms, Inc. and 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
|
-
* @flow strict-local
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
// This class is responsible for coordinating the "focused" state for
|
|
12
|
-
// TextInputs. All calls relating to the keyboard should be funneled
|
|
13
|
-
// through here.
|
|
14
|
-
|
|
15
|
-
// RNOH: patch - update imports
|
|
16
|
-
|
|
17
|
-
import type {
|
|
18
|
-
HostComponent,
|
|
19
|
-
MeasureInWindowOnSuccessCallback,
|
|
20
|
-
MeasureLayoutOnSuccessCallback,
|
|
21
|
-
MeasureOnSuccessCallback,
|
|
22
|
-
} from "react-native/Libraries/Renderer/shims/ReactNativeTypes";
|
|
23
|
-
|
|
24
|
-
import { Commands as AndroidTextInputCommands } from "react-native/Libraries/Components/TextInput/AndroidTextInputNativeComponent";
|
|
25
|
-
import { Commands as iOSTextInputCommands } from "react-native/Libraries/Components/TextInput/RCTSingelineTextInputNativeComponent";
|
|
26
|
-
|
|
27
|
-
const {
|
|
28
|
-
findNodeHandle,
|
|
29
|
-
} = require("react-native/Libraries/ReactNative/RendererProxy");
|
|
30
|
-
const React = require("react");
|
|
31
|
-
type ComponentRef = React.ElementRef<HostComponent<mixed>>;
|
|
32
|
-
|
|
33
|
-
// RNOH: patch - replace Platform.OS occurences with hardcoded PlatformOS
|
|
34
|
-
const PlatformOS = "ios";
|
|
35
|
-
|
|
36
|
-
let currentlyFocusedInputRef: ?ComponentRef = null;
|
|
37
|
-
const inputs = new Set<{
|
|
38
|
-
blur(): void,
|
|
39
|
-
focus(): void,
|
|
40
|
-
measure(callback: MeasureOnSuccessCallback): void,
|
|
41
|
-
measureInWindow(callback: MeasureInWindowOnSuccessCallback): void,
|
|
42
|
-
measureLayout(
|
|
43
|
-
relativeToNativeNode: number | React.ElementRef<HostComponent<mixed>>,
|
|
44
|
-
onSuccess: MeasureLayoutOnSuccessCallback,
|
|
45
|
-
onFail?: () => void
|
|
46
|
-
): void,
|
|
47
|
-
setNativeProps(nativeProps: { ... }): void,
|
|
48
|
-
}>();
|
|
49
|
-
|
|
50
|
-
function currentlyFocusedInput(): ?ComponentRef {
|
|
51
|
-
return currentlyFocusedInputRef;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* Returns the ID of the currently focused text field, if one exists
|
|
56
|
-
* If no text field is focused it returns null
|
|
57
|
-
*/
|
|
58
|
-
function currentlyFocusedField(): ?number {
|
|
59
|
-
if (__DEV__) {
|
|
60
|
-
console.error(
|
|
61
|
-
"currentlyFocusedField is deprecated and will be removed in a future release. Use currentlyFocusedInput"
|
|
62
|
-
);
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
return findNodeHandle(currentlyFocusedInputRef);
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
function focusInput(textField: ?ComponentRef): void {
|
|
69
|
-
if (currentlyFocusedInputRef !== textField && textField != null) {
|
|
70
|
-
currentlyFocusedInputRef = textField;
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
function blurInput(textField: ?ComponentRef): void {
|
|
75
|
-
if (currentlyFocusedInputRef === textField && textField != null) {
|
|
76
|
-
currentlyFocusedInputRef = null;
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
function focusField(textFieldID: ?number): void {
|
|
81
|
-
if (__DEV__) {
|
|
82
|
-
console.error("focusField no longer works. Use focusInput");
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
return;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
function blurField(textFieldID: ?number) {
|
|
89
|
-
if (__DEV__) {
|
|
90
|
-
console.error("blurField no longer works. Use blurInput");
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
return;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
/**
|
|
97
|
-
* @param {number} TextInputID id of the text field to focus
|
|
98
|
-
* Focuses the specified text field
|
|
99
|
-
* noop if the text field was already focused or if the field is not editable
|
|
100
|
-
*/
|
|
101
|
-
function focusTextInput(textField: ?ComponentRef) {
|
|
102
|
-
if (typeof textField === "number") {
|
|
103
|
-
if (__DEV__) {
|
|
104
|
-
console.error(
|
|
105
|
-
"focusTextInput must be called with a host component. Passing a react tag is deprecated."
|
|
106
|
-
);
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
return;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
if (textField != null) {
|
|
113
|
-
const fieldCanBeFocused =
|
|
114
|
-
currentlyFocusedInputRef !== textField &&
|
|
115
|
-
// $FlowFixMe - `currentProps` is missing in `NativeMethods`
|
|
116
|
-
textField.currentProps?.editable !== false;
|
|
117
|
-
|
|
118
|
-
if (!fieldCanBeFocused) {
|
|
119
|
-
return;
|
|
120
|
-
}
|
|
121
|
-
focusInput(textField);
|
|
122
|
-
if (PlatformOS === "ios") {
|
|
123
|
-
// This isn't necessarily a single line text input
|
|
124
|
-
// But commands don't actually care as long as the thing being passed in
|
|
125
|
-
// actually has a command with that name. So this should work with single
|
|
126
|
-
// and multiline text inputs. Ideally we'll merge them into one component
|
|
127
|
-
// in the future.
|
|
128
|
-
iOSTextInputCommands.focus(textField);
|
|
129
|
-
} else if (PlatformOS === "android") {
|
|
130
|
-
AndroidTextInputCommands.focus(textField);
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
/**
|
|
136
|
-
* @param {number} textFieldID id of the text field to unfocus
|
|
137
|
-
* Unfocuses the specified text field
|
|
138
|
-
* noop if it wasn't focused
|
|
139
|
-
*/
|
|
140
|
-
function blurTextInput(textField: ?ComponentRef) {
|
|
141
|
-
if (typeof textField === "number") {
|
|
142
|
-
if (__DEV__) {
|
|
143
|
-
console.error(
|
|
144
|
-
"blurTextInput must be called with a host component. Passing a react tag is deprecated."
|
|
145
|
-
);
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
return;
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
if (currentlyFocusedInputRef === textField && textField != null) {
|
|
152
|
-
blurInput(textField);
|
|
153
|
-
if (PlatformOS === "ios") {
|
|
154
|
-
// This isn't necessarily a single line text input
|
|
155
|
-
// But commands don't actually care as long as the thing being passed in
|
|
156
|
-
// actually has a command with that name. So this should work with single
|
|
157
|
-
// and multiline text inputs. Ideally we'll merge them into one component
|
|
158
|
-
// in the future.
|
|
159
|
-
iOSTextInputCommands.blur(textField);
|
|
160
|
-
} else if (PlatformOS === "android") {
|
|
161
|
-
AndroidTextInputCommands.blur(textField);
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
function registerInput(textField: ComponentRef) {
|
|
167
|
-
if (typeof textField === "number") {
|
|
168
|
-
if (__DEV__) {
|
|
169
|
-
console.error(
|
|
170
|
-
"registerInput must be called with a host component. Passing a react tag is deprecated."
|
|
171
|
-
);
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
return;
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
inputs.add(textField);
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
function unregisterInput(textField: ComponentRef) {
|
|
181
|
-
if (typeof textField === "number") {
|
|
182
|
-
if (__DEV__) {
|
|
183
|
-
console.error(
|
|
184
|
-
"unregisterInput must be called with a host component. Passing a react tag is deprecated."
|
|
185
|
-
);
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
return;
|
|
189
|
-
}
|
|
190
|
-
inputs.delete(textField);
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
function isTextInput(textField: ComponentRef): boolean {
|
|
194
|
-
if (typeof textField === "number") {
|
|
195
|
-
if (__DEV__) {
|
|
196
|
-
console.error(
|
|
197
|
-
"isTextInput must be called with a host component. Passing a react tag is deprecated."
|
|
198
|
-
);
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
return false;
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
return inputs.has(textField);
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
module.exports = {
|
|
208
|
-
currentlyFocusedInput,
|
|
209
|
-
focusInput,
|
|
210
|
-
blurInput,
|
|
211
|
-
|
|
212
|
-
currentlyFocusedField,
|
|
213
|
-
focusField,
|
|
214
|
-
blurField,
|
|
215
|
-
focusTextInput,
|
|
216
|
-
blurTextInput,
|
|
217
|
-
registerInput,
|
|
218
|
-
unregisterInput,
|
|
219
|
-
isTextInput,
|
|
220
|
-
};
|
|
@@ -1,396 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (c) Meta Platforms, Inc. and 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
|
-
* @flow strict-local
|
|
8
|
-
* @format
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
// RNOH patch: disable view flattening
|
|
12
|
-
|
|
13
|
-
import type { ColorValue } from "react-native/Libraries/StyleSheet/StyleSheet";
|
|
14
|
-
import typeof TouchableWithoutFeedback from "./TouchableWithoutFeedback";
|
|
15
|
-
|
|
16
|
-
import View from "react-native/Libraries/Components/View/View";
|
|
17
|
-
import Pressability, {
|
|
18
|
-
type PressabilityConfig,
|
|
19
|
-
} from "react-native/Libraries/Pressability/Pressability";
|
|
20
|
-
import { PressabilityDebugView } from "react-native/Libraries/Pressability/PressabilityDebug";
|
|
21
|
-
import StyleSheet, {
|
|
22
|
-
type ViewStyleProp,
|
|
23
|
-
} from "react-native/Libraries/StyleSheet/StyleSheet";
|
|
24
|
-
import Platform from "react-native/Libraries/Utilities/Platform";
|
|
25
|
-
import * as React from "react";
|
|
26
|
-
|
|
27
|
-
type AndroidProps = $ReadOnly<{|
|
|
28
|
-
nextFocusDown?: ?number,
|
|
29
|
-
nextFocusForward?: ?number,
|
|
30
|
-
nextFocusLeft?: ?number,
|
|
31
|
-
nextFocusRight?: ?number,
|
|
32
|
-
nextFocusUp?: ?number,
|
|
33
|
-
|}>;
|
|
34
|
-
|
|
35
|
-
type IOSProps = $ReadOnly<{|
|
|
36
|
-
hasTVPreferredFocus?: ?boolean,
|
|
37
|
-
|}>;
|
|
38
|
-
|
|
39
|
-
type Props = $ReadOnly<{|
|
|
40
|
-
...React.ElementConfig<TouchableWithoutFeedback>,
|
|
41
|
-
...AndroidProps,
|
|
42
|
-
...IOSProps,
|
|
43
|
-
|
|
44
|
-
activeOpacity?: ?number,
|
|
45
|
-
underlayColor?: ?ColorValue,
|
|
46
|
-
style?: ?ViewStyleProp,
|
|
47
|
-
onShowUnderlay?: ?() => void,
|
|
48
|
-
onHideUnderlay?: ?() => void,
|
|
49
|
-
testOnly_pressed?: ?boolean,
|
|
50
|
-
|
|
51
|
-
hostRef: React.Ref<typeof View>,
|
|
52
|
-
|}>;
|
|
53
|
-
|
|
54
|
-
type ExtraStyles = $ReadOnly<{|
|
|
55
|
-
child: ViewStyleProp,
|
|
56
|
-
underlay: ViewStyleProp,
|
|
57
|
-
|}>;
|
|
58
|
-
|
|
59
|
-
type State = $ReadOnly<{|
|
|
60
|
-
pressability: Pressability,
|
|
61
|
-
extraStyles: ?ExtraStyles,
|
|
62
|
-
|}>;
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
* A wrapper for making views respond properly to touches.
|
|
66
|
-
* On press down, the opacity of the wrapped view is decreased, which allows
|
|
67
|
-
* the underlay color to show through, darkening or tinting the view.
|
|
68
|
-
*
|
|
69
|
-
* The underlay comes from wrapping the child in a new View, which can affect
|
|
70
|
-
* layout, and sometimes cause unwanted visual artifacts if not used correctly,
|
|
71
|
-
* for example if the backgroundColor of the wrapped view isn't explicitly set
|
|
72
|
-
* to an opaque color.
|
|
73
|
-
*
|
|
74
|
-
* TouchableHighlight must have one child (not zero or more than one).
|
|
75
|
-
* If you wish to have several child components, wrap them in a View.
|
|
76
|
-
*
|
|
77
|
-
* Example:
|
|
78
|
-
*
|
|
79
|
-
* ```
|
|
80
|
-
* renderButton: function() {
|
|
81
|
-
* return (
|
|
82
|
-
* <TouchableHighlight onPress={this._onPressButton}>
|
|
83
|
-
* <Image
|
|
84
|
-
* style={styles.button}
|
|
85
|
-
* source={require('./myButton.png')}
|
|
86
|
-
* />
|
|
87
|
-
* </TouchableHighlight>
|
|
88
|
-
* );
|
|
89
|
-
* },
|
|
90
|
-
* ```
|
|
91
|
-
*
|
|
92
|
-
*
|
|
93
|
-
* ### Example
|
|
94
|
-
*
|
|
95
|
-
* ```ReactNativeWebPlayer
|
|
96
|
-
* import React, { Component } from 'react'
|
|
97
|
-
* import {
|
|
98
|
-
* AppRegistry,
|
|
99
|
-
* StyleSheet,
|
|
100
|
-
* TouchableHighlight,
|
|
101
|
-
* Text,
|
|
102
|
-
* View,
|
|
103
|
-
* } from 'react-native'
|
|
104
|
-
*
|
|
105
|
-
* class App extends Component {
|
|
106
|
-
* constructor(props) {
|
|
107
|
-
* super(props)
|
|
108
|
-
* this.state = { count: 0 }
|
|
109
|
-
* }
|
|
110
|
-
*
|
|
111
|
-
* onPress = () => {
|
|
112
|
-
* this.setState({
|
|
113
|
-
* count: this.state.count+1
|
|
114
|
-
* })
|
|
115
|
-
* }
|
|
116
|
-
*
|
|
117
|
-
* render() {
|
|
118
|
-
* return (
|
|
119
|
-
* <View style={styles.container}>
|
|
120
|
-
* <TouchableHighlight
|
|
121
|
-
* style={styles.button}
|
|
122
|
-
* onPress={this.onPress}
|
|
123
|
-
* >
|
|
124
|
-
* <Text> Touch Here </Text>
|
|
125
|
-
* </TouchableHighlight>
|
|
126
|
-
* <View style={[styles.countContainer]}>
|
|
127
|
-
* <Text style={[styles.countText]}>
|
|
128
|
-
* { this.state.count !== 0 ? this.state.count: null}
|
|
129
|
-
* </Text>
|
|
130
|
-
* </View>
|
|
131
|
-
* </View>
|
|
132
|
-
* )
|
|
133
|
-
* }
|
|
134
|
-
* }
|
|
135
|
-
*
|
|
136
|
-
* const styles = StyleSheet.create({
|
|
137
|
-
* container: {
|
|
138
|
-
* flex: 1,
|
|
139
|
-
* justifyContent: 'center',
|
|
140
|
-
* paddingHorizontal: 10
|
|
141
|
-
* },
|
|
142
|
-
* button: {
|
|
143
|
-
* alignItems: 'center',
|
|
144
|
-
* backgroundColor: '#DDDDDD',
|
|
145
|
-
* padding: 10
|
|
146
|
-
* },
|
|
147
|
-
* countContainer: {
|
|
148
|
-
* alignItems: 'center',
|
|
149
|
-
* padding: 10
|
|
150
|
-
* },
|
|
151
|
-
* countText: {
|
|
152
|
-
* color: '#FF00FF'
|
|
153
|
-
* }
|
|
154
|
-
* })
|
|
155
|
-
*
|
|
156
|
-
* AppRegistry.registerComponent('App', () => App)
|
|
157
|
-
* ```
|
|
158
|
-
*
|
|
159
|
-
*/
|
|
160
|
-
class TouchableHighlight extends React.Component<Props, State> {
|
|
161
|
-
_hideTimeout: ?TimeoutID;
|
|
162
|
-
_isMounted: boolean = false;
|
|
163
|
-
|
|
164
|
-
state: State = {
|
|
165
|
-
pressability: new Pressability(this._createPressabilityConfig()),
|
|
166
|
-
extraStyles:
|
|
167
|
-
this.props.testOnly_pressed === true ? this._createExtraStyles() : null,
|
|
168
|
-
};
|
|
169
|
-
|
|
170
|
-
_createPressabilityConfig(): PressabilityConfig {
|
|
171
|
-
return {
|
|
172
|
-
cancelable: !this.props.rejectResponderTermination,
|
|
173
|
-
disabled:
|
|
174
|
-
this.props.disabled != null
|
|
175
|
-
? this.props.disabled
|
|
176
|
-
: this.props.accessibilityState?.disabled,
|
|
177
|
-
hitSlop: this.props.hitSlop,
|
|
178
|
-
delayLongPress: this.props.delayLongPress,
|
|
179
|
-
delayPressIn: this.props.delayPressIn,
|
|
180
|
-
delayPressOut: this.props.delayPressOut,
|
|
181
|
-
minPressDuration: 0,
|
|
182
|
-
pressRectOffset: this.props.pressRetentionOffset,
|
|
183
|
-
android_disableSound: this.props.touchSoundDisabled,
|
|
184
|
-
onBlur: (event) => {
|
|
185
|
-
if (Platform.isTV) {
|
|
186
|
-
this._hideUnderlay();
|
|
187
|
-
}
|
|
188
|
-
if (this.props.onBlur != null) {
|
|
189
|
-
this.props.onBlur(event);
|
|
190
|
-
}
|
|
191
|
-
},
|
|
192
|
-
onFocus: (event) => {
|
|
193
|
-
if (Platform.isTV) {
|
|
194
|
-
this._showUnderlay();
|
|
195
|
-
}
|
|
196
|
-
if (this.props.onFocus != null) {
|
|
197
|
-
this.props.onFocus(event);
|
|
198
|
-
}
|
|
199
|
-
},
|
|
200
|
-
onLongPress: this.props.onLongPress,
|
|
201
|
-
onPress: (event) => {
|
|
202
|
-
if (this._hideTimeout != null) {
|
|
203
|
-
clearTimeout(this._hideTimeout);
|
|
204
|
-
}
|
|
205
|
-
if (!Platform.isTV) {
|
|
206
|
-
this._showUnderlay();
|
|
207
|
-
this._hideTimeout = setTimeout(() => {
|
|
208
|
-
this._hideUnderlay();
|
|
209
|
-
}, this.props.delayPressOut ?? 0);
|
|
210
|
-
}
|
|
211
|
-
if (this.props.onPress != null) {
|
|
212
|
-
this.props.onPress(event);
|
|
213
|
-
}
|
|
214
|
-
},
|
|
215
|
-
onPressIn: (event) => {
|
|
216
|
-
if (this._hideTimeout != null) {
|
|
217
|
-
clearTimeout(this._hideTimeout);
|
|
218
|
-
this._hideTimeout = null;
|
|
219
|
-
}
|
|
220
|
-
this._showUnderlay();
|
|
221
|
-
if (this.props.onPressIn != null) {
|
|
222
|
-
this.props.onPressIn(event);
|
|
223
|
-
}
|
|
224
|
-
},
|
|
225
|
-
onPressOut: (event) => {
|
|
226
|
-
if (this._hideTimeout == null) {
|
|
227
|
-
this._hideUnderlay();
|
|
228
|
-
}
|
|
229
|
-
if (this.props.onPressOut != null) {
|
|
230
|
-
this.props.onPressOut(event);
|
|
231
|
-
}
|
|
232
|
-
},
|
|
233
|
-
};
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
_createExtraStyles(): ExtraStyles {
|
|
237
|
-
return {
|
|
238
|
-
child: { opacity: this.props.activeOpacity ?? 0.85 },
|
|
239
|
-
underlay: {
|
|
240
|
-
backgroundColor:
|
|
241
|
-
this.props.underlayColor === undefined
|
|
242
|
-
? "black"
|
|
243
|
-
: this.props.underlayColor,
|
|
244
|
-
},
|
|
245
|
-
};
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
_showUnderlay(): void {
|
|
249
|
-
if (!this._isMounted || !this._hasPressHandler()) {
|
|
250
|
-
return;
|
|
251
|
-
}
|
|
252
|
-
this.setState({ extraStyles: this._createExtraStyles() });
|
|
253
|
-
if (this.props.onShowUnderlay != null) {
|
|
254
|
-
this.props.onShowUnderlay();
|
|
255
|
-
}
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
_hideUnderlay(): void {
|
|
259
|
-
if (this._hideTimeout != null) {
|
|
260
|
-
clearTimeout(this._hideTimeout);
|
|
261
|
-
this._hideTimeout = null;
|
|
262
|
-
}
|
|
263
|
-
if (this.props.testOnly_pressed === true) {
|
|
264
|
-
return;
|
|
265
|
-
}
|
|
266
|
-
if (this._hasPressHandler()) {
|
|
267
|
-
this.setState({ extraStyles: null });
|
|
268
|
-
if (this.props.onHideUnderlay != null) {
|
|
269
|
-
this.props.onHideUnderlay();
|
|
270
|
-
}
|
|
271
|
-
}
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
_hasPressHandler(): boolean {
|
|
275
|
-
return (
|
|
276
|
-
this.props.onPress != null ||
|
|
277
|
-
this.props.onPressIn != null ||
|
|
278
|
-
this.props.onPressOut != null ||
|
|
279
|
-
this.props.onLongPress != null
|
|
280
|
-
);
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
render(): React.Node {
|
|
284
|
-
const child = React.Children.only<$FlowFixMe>(this.props.children);
|
|
285
|
-
|
|
286
|
-
// BACKWARD-COMPATIBILITY: Focus and blur events were never supported before
|
|
287
|
-
// adopting `Pressability`, so preserve that behavior.
|
|
288
|
-
const { onBlur, onFocus, ...eventHandlersWithoutBlurAndFocus } =
|
|
289
|
-
this.state.pressability.getEventHandlers();
|
|
290
|
-
|
|
291
|
-
const accessibilityState =
|
|
292
|
-
this.props.disabled != null
|
|
293
|
-
? {
|
|
294
|
-
...this.props.accessibilityState,
|
|
295
|
-
disabled: this.props.disabled,
|
|
296
|
-
}
|
|
297
|
-
: this.props.accessibilityState;
|
|
298
|
-
|
|
299
|
-
const accessibilityValue = {
|
|
300
|
-
max: this.props["aria-valuemax"] ?? this.props.accessibilityValue?.max,
|
|
301
|
-
min: this.props["aria-valuemin"] ?? this.props.accessibilityValue?.min,
|
|
302
|
-
now: this.props["aria-valuenow"] ?? this.props.accessibilityValue?.now,
|
|
303
|
-
text: this.props["aria-valuetext"] ?? this.props.accessibilityValue?.text,
|
|
304
|
-
};
|
|
305
|
-
|
|
306
|
-
const accessibilityLiveRegion =
|
|
307
|
-
this.props["aria-live"] === "off"
|
|
308
|
-
? "none"
|
|
309
|
-
: this.props["aria-live"] ?? this.props.accessibilityLiveRegion;
|
|
310
|
-
|
|
311
|
-
const accessibilityLabel =
|
|
312
|
-
this.props["aria-label"] ?? this.props.accessibilityLabel;
|
|
313
|
-
return (
|
|
314
|
-
<View
|
|
315
|
-
accessible={this.props.accessible !== false}
|
|
316
|
-
accessibilityLabel={accessibilityLabel}
|
|
317
|
-
accessibilityHint={this.props.accessibilityHint}
|
|
318
|
-
accessibilityLanguage={this.props.accessibilityLanguage}
|
|
319
|
-
accessibilityRole={this.props.accessibilityRole}
|
|
320
|
-
accessibilityState={accessibilityState}
|
|
321
|
-
accessibilityValue={accessibilityValue}
|
|
322
|
-
accessibilityActions={this.props.accessibilityActions}
|
|
323
|
-
onAccessibilityAction={this.props.onAccessibilityAction}
|
|
324
|
-
importantForAccessibility={
|
|
325
|
-
this.props["aria-hidden"] === true
|
|
326
|
-
? "no-hide-descendants"
|
|
327
|
-
: this.props.importantForAccessibility
|
|
328
|
-
}
|
|
329
|
-
accessibilityViewIsModal={
|
|
330
|
-
this.props["aria-modal"] ?? this.props.accessibilityViewIsModal
|
|
331
|
-
}
|
|
332
|
-
accessibilityLiveRegion={accessibilityLiveRegion}
|
|
333
|
-
accessibilityElementsHidden={
|
|
334
|
-
this.props["aria-hidden"] ?? this.props.accessibilityElementsHidden
|
|
335
|
-
}
|
|
336
|
-
style={StyleSheet.compose(
|
|
337
|
-
this.props.style,
|
|
338
|
-
this.state.extraStyles?.underlay
|
|
339
|
-
)}
|
|
340
|
-
onLayout={this.props.onLayout}
|
|
341
|
-
hitSlop={this.props.hitSlop}
|
|
342
|
-
hasTVPreferredFocus={this.props.hasTVPreferredFocus}
|
|
343
|
-
nextFocusDown={this.props.nextFocusDown}
|
|
344
|
-
nextFocusForward={this.props.nextFocusForward}
|
|
345
|
-
nextFocusLeft={this.props.nextFocusLeft}
|
|
346
|
-
nextFocusRight={this.props.nextFocusRight}
|
|
347
|
-
nextFocusUp={this.props.nextFocusUp}
|
|
348
|
-
focusable={
|
|
349
|
-
this.props.focusable !== false && this.props.onPress !== undefined
|
|
350
|
-
}
|
|
351
|
-
nativeID={this.props.nativeID}
|
|
352
|
-
testID={this.props.testID}
|
|
353
|
-
ref={this.props.hostRef}
|
|
354
|
-
{...eventHandlersWithoutBlurAndFocus}
|
|
355
|
-
collapsable={false} // RNOH: patch
|
|
356
|
-
>
|
|
357
|
-
{React.cloneElement(child, {
|
|
358
|
-
style: StyleSheet.compose(
|
|
359
|
-
child.props.style,
|
|
360
|
-
this.state.extraStyles?.child
|
|
361
|
-
),
|
|
362
|
-
})}
|
|
363
|
-
{__DEV__ ? (
|
|
364
|
-
<PressabilityDebugView color="green" hitSlop={this.props.hitSlop} />
|
|
365
|
-
) : null}
|
|
366
|
-
</View>
|
|
367
|
-
);
|
|
368
|
-
}
|
|
369
|
-
|
|
370
|
-
componentDidMount(): void {
|
|
371
|
-
this._isMounted = true;
|
|
372
|
-
}
|
|
373
|
-
|
|
374
|
-
componentDidUpdate(prevProps: Props, prevState: State) {
|
|
375
|
-
this.state.pressability.configure(this._createPressabilityConfig());
|
|
376
|
-
}
|
|
377
|
-
|
|
378
|
-
componentWillUnmount(): void {
|
|
379
|
-
this._isMounted = false;
|
|
380
|
-
if (this._hideTimeout != null) {
|
|
381
|
-
clearTimeout(this._hideTimeout);
|
|
382
|
-
}
|
|
383
|
-
this.state.pressability.reset();
|
|
384
|
-
}
|
|
385
|
-
}
|
|
386
|
-
|
|
387
|
-
const Touchable = (React.forwardRef((props, hostRef) => (
|
|
388
|
-
<TouchableHighlight {...props} hostRef={hostRef} />
|
|
389
|
-
)): React.AbstractComponent<
|
|
390
|
-
$ReadOnly<$Diff<Props, {| hostRef: React.Ref<typeof View> |}>>,
|
|
391
|
-
React.ElementRef<typeof View>
|
|
392
|
-
>);
|
|
393
|
-
|
|
394
|
-
Touchable.displayName = "TouchableHighlight";
|
|
395
|
-
|
|
396
|
-
module.exports = Touchable;
|