@office-iss/react-native-win32 0.72.8 → 0.73.0-preview.2
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/.flowconfig +15 -5
- package/CHANGELOG.json +530 -101
- package/CHANGELOG.md +213 -56
- package/IntegrationTests/PromiseTest.js +1 -0
- package/IntegrationTests/websocket_integration_test_server.js +1 -1
- package/Libraries/Animated/Animated.js +1 -1
- package/Libraries/Animated/AnimatedImplementation.js +1 -1
- package/Libraries/Animated/NativeAnimatedHelper.js +14 -10
- package/Libraries/Animated/NativeAnimatedHelper.win32.js +16 -12
- package/Libraries/Animated/NativeAnimatedModule.js +6 -2
- package/Libraries/Animated/NativeAnimatedTurboModule.js +7 -4
- package/Libraries/Animated/animations/Animation.js +57 -3
- package/Libraries/Animated/animations/DecayAnimation.js +9 -0
- package/Libraries/Animated/animations/SpringAnimation.js +8 -0
- package/Libraries/Animated/animations/TimingAnimation.js +8 -0
- package/Libraries/Animated/components/AnimatedFlatList.js +2 -1
- package/Libraries/Animated/components/AnimatedScrollView.js +2 -0
- package/Libraries/Animated/components/AnimatedSectionList.js +2 -1
- package/Libraries/Animated/createAnimatedComponent.js +1 -0
- package/Libraries/Animated/nodes/AnimatedColor.js +1 -1
- package/Libraries/Animated/nodes/AnimatedObject.js +146 -0
- package/Libraries/Animated/nodes/AnimatedProps.js +19 -7
- package/Libraries/Animated/nodes/AnimatedStyle.js +29 -55
- package/Libraries/Animated/nodes/AnimatedValueXY.js +3 -17
- package/Libraries/Animated/shouldUseTurboAnimatedModule.js +17 -0
- package/Libraries/Animated/useAnimatedProps.js +9 -10
- package/Libraries/AppState/AppState.d.ts +1 -1
- package/Libraries/AppState/NativeAppState.js +8 -4
- package/Libraries/BatchedBridge/MessageQueue.js +45 -36
- package/Libraries/Blob/Blob.js +6 -2
- package/Libraries/Blob/BlobManager.js +9 -10
- package/Libraries/Blob/BlobRegistry.js +14 -9
- package/Libraries/Blob/File.js +1 -1
- package/Libraries/Blob/FileReader.js +1 -2
- package/Libraries/Components/AccessibilityInfo/AccessibilityInfo.d.ts +1 -5
- package/Libraries/Components/AccessibilityInfo/AccessibilityInfo.win32.js +7 -48
- package/Libraries/Components/Button/ButtonWin32.Props.d.ts +1 -1
- package/Libraries/Components/Button/ButtonWin32.Props.js.map +1 -1
- package/Libraries/Components/Button/ButtonWin32.d.ts +1 -1
- package/Libraries/Components/Button/ButtonWin32.js +1 -4
- package/Libraries/Components/Button/ButtonWin32.js.map +1 -1
- package/Libraries/Components/Clipboard/Clipboard.d.ts +4 -4
- package/Libraries/Components/DrawerAndroid/DrawerLayoutAndroid.android.js +3 -1
- package/Libraries/Components/EnterString.win32.d.ts +1 -1
- package/Libraries/Components/Keyboard/KeyboardAvoidingView.js +26 -6
- package/Libraries/Components/Pressable/Pressable.js +3 -2
- package/Libraries/Components/Pressable/Pressable.win32.js +4 -3
- package/Libraries/Components/Pressable/useAndroidRippleForView.js +1 -1
- package/Libraries/Components/SafeAreaView/SafeAreaView.js +7 -7
- package/Libraries/Components/SafeAreaView/SafeAreaView.win32.js +7 -8
- package/Libraries/Components/ScrollView/ScrollView.js +3 -1
- package/Libraries/Components/ScrollView/ScrollView.win32.js +3 -1
- package/Libraries/Components/ScrollView/ScrollViewStickyHeader.js +39 -46
- package/Libraries/Components/Switch/Switch.js +1 -0
- package/Libraries/Components/Text/TextWin32.d.ts +1 -1
- package/Libraries/Components/TextInput/RCTTextInputViewConfig.js +1 -0
- package/Libraries/Components/TextInput/TextInput.d.ts +49 -7
- package/Libraries/Components/TextInput/TextInput.flow.js +43 -10
- package/Libraries/Components/TextInput/TextInput.js +62 -10
- package/Libraries/Components/TextInput/TextInput.win32.js +953 -206
- package/Libraries/Components/TextInput/Win32TextInputNativeComponent.js +23 -0
- package/Libraries/Components/ToastAndroid/{ToastAndroid.ios.js → ToastAndroid.js} +9 -1
- package/Libraries/Components/ToastAndroid/ToastAndroid.win32.js +9 -1
- package/Libraries/Components/Touchable/Tests/TouchableWin32Test.js +2 -2
- package/Libraries/Components/Touchable/Tests/TouchableWin32Test.js.map +1 -1
- package/Libraries/Components/Touchable/TouchableBounce.js +1 -1
- package/Libraries/Components/Touchable/TouchableHighlight.js +1 -1
- package/Libraries/Components/Touchable/TouchableNativeFeedback.js +1 -1
- package/Libraries/Components/Touchable/TouchableOpacity.js +4 -1
- package/Libraries/Components/Touchable/TouchableWin32.d.ts +1 -1
- package/Libraries/Components/Touchable/TouchableWin32.js.map +1 -1
- package/Libraries/Components/Touchable/TouchableWithoutFeedback.js +1 -0
- package/Libraries/Components/TraceUpdateOverlay/TraceUpdateOverlay.js +16 -6
- package/Libraries/Components/View/ReactNativeStyleAttributes.js +9 -0
- package/Libraries/Components/View/ReactNativeViewAttributes.js +1 -0
- package/Libraries/Components/View/ReactNativeViewAttributes.win32.js +1 -0
- package/Libraries/Components/View/View.js +46 -32
- package/Libraries/Components/View/View.win32.js +37 -6
- package/Libraries/Components/View/ViewAccessibility.d.ts +8 -2
- package/Libraries/Components/View/ViewNativeComponent.js +1 -0
- package/Libraries/Components/View/ViewPropTypes.js +18 -3
- package/Libraries/Components/View/ViewPropTypes.win32.js +30 -4
- package/Libraries/Components/View/ViewWin32.js +3 -2
- package/Libraries/Core/Devtools/loadBundleFromServer.js +152 -0
- package/Libraries/Core/Devtools/symbolicateStackTrace.js +2 -1
- package/Libraries/Core/ExceptionsManager.js +16 -7
- package/Libraries/Core/ExtendedError.js +12 -0
- package/Libraries/Core/ReactNativeVersion.js +3 -3
- package/Libraries/Core/ReactNativeVersionCheck.js +0 -2
- package/Libraries/Core/ReactNativeVersionCheck.win32.js +0 -2
- package/Libraries/Core/__mocks__/NativeExceptionsManager.js +20 -0
- package/Libraries/Core/setUpDeveloperTools.js +5 -1
- package/Libraries/Core/setUpIntersectionObserver.js +16 -0
- package/Libraries/{Components/ProgressBarAndroid/ProgressBarAndroid.ios.js → Core/setUpMutationObserver.js} +6 -2
- package/Libraries/Core/setUpPerformance.js +6 -13
- package/Libraries/Core/setUpPerformanceObserver.js +16 -0
- package/Libraries/Core/setUpRegeneratorRuntime.js +4 -2
- package/Libraries/DOM/Nodes/ReactNativeElement.js +135 -18
- package/Libraries/DOM/Nodes/ReadOnlyCharacterData.js +72 -0
- package/Libraries/DOM/Nodes/ReadOnlyElement.js +209 -21
- package/Libraries/DOM/Nodes/ReadOnlyNode.js +206 -17
- package/Libraries/DOM/Nodes/ReadOnlyText.js +30 -0
- package/Libraries/DOM/Nodes/Utilities/Traversal.js +54 -0
- package/Libraries/EventEmitter/NativeEventEmitter.d.ts +0 -6
- package/Libraries/EventEmitter/RCTDeviceEventEmitter.js +15 -4
- package/Libraries/Image/Image.android.js +8 -2
- package/Libraries/Image/Image.d.ts +1 -1
- package/Libraries/Image/Image.ios.js +4 -1
- package/Libraries/Image/Image.win32.js +6 -3
- package/Libraries/Image/ImageBackground.js +3 -0
- package/Libraries/Image/resolveAssetSource.win32.js +1 -1
- package/Libraries/Inspector/DevtoolsOverlay.js +6 -3
- package/Libraries/Inspector/NetworkOverlay.js +2 -2
- package/Libraries/Interaction/JSEventLoopWatchdog.js +1 -5
- package/Libraries/Interaction/PanResponder.js +1 -4
- package/Libraries/IntersectionObserver/IntersectionObserver.js +252 -0
- package/Libraries/IntersectionObserver/IntersectionObserverEntry.js +140 -0
- package/Libraries/IntersectionObserver/IntersectionObserverManager.js +221 -0
- package/Libraries/IntersectionObserver/NativeIntersectionObserver.js +41 -0
- package/Libraries/IntersectionObserver/__mocks__/NativeIntersectionObserver.js +162 -0
- package/Libraries/LayoutAnimation/LayoutAnimation.js +1 -1
- package/Libraries/Lists/FlatList.d.ts +2 -1
- package/Libraries/Lists/FlatList.js +15 -5
- package/Libraries/Lists/SectionList.js +4 -0
- package/Libraries/LogBox/Data/LogBoxData.js +2 -1
- package/Libraries/LogBox/Data/LogBoxLog.js +4 -1
- package/Libraries/LogBox/Data/LogBoxSymbolication.js +5 -2
- package/Libraries/LogBox/Data/parseLogBoxLog.js +57 -20
- package/Libraries/LogBox/UI/AnsiHighlight.js +1 -1
- package/Libraries/LogBox/UI/LogBoxInspectorFooter.js +24 -31
- package/Libraries/LogBox/UI/LogBoxInspectorHeader.js +1 -1
- package/Libraries/LogBox/UI/LogBoxMessage.js +4 -7
- package/Libraries/MutationObserver/MutationObserver.js +184 -0
- package/Libraries/MutationObserver/MutationObserverManager.js +218 -0
- package/Libraries/MutationObserver/MutationRecord.js +82 -0
- package/Libraries/MutationObserver/NativeMutationObserver.js +58 -0
- package/Libraries/MutationObserver/__mocks__/NativeMutationObserver.js +327 -0
- package/Libraries/NativeComponent/BaseViewConfig.android.js +18 -3
- package/Libraries/NativeComponent/BaseViewConfig.ios.js +33 -0
- package/Libraries/NativeComponent/BaseViewConfig.win32.js +33 -0
- package/Libraries/NativeComponent/NativeComponentRegistry.js +13 -9
- package/Libraries/NativeModules/specs/NativeSourceCode.js +6 -6
- package/Libraries/Network/RCTNetworking.android.js +2 -1
- package/Libraries/Network/XMLHttpRequest.js +1 -1
- package/Libraries/NewAppScreen/components/DebugInstructions.js +4 -4
- package/Libraries/NewAppScreen/components/LearnMoreLinks.js +9 -2
- package/Libraries/Performance/QuickPerformanceLogger.js +1 -1
- package/Libraries/PermissionsAndroid/NativePermissionsAndroid.js +1 -0
- package/Libraries/PermissionsAndroid/PermissionsAndroid.d.ts +1 -0
- package/Libraries/PermissionsAndroid/PermissionsAndroid.js +3 -1
- package/Libraries/Pressability/Pressability.js +28 -3
- package/Libraries/Pressability/Pressability.win32.js +30 -5
- package/Libraries/ReactNative/AppContainer.js +2 -3
- package/Libraries/ReactNative/AppRegistry.d.ts +0 -5
- package/Libraries/ReactNative/AppRegistry.js +66 -53
- package/Libraries/ReactNative/BridgelessUIManager.js +38 -9
- package/Libraries/ReactNative/FabricUIManager.js +143 -34
- package/Libraries/ReactNative/I18nManager.js +5 -11
- package/Libraries/ReactNative/NativeI18nManager.js +7 -5
- package/Libraries/ReactNative/PaperUIManager.win32.js +2 -2
- package/Libraries/ReactNative/ReactFabricPublicInstance/ReactFabricHostComponent.js +151 -0
- package/Libraries/ReactNative/ReactFabricPublicInstance/ReactFabricPublicInstance.js +81 -0
- package/Libraries/ReactNative/ReactFabricPublicInstance/ReactNativeAttributePayload.js +492 -0
- package/Libraries/ReactNative/ReactFabricPublicInstance/warnForStyleProps.js +32 -0
- package/Libraries/ReactNative/ReactNativeFeatureFlags.js +19 -3
- package/Libraries/ReactNative/UIManager.js +8 -0
- package/Libraries/ReactNative/__mocks__/FabricUIManager.js +648 -0
- package/Libraries/ReactPrivate/ReactNativePrivateInterface.js +38 -2
- package/Libraries/Renderer/implementations/ReactFabric-dev.js +27 -27
- package/Libraries/Renderer/implementations/ReactFabric-prod.js +3 -3
- package/Libraries/Renderer/implementations/ReactFabric-profiling.js +3 -3
- package/Libraries/Renderer/implementations/ReactNativeRenderer-dev.js +27 -27
- package/Libraries/Renderer/implementations/ReactNativeRenderer-prod.js +3 -3
- package/Libraries/Renderer/implementations/ReactNativeRenderer-profiling.js +3 -3
- package/Libraries/Renderer/shims/ReactFabric.js +5 -6
- package/Libraries/Renderer/shims/ReactFeatureFlags.js +2 -3
- package/Libraries/Renderer/shims/ReactNative.js +2 -3
- package/Libraries/Renderer/shims/ReactNativeTypes.js +35 -17
- package/Libraries/Renderer/shims/ReactNativeViewConfigRegistry.js +3 -3
- package/Libraries/Renderer/shims/createReactNativeComponentClass.js +2 -3
- package/Libraries/Settings/{Settings.android.js → Settings.js} +4 -4
- package/Libraries/Share/Share.d.ts +3 -9
- package/Libraries/StyleSheet/PlatformColorValueTypes.android.js +9 -4
- package/Libraries/StyleSheet/PlatformColorValueTypes.ios.js +28 -13
- package/Libraries/StyleSheet/PlatformColorValueTypes.win32.js +14 -4
- package/Libraries/StyleSheet/PlatformColorValueTypesIOS.ios.js +1 -1
- package/Libraries/StyleSheet/PlatformColorValueTypesWin32.d.ts +1 -1
- package/Libraries/StyleSheet/StyleSheet.d.ts +10 -1
- package/Libraries/StyleSheet/StyleSheet.js +3 -0
- package/Libraries/StyleSheet/StyleSheet.win32.js +3 -0
- package/Libraries/StyleSheet/StyleSheetTypes.d.ts +31 -17
- package/Libraries/StyleSheet/StyleSheetTypes.js +90 -6
- package/Libraries/StyleSheet/flattenStyle.js +4 -0
- package/Libraries/StyleSheet/private/_TransformStyle.js +16 -2
- package/Libraries/StyleSheet/processColor.js +1 -2
- package/Libraries/StyleSheet/processTransformOrigin.js +136 -0
- package/Libraries/StyleSheet/splitLayoutProps.js +1 -0
- package/Libraries/Text/Text.d.ts +5 -5
- package/Libraries/Text/Text.js +17 -10
- package/Libraries/Text/Text.win32.js +354 -0
- package/Libraries/Text/TextProps.win32.js +281 -0
- package/Libraries/TurboModule/TurboModuleRegistry.js +47 -7
- package/Libraries/TurboModule/samples/NativeSampleTurboModule.js +6 -0
- package/Libraries/Types/CoreEventTypes.d.ts +5 -2
- package/Libraries/Utilities/GlobalPerformanceLogger.js +2 -12
- package/Libraries/Utilities/NativeDeviceInfo.js +8 -9
- package/Libraries/Utilities/NativePlatformConstantsAndroid.js +23 -18
- package/Libraries/Utilities/NativePlatformConstantsIOS.js +16 -13
- package/Libraries/Utilities/NativePlatformConstantsWin.js +13 -10
- package/Libraries/Utilities/PerformanceLoggerContext.js +1 -1
- package/Libraries/Utilities/Platform.android.js +12 -8
- package/Libraries/Utilities/Platform.d.ts +1 -0
- package/Libraries/Utilities/Platform.flow.js +84 -0
- package/Libraries/Utilities/Platform.flow.win32.js +111 -0
- package/Libraries/Utilities/Platform.ios.js +12 -8
- package/Libraries/Utilities/Platform.win32.js +12 -8
- package/Libraries/Utilities/PolyfillFunctions.js +1 -1
- package/Libraries/Utilities/ReactNativeTestTools.js +1 -2
- package/Libraries/Utilities/SceneTracker.js +1 -1
- package/Libraries/Utilities/createPerformanceLogger.js +63 -32
- package/Libraries/Utilities/useColorScheme.js +7 -8
- package/Libraries/WebPerformance/MemoryInfo.js +1 -1
- package/Libraries/WebPerformance/NativePerformance.js +3 -8
- package/Libraries/WebPerformance/NativePerformanceObserver.js +4 -0
- package/Libraries/WebPerformance/Performance.js +42 -15
- package/Libraries/WebPerformance/PerformanceEntry.js +14 -6
- package/Libraries/WebPerformance/PerformanceEventTiming.js +18 -1
- package/Libraries/WebPerformance/ReactNativeStartupTiming.js +40 -14
- package/Libraries/WebPerformance/__mocks__/NativePerformance.js +4 -2
- package/Libraries/WebPerformance/__mocks__/NativePerformanceObserver.js +21 -3
- package/Libraries/promiseRejectionTrackingOptions.js +21 -9
- package/Libraries/vendor/emitter/EventEmitter.js +17 -17
- package/flow/global.js +1 -3
- package/flow/jest.js +5 -1
- package/{Libraries/Components/DrawerAndroid/DrawerLayoutAndroid.ios.js → jest/ReactNativeInternalFeatureFlagsMock.js} +2 -1
- package/jest/__tests__/setup-test.js +18 -0
- package/jest/mockModal.js +6 -4
- package/jest/setup.js +61 -30
- package/jest.config.js +1 -1
- package/just-task.js +1 -0
- package/overrides.json +54 -60
- package/package.json +35 -33
- package/src/Libraries/Components/Button/ButtonWin32.Props.ts +1 -1
- package/src/Libraries/Components/Button/ButtonWin32.tsx +0 -2
- package/src/Libraries/Components/Touchable/Tests/TouchableWin32Test.tsx +2 -2
- package/src/Libraries/Components/Touchable/TouchableWin32.tsx +1 -1
- package/src/Libraries/Components/View/ViewAccessibility.d.ts +8 -2
- package/src/Libraries/StyleSheet/PlatformColorValueTypesWin32.d.ts +1 -1
- package/types/experimental.d.ts +44 -0
- package/types/index.d.ts +2 -1
- package/types/modules/Devtools.d.ts +1 -0
- package/types/modules/globals.d.ts +16 -1
- package/IntegrationTests/BUCK +0 -32
- package/IntegrationTests/PropertiesUpdateTest.js +0 -29
- package/IntegrationTests/RCTRootViewIntegrationTestApp.js +0 -86
- package/IntegrationTests/ReactContentSizeUpdateTest.js +0 -89
- package/IntegrationTests/SizeFlexibilityUpdateTest.js +0 -106
- package/Libraries/Components/AccessibilityInfo/NativeAccessibilityInfoWin32.js +0 -37
- package/Libraries/Components/TextInput/TextInput.Types.win32.d.ts +0 -51
- package/Libraries/Components/TextInput/TextInput.Types.win32.js +0 -3
- package/Libraries/Components/TextInput/TextInput.Types.win32.js.map +0 -1
- package/Libraries/Utilities/AcessibilityMapping.js +0 -154
- package/Libraries/Utilities/AcessibilityMapping.win32.js +0 -156
- package/Libraries/Utilities/NativeDevSplitBundleLoader.js +0 -19
- package/Libraries/Utilities/useColorScheme.win32.js +0 -26
- package/flow/use-sync-external-store.js +0 -20
- package/flow-typed/npm/base64-js_v1.x.x.js +0 -12
- package/flow-typed/npm/glob_v7.x.x.js +0 -79
- package/flow-typed/npm/pretty-format_v26.x.x.js +0 -49
- package/flow-typed/npm/promise_v8.x.x.js +0 -30
- package/flow-typed/npm/react-dom_v17.x.x.js +0 -139
- package/flow-typed/npm/react-test-renderer_v16.x.x.js +0 -79
- package/flow-typed/npm/stacktrace-parser_v0.1.x.js +0 -17
- package/flow-typed/npm/yargs_v17.x.x.js +0 -341
- package/src/Libraries/Components/AccessibilityInfo/AccessibilityInfo.d.ts +0 -161
- package/src/Libraries/Components/TextInput/TextInput.Types.win32.ts +0 -68
- /package/Libraries/{Renderer/public → ReactNative/ReactFabricPublicInstance}/ReactFabricPublicInstanceUtils.js +0 -0
|
@@ -1,44 +1,38 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
* The fork is necessary as platform checks in the base implementation made the
|
|
4
|
-
* control unusable on win32. In addition to cleaning up some of the code, this
|
|
5
|
-
* fork also uses Typescript rather than Flow for type safety.
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
6
3
|
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
* The original implementation can be found at
|
|
11
|
-
* https://github.com/facebook/react-native/blob/1013a010492a7bef5ff58073a088ac924a986e9e/Libraries/Components/TextInput/TextInput.js
|
|
12
|
-
*
|
|
13
|
-
* This control does not support the full React Native TextInput interface yet.
|
|
14
|
-
* Most of the work necessary to make that happen needs to happen on the native side.
|
|
15
|
-
* Future work on the JS side may include:
|
|
16
|
-
* 1. Expanded typings for some of the events
|
|
17
|
-
* 2. Additional work to manage selection
|
|
18
|
-
* 3. Any base/default styling work
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
19
6
|
*
|
|
20
7
|
* @flow strict-local
|
|
21
8
|
* @format
|
|
22
9
|
*/
|
|
23
10
|
|
|
24
11
|
import type {HostComponent} from '../../Renderer/shims/ReactNativeTypes';
|
|
25
|
-
import {findNodeHandle} from '../../ReactNative/RendererProxy';
|
|
26
|
-
import UIManager from '../../ReactNative/UIManager';
|
|
27
|
-
import requireNativeComponent from '../../ReactNative/requireNativeComponent';
|
|
28
|
-
import * as React from 'react';
|
|
29
|
-
import TextAncestor from '../../Text/TextAncestor';
|
|
30
|
-
import TextInputState from './TextInputState';
|
|
31
|
-
import type {ViewProps} from '../View/ViewPropTypes';
|
|
32
12
|
import type {
|
|
33
13
|
PressEvent,
|
|
34
14
|
ScrollEvent,
|
|
35
15
|
SyntheticEvent,
|
|
36
16
|
} from '../../Types/CoreEventTypes';
|
|
17
|
+
import type {ViewProps} from '../View/ViewPropTypes';
|
|
18
|
+
import type {TextInputType} from './TextInput.flow';
|
|
19
|
+
|
|
20
|
+
import usePressability from '../../Pressability/usePressability';
|
|
21
|
+
import flattenStyle from '../../StyleSheet/flattenStyle';
|
|
37
22
|
import StyleSheet, {
|
|
38
23
|
type ColorValue,
|
|
39
24
|
type TextStyleProp,
|
|
40
25
|
type ViewStyleProp,
|
|
41
26
|
} from '../../StyleSheet/StyleSheet';
|
|
27
|
+
import Text from '../../Text/Text';
|
|
28
|
+
import TextAncestor from '../../Text/TextAncestor';
|
|
29
|
+
import Platform from '../../Utilities/Platform';
|
|
30
|
+
import useMergeRefs from '../../Utilities/useMergeRefs';
|
|
31
|
+
import TextInputState from './TextInputState';
|
|
32
|
+
import invariant from 'invariant';
|
|
33
|
+
import nullthrows from 'nullthrows';
|
|
34
|
+
import * as React from 'react';
|
|
35
|
+
import {useCallback, useLayoutEffect, useRef, useState} from 'react';
|
|
42
36
|
|
|
43
37
|
type ReactRefSetter<T> = {current: null | T, ...} | ((ref: null | T) => mixed);
|
|
44
38
|
type TextInputInstance = React.ElementRef<HostComponent<mixed>> & {
|
|
@@ -48,6 +42,39 @@ type TextInputInstance = React.ElementRef<HostComponent<mixed>> & {
|
|
|
48
42
|
+setSelection: (start: number, end: number) => void,
|
|
49
43
|
};
|
|
50
44
|
|
|
45
|
+
let AndroidTextInput;
|
|
46
|
+
let AndroidTextInputCommands;
|
|
47
|
+
let RCTSinglelineTextInputView;
|
|
48
|
+
let RCTSinglelineTextInputNativeCommands;
|
|
49
|
+
let RCTMultilineTextInputView;
|
|
50
|
+
let RCTMultilineTextInputNativeCommands;
|
|
51
|
+
let WindowsTextInput; // [Windows]
|
|
52
|
+
let WindowsTextInputCommands; // [Windows]
|
|
53
|
+
import type {KeyEvent} from '../../Types/CoreEventTypes'; // [Windows]
|
|
54
|
+
|
|
55
|
+
// [Windows
|
|
56
|
+
if (Platform.OS === 'android') {
|
|
57
|
+
AndroidTextInput = require('./AndroidTextInputNativeComponent').default;
|
|
58
|
+
AndroidTextInputCommands =
|
|
59
|
+
require('./AndroidTextInputNativeComponent').Commands;
|
|
60
|
+
} else if (Platform.OS === 'ios') {
|
|
61
|
+
RCTSinglelineTextInputView =
|
|
62
|
+
require('./RCTSingelineTextInputNativeComponent').default;
|
|
63
|
+
RCTSinglelineTextInputNativeCommands =
|
|
64
|
+
require('./RCTSingelineTextInputNativeComponent').Commands;
|
|
65
|
+
RCTMultilineTextInputView =
|
|
66
|
+
require('./RCTMultilineTextInputNativeComponent').default;
|
|
67
|
+
RCTMultilineTextInputNativeCommands =
|
|
68
|
+
require('./RCTMultilineTextInputNativeComponent').Commands;
|
|
69
|
+
}
|
|
70
|
+
// [Windows
|
|
71
|
+
else if (Platform.OS === 'win32') {
|
|
72
|
+
WindowsTextInput = require('./Win32TextInputNativeComponent').default;
|
|
73
|
+
WindowsTextInputCommands =
|
|
74
|
+
require('./Win32TextInputNativeComponent').Commands;
|
|
75
|
+
}
|
|
76
|
+
// Windows]
|
|
77
|
+
|
|
51
78
|
export type ChangeEvent = SyntheticEvent<
|
|
52
79
|
$ReadOnly<{|
|
|
53
80
|
eventCount: number,
|
|
@@ -184,6 +211,15 @@ export type TextContentType =
|
|
|
184
211
|
| 'addressState'
|
|
185
212
|
| 'countryName'
|
|
186
213
|
| 'creditCardNumber'
|
|
214
|
+
| 'creditCardExpiration'
|
|
215
|
+
| 'creditCardExpirationMonth'
|
|
216
|
+
| 'creditCardExpirationYear'
|
|
217
|
+
| 'creditCardSecurityCode'
|
|
218
|
+
| 'creditCardType'
|
|
219
|
+
| 'creditCardName'
|
|
220
|
+
| 'creditCardGivenName'
|
|
221
|
+
| 'creditCardMiddleName'
|
|
222
|
+
| 'creditCardFamilyName'
|
|
187
223
|
| 'emailAddress'
|
|
188
224
|
| 'familyName'
|
|
189
225
|
| 'fullStreetAddress'
|
|
@@ -204,7 +240,11 @@ export type TextContentType =
|
|
|
204
240
|
| 'username'
|
|
205
241
|
| 'password'
|
|
206
242
|
| 'newPassword'
|
|
207
|
-
| 'oneTimeCode'
|
|
243
|
+
| 'oneTimeCode'
|
|
244
|
+
| 'birthdate'
|
|
245
|
+
| 'birthdateDay'
|
|
246
|
+
| 'birthdateMonth'
|
|
247
|
+
| 'birthdateYear';
|
|
208
248
|
|
|
209
249
|
export type enterKeyHintType =
|
|
210
250
|
// Cross Platform
|
|
@@ -320,6 +360,16 @@ type IOSProps = $ReadOnly<{|
|
|
|
320
360
|
* @platform ios
|
|
321
361
|
*/
|
|
322
362
|
lineBreakStrategyIOS?: ?('none' | 'standard' | 'hangul-word' | 'push-out'),
|
|
363
|
+
|
|
364
|
+
/**
|
|
365
|
+
* If `false`, the iOS system will not insert an extra space after a paste operation
|
|
366
|
+
* neither delete one or two spaces after a cut or delete operation.
|
|
367
|
+
*
|
|
368
|
+
* The default value is `true`.
|
|
369
|
+
*
|
|
370
|
+
* @platform ios
|
|
371
|
+
*/
|
|
372
|
+
smartInsertDelete?: ?boolean,
|
|
323
373
|
|}>;
|
|
324
374
|
|
|
325
375
|
type AndroidProps = $ReadOnly<{|
|
|
@@ -408,10 +458,37 @@ type AndroidProps = $ReadOnly<{|
|
|
|
408
458
|
underlineColorAndroid?: ?ColorValue,
|
|
409
459
|
|}>;
|
|
410
460
|
|
|
461
|
+
// [Windows
|
|
462
|
+
|
|
463
|
+
type SubmitKeyEvent = $ReadOnly<{|
|
|
464
|
+
altKey?: ?boolean,
|
|
465
|
+
ctrlKey?: ?boolean,
|
|
466
|
+
metaKey?: ?boolean,
|
|
467
|
+
shiftKey?: ?boolean,
|
|
468
|
+
code: string,
|
|
469
|
+
|}>;
|
|
470
|
+
|
|
471
|
+
type WindowsProps = $ReadOnly<{|
|
|
472
|
+
/**
|
|
473
|
+
* If `true`, clears the text field synchronously before `onSubmitEditing` is emitted.
|
|
474
|
+
* @platform windows
|
|
475
|
+
*/
|
|
476
|
+
clearTextOnSubmit?: ?boolean,
|
|
477
|
+
|
|
478
|
+
/**
|
|
479
|
+
* Configures keys that can be used to submit editing for the TextInput.
|
|
480
|
+
* @platform windows
|
|
481
|
+
*/
|
|
482
|
+
submitKeyEvents?: ?$ReadOnlyArray<SubmitKeyEvent>,
|
|
483
|
+
|}>;
|
|
484
|
+
|
|
485
|
+
// Windows]
|
|
486
|
+
|
|
411
487
|
export type Props = $ReadOnly<{|
|
|
412
488
|
...$Diff<ViewProps, $ReadOnly<{|style: ?ViewStyleProp|}>>,
|
|
413
489
|
...IOSProps,
|
|
414
490
|
...AndroidProps,
|
|
491
|
+
...WindowsProps, // [Windows]
|
|
415
492
|
|
|
416
493
|
/**
|
|
417
494
|
* String to be read by screenreaders to indicate an error state. The acceptable parameters
|
|
@@ -441,7 +518,16 @@ export type Props = $ReadOnly<{|
|
|
|
441
518
|
* - `additional-name`
|
|
442
519
|
* - `address-line1`
|
|
443
520
|
* - `address-line2`
|
|
521
|
+
* - `birthdate-day` (iOS 17+)
|
|
522
|
+
* - `birthdate-full` (iOS 17+)
|
|
523
|
+
* - `birthdate-month` (iOS 17+)
|
|
524
|
+
* - `birthdate-year` (iOS 17+)
|
|
444
525
|
* - `cc-number`
|
|
526
|
+
* - `cc-csc` (iOS 17+)
|
|
527
|
+
* - `cc-exp` (iOS 17+)
|
|
528
|
+
* - `cc-exp-day` (iOS 17+)
|
|
529
|
+
* - `cc-exp-month` (iOS 17+)
|
|
530
|
+
* - `cc-exp-year` (iOS 17+)
|
|
445
531
|
* - `country`
|
|
446
532
|
* - `current-password`
|
|
447
533
|
* - `email`
|
|
@@ -460,6 +546,11 @@ export type Props = $ReadOnly<{|
|
|
|
460
546
|
*
|
|
461
547
|
* The following values work on iOS only:
|
|
462
548
|
*
|
|
549
|
+
* - `cc-name` (iOS 17+)
|
|
550
|
+
* - `cc-given-name` (iOS 17+)
|
|
551
|
+
* - `cc-middle-name` (iOS 17+)
|
|
552
|
+
* - `cc-family-name` (iOS 17+)
|
|
553
|
+
* - `cc-type` (iOS 17+)
|
|
463
554
|
* - `nickname`
|
|
464
555
|
* - `organization`
|
|
465
556
|
* - `organization-title`
|
|
@@ -467,15 +558,6 @@ export type Props = $ReadOnly<{|
|
|
|
467
558
|
*
|
|
468
559
|
* The following values work on Android only:
|
|
469
560
|
*
|
|
470
|
-
* - `birthdate-day`
|
|
471
|
-
* - `birthdate-full`
|
|
472
|
-
* - `birthdate-month`
|
|
473
|
-
* - `birthdate-year`
|
|
474
|
-
* - `cc-csc`
|
|
475
|
-
* - `cc-exp`
|
|
476
|
-
* - `cc-exp-day`
|
|
477
|
-
* - `cc-exp-month`
|
|
478
|
-
* - `cc-exp-year`
|
|
479
561
|
* - `gender`
|
|
480
562
|
* - `name-family`
|
|
481
563
|
* - `name-given`
|
|
@@ -511,6 +593,11 @@ export type Props = $ReadOnly<{|
|
|
|
511
593
|
| 'cc-exp-month'
|
|
512
594
|
| 'cc-exp-year'
|
|
513
595
|
| 'cc-number'
|
|
596
|
+
| 'cc-name'
|
|
597
|
+
| 'cc-given-name'
|
|
598
|
+
| 'cc-middle-name'
|
|
599
|
+
| 'cc-family-name'
|
|
600
|
+
| 'cc-type'
|
|
514
601
|
| 'country'
|
|
515
602
|
| 'current-password'
|
|
516
603
|
| 'email'
|
|
@@ -575,7 +662,7 @@ export type Props = $ReadOnly<{|
|
|
|
575
662
|
* On Android devices manufactured by Xiaomi with Android Q,
|
|
576
663
|
* when keyboardType equals 'email-address'this will be set
|
|
577
664
|
* in native to 'true' to prevent a system related crash. This
|
|
578
|
-
* will cause cursor to be
|
|
665
|
+
* will cause cursor to be disabled as a side-effect.
|
|
579
666
|
*
|
|
580
667
|
*/
|
|
581
668
|
caretHidden?: ?boolean,
|
|
@@ -933,215 +1020,875 @@ export type Props = $ReadOnly<{|
|
|
|
933
1020
|
* unwanted edits without flicker.
|
|
934
1021
|
*/
|
|
935
1022
|
value?: ?Stringish,
|
|
936
|
-
|
|
937
|
-
text?: ?Stringish, // Win32
|
|
938
1023
|
|}>;
|
|
939
1024
|
|
|
940
|
-
|
|
941
|
-
import {
|
|
942
|
-
TextInputProps,
|
|
943
|
-
NativeMethods,
|
|
944
|
-
} from 'react-native';
|
|
945
|
-
import {
|
|
946
|
-
IBlurEvent,
|
|
947
|
-
IChangeEvent,
|
|
948
|
-
IFocusEvent,
|
|
949
|
-
} from './TextInput.Types.win32';
|
|
950
|
-
import React from 'react'
|
|
951
|
-
|
|
952
|
-
type RCTTextInputProps = TextInputProps & {
|
|
953
|
-
text: string;
|
|
954
|
-
};
|
|
955
|
-
*/
|
|
956
|
-
|
|
957
|
-
// RCTTextInput is the native component that win32 understands
|
|
958
|
-
const RCTTextInput = requireNativeComponent<Props>('RCTTextInput');
|
|
1025
|
+
const emptyFunctionThatReturnsTrue = () => true;
|
|
959
1026
|
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
1027
|
+
/**
|
|
1028
|
+
* A foundational component for inputting text into the app via a
|
|
1029
|
+
* keyboard. Props provide configurability for several features, such as
|
|
1030
|
+
* auto-correction, auto-capitalization, placeholder text, and different keyboard
|
|
1031
|
+
* types, such as a numeric keypad.
|
|
1032
|
+
*
|
|
1033
|
+
* The simplest use case is to plop down a `TextInput` and subscribe to the
|
|
1034
|
+
* `onChangeText` events to read the user input. There are also other events,
|
|
1035
|
+
* such as `onSubmitEditing` and `onFocus` that can be subscribed to. A simple
|
|
1036
|
+
* example:
|
|
1037
|
+
*
|
|
1038
|
+
* ```ReactNativeWebPlayer
|
|
1039
|
+
* import React, { Component } from 'react';
|
|
1040
|
+
* import { AppRegistry, TextInput } from 'react-native';
|
|
1041
|
+
*
|
|
1042
|
+
* export default class UselessTextInput extends Component {
|
|
1043
|
+
* constructor(props) {
|
|
1044
|
+
* super(props);
|
|
1045
|
+
* this.state = { text: 'Useless Placeholder' };
|
|
1046
|
+
* }
|
|
1047
|
+
*
|
|
1048
|
+
* render() {
|
|
1049
|
+
* return (
|
|
1050
|
+
* <TextInput
|
|
1051
|
+
* style={{height: 40, borderColor: 'gray', borderWidth: 1}}
|
|
1052
|
+
* onChangeText={(text) => this.setState({text})}
|
|
1053
|
+
* value={this.state.text}
|
|
1054
|
+
* />
|
|
1055
|
+
* );
|
|
1056
|
+
* }
|
|
1057
|
+
* }
|
|
1058
|
+
*
|
|
1059
|
+
* // skip this line if using Create React Native App
|
|
1060
|
+
* AppRegistry.registerComponent('AwesomeProject', () => UselessTextInput);
|
|
1061
|
+
* ```
|
|
1062
|
+
*
|
|
1063
|
+
* Two methods exposed via the native element are .focus() and .blur() that
|
|
1064
|
+
* will focus or blur the TextInput programmatically.
|
|
1065
|
+
*
|
|
1066
|
+
* Note that some props are only available with `multiline={true/false}`.
|
|
1067
|
+
* Additionally, border styles that apply to only one side of the element
|
|
1068
|
+
* (e.g., `borderBottomColor`, `borderLeftWidth`, etc.) will not be applied if
|
|
1069
|
+
* `multiline=false`. To achieve the same effect, you can wrap your `TextInput`
|
|
1070
|
+
* in a `View`:
|
|
1071
|
+
*
|
|
1072
|
+
* ```ReactNativeWebPlayer
|
|
1073
|
+
* import React, { Component } from 'react';
|
|
1074
|
+
* import { AppRegistry, View, TextInput } from 'react-native';
|
|
1075
|
+
*
|
|
1076
|
+
* class UselessTextInput extends Component {
|
|
1077
|
+
* render() {
|
|
1078
|
+
* return (
|
|
1079
|
+
* <TextInput
|
|
1080
|
+
* {...this.props} // Inherit any props passed to it; e.g., multiline, numberOfLines below
|
|
1081
|
+
* editable = {true}
|
|
1082
|
+
* maxLength = {40}
|
|
1083
|
+
* />
|
|
1084
|
+
* );
|
|
1085
|
+
* }
|
|
1086
|
+
* }
|
|
1087
|
+
*
|
|
1088
|
+
* export default class UselessTextInputMultiline extends Component {
|
|
1089
|
+
* constructor(props) {
|
|
1090
|
+
* super(props);
|
|
1091
|
+
* this.state = {
|
|
1092
|
+
* text: 'Useless Multiline Placeholder',
|
|
1093
|
+
* };
|
|
1094
|
+
* }
|
|
1095
|
+
*
|
|
1096
|
+
* // If you type something in the text box that is a color, the background will change to that
|
|
1097
|
+
* // color.
|
|
1098
|
+
* render() {
|
|
1099
|
+
* return (
|
|
1100
|
+
* <View style={{
|
|
1101
|
+
* backgroundColor: this.state.text,
|
|
1102
|
+
* borderBottomColor: '#000000',
|
|
1103
|
+
* borderBottomWidth: 1 }}
|
|
1104
|
+
* >
|
|
1105
|
+
* <UselessTextInput
|
|
1106
|
+
* multiline = {true}
|
|
1107
|
+
* numberOfLines = {4}
|
|
1108
|
+
* onChangeText={(text) => this.setState({text})}
|
|
1109
|
+
* value={this.state.text}
|
|
1110
|
+
* />
|
|
1111
|
+
* </View>
|
|
1112
|
+
* );
|
|
1113
|
+
* }
|
|
1114
|
+
* }
|
|
1115
|
+
*
|
|
1116
|
+
* // skip these lines if using Create React Native App
|
|
1117
|
+
* AppRegistry.registerComponent(
|
|
1118
|
+
* 'AwesomeProject',
|
|
1119
|
+
* () => UselessTextInputMultiline
|
|
1120
|
+
* );
|
|
1121
|
+
* ```
|
|
1122
|
+
*
|
|
1123
|
+
* `TextInput` has by default a border at the bottom of its view. This border
|
|
1124
|
+
* has its padding set by the background image provided by the system, and it
|
|
1125
|
+
* cannot be changed. Solutions to avoid this is to either not set height
|
|
1126
|
+
* explicitly, case in which the system will take care of displaying the border
|
|
1127
|
+
* in the correct position, or to not display the border by setting
|
|
1128
|
+
* `underlineColorAndroid` to transparent.
|
|
1129
|
+
*
|
|
1130
|
+
* Note that on Android performing text selection in input can change
|
|
1131
|
+
* app's activity `windowSoftInputMode` param to `adjustResize`.
|
|
1132
|
+
* This may cause issues with components that have position: 'absolute'
|
|
1133
|
+
* while keyboard is active. To avoid this behavior either specify `windowSoftInputMode`
|
|
1134
|
+
* in AndroidManifest.xml ( https://developer.android.com/guide/topics/manifest/activity-element.html )
|
|
1135
|
+
* or control this param programmatically with native code.
|
|
1136
|
+
*
|
|
1137
|
+
*/
|
|
1138
|
+
function InternalTextInput(props: Props): React.Node {
|
|
1139
|
+
const {
|
|
1140
|
+
'aria-busy': ariaBusy,
|
|
1141
|
+
'aria-checked': ariaChecked,
|
|
1142
|
+
'aria-disabled': ariaDisabled,
|
|
1143
|
+
'aria-expanded': ariaExpanded,
|
|
1144
|
+
'aria-selected': ariaSelected,
|
|
1145
|
+
'aria-multiselectable': ariaMultiselectable, // Win32
|
|
1146
|
+
'aria-required': ariaRequired, // Win32
|
|
1147
|
+
accessibilityState,
|
|
1148
|
+
id,
|
|
1149
|
+
tabIndex,
|
|
1150
|
+
selection: propsSelection,
|
|
1151
|
+
...otherProps
|
|
1152
|
+
} = props;
|
|
1153
|
+
|
|
1154
|
+
const inputRef = useRef<null | React.ElementRef<HostComponent<mixed>>>(null);
|
|
1155
|
+
|
|
1156
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
1157
|
+
const selection: ?Selection =
|
|
1158
|
+
propsSelection == null
|
|
1159
|
+
? null
|
|
1160
|
+
: {
|
|
1161
|
+
start: propsSelection.start,
|
|
1162
|
+
end: propsSelection.end ?? propsSelection.start,
|
|
1163
|
+
};
|
|
1164
|
+
|
|
1165
|
+
const [mostRecentEventCount, setMostRecentEventCount] = useState<number>(0);
|
|
1166
|
+
|
|
1167
|
+
const [lastNativeText, setLastNativeText] = useState<?Stringish>(props.value);
|
|
1168
|
+
const [lastNativeSelectionState, setLastNativeSelection] = useState<{|
|
|
1169
|
+
selection: ?Selection,
|
|
1170
|
+
mostRecentEventCount: number,
|
|
1171
|
+
|}>({selection, mostRecentEventCount});
|
|
1172
|
+
|
|
1173
|
+
const lastNativeSelection = lastNativeSelectionState.selection;
|
|
1174
|
+
|
|
1175
|
+
let viewCommands;
|
|
1176
|
+
if (AndroidTextInputCommands) {
|
|
1177
|
+
viewCommands = AndroidTextInputCommands;
|
|
1178
|
+
}
|
|
1179
|
+
// [Windows
|
|
1180
|
+
else if (WindowsTextInputCommands) {
|
|
1181
|
+
viewCommands = WindowsTextInputCommands;
|
|
1182
|
+
}
|
|
1183
|
+
// Windows]
|
|
1184
|
+
else {
|
|
1185
|
+
viewCommands =
|
|
1186
|
+
props.multiline === true
|
|
1187
|
+
? RCTMultilineTextInputNativeCommands
|
|
1188
|
+
: RCTSinglelineTextInputNativeCommands;
|
|
1189
|
+
}
|
|
963
1190
|
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
1191
|
+
const text =
|
|
1192
|
+
typeof props.value === 'string'
|
|
1193
|
+
? props.value
|
|
1194
|
+
: typeof props.defaultValue === 'string'
|
|
1195
|
+
? props.defaultValue
|
|
1196
|
+
: '';
|
|
1197
|
+
|
|
1198
|
+
// This is necessary in case native updates the text and JS decides
|
|
1199
|
+
// that the update should be ignored and we should stick with the value
|
|
1200
|
+
// that we have in JS.
|
|
1201
|
+
useLayoutEffect(() => {
|
|
1202
|
+
const nativeUpdate: {text?: string, selection?: Selection} = {};
|
|
1203
|
+
|
|
1204
|
+
if (lastNativeText !== props.value && typeof props.value === 'string') {
|
|
1205
|
+
nativeUpdate.text = props.value;
|
|
1206
|
+
setLastNativeText(props.value);
|
|
1207
|
+
}
|
|
968
1208
|
|
|
969
|
-
|
|
1209
|
+
if (
|
|
1210
|
+
selection &&
|
|
1211
|
+
lastNativeSelection &&
|
|
1212
|
+
(lastNativeSelection.start !== selection.start ||
|
|
1213
|
+
lastNativeSelection.end !== selection.end)
|
|
1214
|
+
) {
|
|
1215
|
+
nativeUpdate.selection = selection;
|
|
1216
|
+
setLastNativeSelection({selection, mostRecentEventCount});
|
|
1217
|
+
}
|
|
970
1218
|
|
|
971
|
-
|
|
972
|
-
|
|
1219
|
+
if (Object.keys(nativeUpdate).length === 0) {
|
|
1220
|
+
return;
|
|
1221
|
+
}
|
|
973
1222
|
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
1223
|
+
if (inputRef.current != null) {
|
|
1224
|
+
viewCommands.setTextAndSelection(
|
|
1225
|
+
inputRef.current,
|
|
1226
|
+
mostRecentEventCount,
|
|
1227
|
+
text,
|
|
1228
|
+
selection?.start ?? -1,
|
|
1229
|
+
selection?.end ?? -1,
|
|
1230
|
+
);
|
|
1231
|
+
}
|
|
1232
|
+
}, [
|
|
1233
|
+
mostRecentEventCount,
|
|
1234
|
+
inputRef,
|
|
1235
|
+
props.value,
|
|
1236
|
+
props.defaultValue,
|
|
1237
|
+
lastNativeText,
|
|
1238
|
+
selection,
|
|
1239
|
+
lastNativeSelection,
|
|
1240
|
+
text,
|
|
1241
|
+
viewCommands,
|
|
1242
|
+
]);
|
|
1243
|
+
|
|
1244
|
+
useLayoutEffect(() => {
|
|
1245
|
+
const inputRefValue = inputRef.current;
|
|
1246
|
+
|
|
1247
|
+
if (inputRefValue != null) {
|
|
1248
|
+
TextInputState.registerInput(inputRefValue);
|
|
1249
|
+
|
|
1250
|
+
return () => {
|
|
1251
|
+
TextInputState.unregisterInput(inputRefValue);
|
|
1252
|
+
|
|
1253
|
+
if (TextInputState.currentlyFocusedInput() === inputRefValue) {
|
|
1254
|
+
nullthrows(inputRefValue).blur();
|
|
1255
|
+
}
|
|
1256
|
+
};
|
|
1257
|
+
}
|
|
1258
|
+
}, [inputRef]);
|
|
1259
|
+
|
|
1260
|
+
const setLocalRef = useCallback(
|
|
1261
|
+
(instance: TextInputInstance | null) => {
|
|
1262
|
+
inputRef.current = instance;
|
|
1263
|
+
|
|
1264
|
+
/*
|
|
1265
|
+
Hi reader from the future. I'm sorry for this.
|
|
1266
|
+
|
|
1267
|
+
This is a hack. Ideally we would forwardRef to the underlying
|
|
1268
|
+
host component. However, since TextInput has it's own methods that can be
|
|
1269
|
+
called as well, if we used the standard forwardRef then these
|
|
1270
|
+
methods wouldn't be accessible and thus be a breaking change.
|
|
1271
|
+
|
|
1272
|
+
We have a couple of options of how to handle this:
|
|
1273
|
+
- Return a new ref with everything we methods from both. This is problematic
|
|
1274
|
+
because we need React to also know it is a host component which requires
|
|
1275
|
+
internals of the class implementation of the ref.
|
|
1276
|
+
- Break the API and have some other way to call one set of the methods or
|
|
1277
|
+
the other. This is our long term approach as we want to eventually
|
|
1278
|
+
get the methods on host components off the ref. So instead of calling
|
|
1279
|
+
ref.measure() you might call ReactNative.measure(ref). This would hopefully
|
|
1280
|
+
let the ref for TextInput then have the methods like `.clear`. Or we do it
|
|
1281
|
+
the other way and make it TextInput.clear(textInputRef) which would be fine
|
|
1282
|
+
too. Either way though is a breaking change that is longer term.
|
|
1283
|
+
- Mutate this ref. :( Gross, but accomplishes what we need in the meantime
|
|
1284
|
+
before we can get to the long term breaking change.
|
|
1285
|
+
*/
|
|
1286
|
+
if (instance != null) {
|
|
1287
|
+
// $FlowFixMe[incompatible-use] - See the explanation above.
|
|
1288
|
+
Object.assign(instance, {
|
|
1289
|
+
clear(): void {
|
|
1290
|
+
if (inputRef.current != null) {
|
|
1291
|
+
viewCommands.setTextAndSelection(
|
|
1292
|
+
inputRef.current,
|
|
1293
|
+
mostRecentEventCount,
|
|
1294
|
+
'',
|
|
1295
|
+
0,
|
|
1296
|
+
0,
|
|
1297
|
+
);
|
|
1298
|
+
}
|
|
1299
|
+
},
|
|
1300
|
+
// TODO: Fix this returning true on null === null, when no input is focused
|
|
1301
|
+
isFocused(): boolean {
|
|
1302
|
+
return TextInputState.currentlyFocusedInput() === inputRef.current;
|
|
1303
|
+
},
|
|
1304
|
+
getNativeRef(): ?React.ElementRef<HostComponent<mixed>> {
|
|
1305
|
+
return inputRef.current;
|
|
1306
|
+
},
|
|
1307
|
+
setSelection(start: number, end: number): void {
|
|
1308
|
+
if (inputRef.current != null) {
|
|
1309
|
+
viewCommands.setTextAndSelection(
|
|
1310
|
+
inputRef.current,
|
|
1311
|
+
mostRecentEventCount,
|
|
1312
|
+
null,
|
|
1313
|
+
start,
|
|
1314
|
+
end,
|
|
1315
|
+
);
|
|
1316
|
+
}
|
|
1317
|
+
},
|
|
1318
|
+
});
|
|
1319
|
+
}
|
|
1320
|
+
},
|
|
1321
|
+
[mostRecentEventCount, viewCommands],
|
|
1322
|
+
);
|
|
1323
|
+
|
|
1324
|
+
const ref = useMergeRefs<TextInputInstance | null>(
|
|
1325
|
+
setLocalRef,
|
|
1326
|
+
props.forwardedRef,
|
|
1327
|
+
);
|
|
1328
|
+
|
|
1329
|
+
const _onChange = (event: ChangeEvent) => {
|
|
1330
|
+
const currentText = event.nativeEvent.text;
|
|
1331
|
+
props.onChange && props.onChange(event);
|
|
1332
|
+
props.onChangeText && props.onChangeText(currentText);
|
|
1333
|
+
|
|
1334
|
+
if (inputRef.current == null) {
|
|
1335
|
+
// calling `props.onChange` or `props.onChangeText`
|
|
1336
|
+
// may clean up the input itself. Exits here.
|
|
1337
|
+
return;
|
|
1338
|
+
}
|
|
977
1339
|
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
1340
|
+
setLastNativeText(currentText);
|
|
1341
|
+
// This must happen last, after we call setLastNativeText.
|
|
1342
|
+
// Different ordering can cause bugs when editing AndroidTextInputs
|
|
1343
|
+
// with multiple Fragments.
|
|
1344
|
+
// We must update this so that controlled input updates work.
|
|
1345
|
+
setMostRecentEventCount(event.nativeEvent.eventCount);
|
|
1346
|
+
};
|
|
984
1347
|
|
|
985
|
-
|
|
986
|
-
|
|
1348
|
+
const _onChangeSync = (event: ChangeEvent) => {
|
|
1349
|
+
const currentText = event.nativeEvent.text;
|
|
1350
|
+
props.unstable_onChangeSync && props.unstable_onChangeSync(event);
|
|
1351
|
+
props.unstable_onChangeTextSync &&
|
|
1352
|
+
props.unstable_onChangeTextSync(currentText);
|
|
987
1353
|
|
|
988
|
-
if (
|
|
989
|
-
|
|
1354
|
+
if (inputRef.current == null) {
|
|
1355
|
+
// calling `props.onChange` or `props.onChangeText`
|
|
1356
|
+
// may clean up the input itself. Exits here.
|
|
1357
|
+
return;
|
|
990
1358
|
}
|
|
991
|
-
}
|
|
992
1359
|
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
this._getText() && this.setNativeText(this._getText());
|
|
1001
|
-
}
|
|
1360
|
+
setLastNativeText(currentText);
|
|
1361
|
+
// This must happen last, after we call setLastNativeText.
|
|
1362
|
+
// Different ordering can cause bugs when editing AndroidTextInputs
|
|
1363
|
+
// with multiple Fragments.
|
|
1364
|
+
// We must update this so that controlled input updates work.
|
|
1365
|
+
setMostRecentEventCount(event.nativeEvent.eventCount);
|
|
1366
|
+
};
|
|
1002
1367
|
|
|
1003
|
-
|
|
1004
|
-
|
|
1368
|
+
const _onSelectionChange = (event: SelectionChangeEvent) => {
|
|
1369
|
+
props.onSelectionChange && props.onSelectionChange(event);
|
|
1005
1370
|
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
componentWillUnmount() {
|
|
1011
|
-
// blur
|
|
1012
|
-
if (this.isFocused()) {
|
|
1013
|
-
this.blur();
|
|
1371
|
+
if (inputRef.current == null) {
|
|
1372
|
+
// calling `props.onSelectionChange`
|
|
1373
|
+
// may clean up the input itself. Exits here.
|
|
1374
|
+
return;
|
|
1014
1375
|
}
|
|
1015
1376
|
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1377
|
+
setLastNativeSelection({
|
|
1378
|
+
selection: event.nativeEvent.selection,
|
|
1379
|
+
mostRecentEventCount,
|
|
1380
|
+
});
|
|
1381
|
+
};
|
|
1019
1382
|
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1383
|
+
const _onFocus = (event: FocusEvent) => {
|
|
1384
|
+
TextInputState.focusInput(inputRef.current);
|
|
1385
|
+
if (props.onFocus) {
|
|
1386
|
+
props.onFocus(event);
|
|
1023
1387
|
}
|
|
1024
|
-
|
|
1025
|
-
|
|
1388
|
+
};
|
|
1389
|
+
|
|
1390
|
+
const _onBlur = (event: BlurEvent) => {
|
|
1391
|
+
TextInputState.blurInput(inputRef.current);
|
|
1392
|
+
if (props.onBlur) {
|
|
1393
|
+
props.onBlur(event);
|
|
1026
1394
|
}
|
|
1027
|
-
|
|
1028
|
-
}
|
|
1395
|
+
};
|
|
1029
1396
|
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
allowFontScaling =
|
|
1034
|
-
this.props.allowFontScaling === null ||
|
|
1035
|
-
this.props.allowFontScaling === undefined
|
|
1036
|
-
? true
|
|
1037
|
-
: this.props.allowFontScaling;
|
|
1038
|
-
|
|
1039
|
-
return (
|
|
1040
|
-
<TextAncestor.Provider value={true}>
|
|
1041
|
-
<RCTTextInput
|
|
1042
|
-
{...otherProps}
|
|
1043
|
-
allowFontScaling={allowFontScaling}
|
|
1044
|
-
text={this._getText()}
|
|
1045
|
-
onFocus={this._onFocus}
|
|
1046
|
-
onBlur={this._onBlur}
|
|
1047
|
-
onChange={this._onChange}
|
|
1048
|
-
/>
|
|
1049
|
-
</TextAncestor.Provider>
|
|
1050
|
-
);
|
|
1051
|
-
}
|
|
1397
|
+
const _onScroll = (event: ScrollEvent) => {
|
|
1398
|
+
props.onScroll && props.onScroll(event);
|
|
1399
|
+
};
|
|
1052
1400
|
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1401
|
+
let textInput = null;
|
|
1402
|
+
|
|
1403
|
+
const multiline = props.multiline ?? false;
|
|
1404
|
+
|
|
1405
|
+
let submitBehavior: SubmitBehavior;
|
|
1406
|
+
if (props.submitBehavior != null) {
|
|
1407
|
+
// `submitBehavior` is set explicitly
|
|
1408
|
+
if (!multiline && props.submitBehavior === 'newline') {
|
|
1409
|
+
// For single line text inputs, `'newline'` is not a valid option
|
|
1410
|
+
submitBehavior = 'blurAndSubmit';
|
|
1411
|
+
} else {
|
|
1412
|
+
submitBehavior = props.submitBehavior;
|
|
1413
|
+
}
|
|
1414
|
+
} else if (multiline) {
|
|
1415
|
+
if (props.blurOnSubmit === true) {
|
|
1416
|
+
submitBehavior = 'blurAndSubmit';
|
|
1417
|
+
} else {
|
|
1418
|
+
submitBehavior = 'newline';
|
|
1419
|
+
}
|
|
1420
|
+
} else {
|
|
1421
|
+
// Single line
|
|
1422
|
+
if (props.blurOnSubmit !== false) {
|
|
1423
|
+
submitBehavior = 'blurAndSubmit';
|
|
1424
|
+
} else {
|
|
1425
|
+
submitBehavior = 'submit';
|
|
1426
|
+
}
|
|
1058
1427
|
}
|
|
1059
1428
|
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
)
|
|
1071
|
-
|
|
1429
|
+
const accessible = props.accessible !== false;
|
|
1430
|
+
|
|
1431
|
+
const accessibilityErrorMessage =
|
|
1432
|
+
props.accessibilityInvalid === true
|
|
1433
|
+
? props.accessibilityErrorMessage
|
|
1434
|
+
: null;
|
|
1435
|
+
|
|
1436
|
+
const focusable = props.focusable !== false;
|
|
1437
|
+
|
|
1438
|
+
const config = React.useMemo(
|
|
1439
|
+
() => ({
|
|
1440
|
+
hitSlop: props.hitSlop,
|
|
1441
|
+
onPress: (event: PressEvent) => {
|
|
1442
|
+
if (props.editable !== false) {
|
|
1443
|
+
if (inputRef.current != null) {
|
|
1444
|
+
inputRef.current.focus();
|
|
1445
|
+
}
|
|
1446
|
+
}
|
|
1447
|
+
},
|
|
1448
|
+
onPressIn: props.onPressIn,
|
|
1449
|
+
onPressOut: props.onPressOut,
|
|
1450
|
+
cancelable:
|
|
1451
|
+
Platform.OS === 'ios' ? !props.rejectResponderTermination : null,
|
|
1452
|
+
}),
|
|
1453
|
+
[
|
|
1454
|
+
props.editable,
|
|
1455
|
+
props.hitSlop,
|
|
1456
|
+
props.onPressIn,
|
|
1457
|
+
props.onPressOut,
|
|
1458
|
+
props.rejectResponderTermination,
|
|
1459
|
+
],
|
|
1460
|
+
);
|
|
1461
|
+
|
|
1462
|
+
// Hide caret during test runs due to a flashing caret
|
|
1463
|
+
// makes screenshot tests flakey
|
|
1464
|
+
let caretHidden = props.caretHidden;
|
|
1465
|
+
if (Platform.isTesting) {
|
|
1466
|
+
caretHidden = true;
|
|
1467
|
+
}
|
|
1072
1468
|
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1469
|
+
// TextInput handles onBlur and onFocus events
|
|
1470
|
+
// so omitting onBlur and onFocus pressability handlers here.
|
|
1471
|
+
const {onBlur, onFocus, ...eventHandlers} = usePressability(config) || {};
|
|
1472
|
+
const eventPhase = Object.freeze({Capturing: 1, Bubbling: 3});
|
|
1473
|
+
const _keyDown = (event: KeyEvent) => {
|
|
1474
|
+
if (props.keyDownEvents && event.isPropagationStopped() !== true) {
|
|
1475
|
+
// $FlowFixMe - keyDownEvents was already checked to not be undefined
|
|
1476
|
+
for (const el of props.keyDownEvents) {
|
|
1477
|
+
if (
|
|
1478
|
+
event.nativeEvent.code == el.code &&
|
|
1479
|
+
el.handledEventPhase == eventPhase.Bubbling
|
|
1480
|
+
) {
|
|
1481
|
+
event.stopPropagation();
|
|
1482
|
+
}
|
|
1483
|
+
}
|
|
1484
|
+
}
|
|
1485
|
+
props.onKeyDown && props.onKeyDown(event);
|
|
1084
1486
|
};
|
|
1085
1487
|
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1488
|
+
const _keyUp = (event: KeyEvent) => {
|
|
1489
|
+
if (props.keyUpEvents && event.isPropagationStopped() !== true) {
|
|
1490
|
+
// $FlowFixMe - keyDownEvents was already checked to not be undefined
|
|
1491
|
+
for (const el of props.keyUpEvents) {
|
|
1492
|
+
if (event.nativeEvent.code == el.code && el.handledEventPhase == 3) {
|
|
1493
|
+
event.stopPropagation();
|
|
1494
|
+
}
|
|
1495
|
+
}
|
|
1496
|
+
}
|
|
1497
|
+
props.onKeyUp && props.onKeyUp(event);
|
|
1091
1498
|
};
|
|
1092
1499
|
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1500
|
+
const _keyDownCapture = (event: KeyEvent) => {
|
|
1501
|
+
if (props.keyDownEvents && event.isPropagationStopped() !== true) {
|
|
1502
|
+
// $FlowFixMe - keyDownEvents was already checked to not be undefined
|
|
1503
|
+
for (const el of props.keyDownEvents) {
|
|
1504
|
+
if (event.nativeEvent.code == el.code && el.handledEventPhase == 1) {
|
|
1505
|
+
event.stopPropagation();
|
|
1506
|
+
}
|
|
1507
|
+
}
|
|
1508
|
+
}
|
|
1509
|
+
props.onKeyDownCapture && props.onKeyDownCapture(event);
|
|
1099
1510
|
};
|
|
1100
1511
|
|
|
1101
|
-
|
|
1102
|
-
if (
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1512
|
+
const _keyUpCapture = (event: KeyEvent) => {
|
|
1513
|
+
if (props.keyUpEvents && event.isPropagationStopped() !== true) {
|
|
1514
|
+
// $FlowFixMe - keyDownEvents was already checked to not be undefined
|
|
1515
|
+
for (const el of props.keyUpEvents) {
|
|
1516
|
+
if (event.nativeEvent.code == el.code && el.handledEventPhase == 1) {
|
|
1517
|
+
event.stopPropagation();
|
|
1518
|
+
}
|
|
1519
|
+
}
|
|
1108
1520
|
}
|
|
1521
|
+
props.onKeyUpCapture && props.onKeyUpCapture(event);
|
|
1109
1522
|
};
|
|
1110
1523
|
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1524
|
+
let _accessibilityState;
|
|
1525
|
+
if (
|
|
1526
|
+
accessibilityState != null ||
|
|
1527
|
+
ariaBusy != null ||
|
|
1528
|
+
ariaChecked != null ||
|
|
1529
|
+
ariaDisabled != null ||
|
|
1530
|
+
ariaExpanded != null ||
|
|
1531
|
+
ariaMultiselectable != null ||
|
|
1532
|
+
ariaRequired != null ||
|
|
1533
|
+
ariaSelected != null
|
|
1534
|
+
) {
|
|
1535
|
+
_accessibilityState = {
|
|
1536
|
+
busy: ariaBusy ?? accessibilityState?.busy,
|
|
1537
|
+
checked: ariaChecked ?? accessibilityState?.checked,
|
|
1538
|
+
disabled: ariaDisabled ?? accessibilityState?.disabled,
|
|
1539
|
+
expanded: ariaExpanded ?? accessibilityState?.expanded,
|
|
1540
|
+
multiselectable:
|
|
1541
|
+
ariaMultiselectable ?? accessibilityState?.multiselectable, // Win32
|
|
1542
|
+
required: ariaRequired ?? accessibilityState?.required, // Win32
|
|
1543
|
+
selected: ariaSelected ?? accessibilityState?.selected,
|
|
1544
|
+
};
|
|
1545
|
+
}
|
|
1546
|
+
|
|
1547
|
+
// $FlowFixMe[underconstrained-implicit-instantiation]
|
|
1548
|
+
let style = flattenStyle(props.style);
|
|
1549
|
+
|
|
1550
|
+
if (Platform.OS === 'ios') {
|
|
1551
|
+
const RCTTextInputView =
|
|
1552
|
+
props.multiline === true
|
|
1553
|
+
? RCTMultilineTextInputView
|
|
1554
|
+
: RCTSinglelineTextInputView;
|
|
1555
|
+
|
|
1556
|
+
style = props.multiline === true ? [styles.multilineInput, style] : style;
|
|
1557
|
+
|
|
1558
|
+
const useOnChangeSync =
|
|
1559
|
+
(props.unstable_onChangeSync || props.unstable_onChangeTextSync) &&
|
|
1560
|
+
!(props.onChange || props.onChangeText);
|
|
1561
|
+
|
|
1562
|
+
textInput = (
|
|
1563
|
+
<RCTTextInputView
|
|
1564
|
+
// $FlowFixMe[incompatible-type] - Figure out imperative + forward refs.
|
|
1565
|
+
ref={ref}
|
|
1566
|
+
{...otherProps}
|
|
1567
|
+
{...eventHandlers}
|
|
1568
|
+
accessibilityErrorMessage={accessibilityErrorMessage}
|
|
1569
|
+
accessibilityState={_accessibilityState}
|
|
1570
|
+
accessible={accessible}
|
|
1571
|
+
submitBehavior={submitBehavior}
|
|
1572
|
+
caretHidden={caretHidden}
|
|
1573
|
+
dataDetectorTypes={props.dataDetectorTypes}
|
|
1574
|
+
focusable={tabIndex !== undefined ? !tabIndex : focusable}
|
|
1575
|
+
mostRecentEventCount={mostRecentEventCount}
|
|
1576
|
+
nativeID={id ?? props.nativeID}
|
|
1577
|
+
onBlur={_onBlur}
|
|
1578
|
+
onKeyPressSync={props.unstable_onKeyPressSync}
|
|
1579
|
+
onChange={_onChange}
|
|
1580
|
+
onChangeSync={useOnChangeSync === true ? _onChangeSync : null}
|
|
1581
|
+
onContentSizeChange={props.onContentSizeChange}
|
|
1582
|
+
onFocus={_onFocus}
|
|
1583
|
+
onScroll={_onScroll}
|
|
1584
|
+
onSelectionChange={_onSelectionChange}
|
|
1585
|
+
onSelectionChangeShouldSetResponder={emptyFunctionThatReturnsTrue}
|
|
1586
|
+
selection={selection}
|
|
1587
|
+
style={style}
|
|
1588
|
+
text={text}
|
|
1589
|
+
/>
|
|
1590
|
+
);
|
|
1591
|
+
} else if (Platform.OS === 'android') {
|
|
1592
|
+
const autoCapitalize = props.autoCapitalize || 'sentences';
|
|
1593
|
+
const _accessibilityLabelledBy =
|
|
1594
|
+
props?.['aria-labelledby'] ?? props?.accessibilityLabelledBy;
|
|
1595
|
+
const placeholder = props.placeholder ?? '';
|
|
1596
|
+
let children = props.children;
|
|
1597
|
+
const childCount = React.Children.count(children);
|
|
1598
|
+
invariant(
|
|
1599
|
+
!(props.value != null && childCount),
|
|
1600
|
+
'Cannot specify both value and children.',
|
|
1601
|
+
);
|
|
1602
|
+
if (childCount > 1) {
|
|
1603
|
+
children = <Text>{children}</Text>;
|
|
1120
1604
|
}
|
|
1121
|
-
return null;
|
|
1122
|
-
};
|
|
1123
1605
|
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1606
|
+
textInput = (
|
|
1607
|
+
/* $FlowFixMe[prop-missing] the types for AndroidTextInput don't match up
|
|
1608
|
+
* exactly with the props for TextInput. This will need to get fixed */
|
|
1609
|
+
/* $FlowFixMe[incompatible-type] the types for AndroidTextInput don't
|
|
1610
|
+
* match up exactly with the props for TextInput. This will need to get
|
|
1611
|
+
* fixed */
|
|
1612
|
+
/* $FlowFixMe[incompatible-type-arg] the types for AndroidTextInput don't
|
|
1613
|
+
* match up exactly with the props for TextInput. This will need to get
|
|
1614
|
+
* fixed */
|
|
1615
|
+
<AndroidTextInput
|
|
1616
|
+
// $FlowFixMe[incompatible-type] - Figure out imperative + forward refs.
|
|
1617
|
+
ref={ref}
|
|
1618
|
+
{...otherProps}
|
|
1619
|
+
{...eventHandlers}
|
|
1620
|
+
accessibilityErrorMessage={accessibilityErrorMessage}
|
|
1621
|
+
accessibilityState={_accessibilityState}
|
|
1622
|
+
accessibilityLabelledBy={_accessibilityLabelledBy}
|
|
1623
|
+
accessible={accessible}
|
|
1624
|
+
autoCapitalize={autoCapitalize}
|
|
1625
|
+
submitBehavior={submitBehavior}
|
|
1626
|
+
caretHidden={caretHidden}
|
|
1627
|
+
children={children}
|
|
1628
|
+
disableFullscreenUI={props.disableFullscreenUI}
|
|
1629
|
+
focusable={tabIndex !== undefined ? !tabIndex : focusable}
|
|
1630
|
+
mostRecentEventCount={mostRecentEventCount}
|
|
1631
|
+
nativeID={id ?? props.nativeID}
|
|
1632
|
+
numberOfLines={props.rows ?? props.numberOfLines}
|
|
1633
|
+
onBlur={_onBlur}
|
|
1634
|
+
onChange={_onChange}
|
|
1635
|
+
onFocus={_onFocus}
|
|
1636
|
+
/* $FlowFixMe[prop-missing] the types for AndroidTextInput don't match
|
|
1637
|
+
* up exactly with the props for TextInput. This will need to get fixed
|
|
1638
|
+
*/
|
|
1639
|
+
/* $FlowFixMe[incompatible-type-arg] the types for AndroidTextInput
|
|
1640
|
+
* don't match up exactly with the props for TextInput. This will need
|
|
1641
|
+
* to get fixed */
|
|
1642
|
+
onScroll={_onScroll}
|
|
1643
|
+
onSelectionChange={_onSelectionChange}
|
|
1644
|
+
placeholder={placeholder}
|
|
1645
|
+
style={style}
|
|
1646
|
+
text={text}
|
|
1647
|
+
textBreakStrategy={props.textBreakStrategy}
|
|
1648
|
+
/>
|
|
1649
|
+
);
|
|
1650
|
+
} // [Windows
|
|
1651
|
+
else if (Platform.OS === 'win32') {
|
|
1652
|
+
textInput = (
|
|
1653
|
+
<WindowsTextInput
|
|
1654
|
+
// $FlowFixMe[incompatible-type] - Figure out imperative + forward refs.
|
|
1655
|
+
ref={ref}
|
|
1656
|
+
{...props}
|
|
1657
|
+
accessible={accessible}
|
|
1658
|
+
focusable={focusable}
|
|
1659
|
+
dataDetectorTypes={props.dataDetectorTypes}
|
|
1660
|
+
mostRecentEventCount={mostRecentEventCount}
|
|
1661
|
+
onBlur={_onBlur}
|
|
1662
|
+
onChange={_onChange}
|
|
1663
|
+
onContentSizeChange={props.onContentSizeChange}
|
|
1664
|
+
onFocus={_onFocus}
|
|
1665
|
+
onScroll={_onScroll}
|
|
1666
|
+
onSelectionChange={_onSelectionChange}
|
|
1667
|
+
onSelectionChangeShouldSetResponder={emptyFunctionThatReturnsTrue}
|
|
1668
|
+
selection={selection}
|
|
1669
|
+
text={text}
|
|
1670
|
+
onKeyDown={_keyDown}
|
|
1671
|
+
onKeyDownCapture={_keyDownCapture}
|
|
1672
|
+
onKeyUp={_keyUp}
|
|
1673
|
+
onKeyUpCapture={_keyUpCapture}
|
|
1674
|
+
/>
|
|
1675
|
+
);
|
|
1676
|
+
} // Windows]
|
|
1677
|
+
return (
|
|
1678
|
+
<TextAncestor.Provider value={true}>{textInput}</TextAncestor.Provider>
|
|
1679
|
+
);
|
|
1680
|
+
}
|
|
1128
1681
|
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1682
|
+
const enterKeyHintToReturnTypeMap = {
|
|
1683
|
+
enter: 'default',
|
|
1684
|
+
done: 'done',
|
|
1685
|
+
go: 'go',
|
|
1686
|
+
next: 'next',
|
|
1687
|
+
previous: 'previous',
|
|
1688
|
+
search: 'search',
|
|
1689
|
+
send: 'send',
|
|
1690
|
+
};
|
|
1132
1691
|
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1692
|
+
const inputModeToKeyboardTypeMap = {
|
|
1693
|
+
none: 'default',
|
|
1694
|
+
text: 'default',
|
|
1695
|
+
decimal: 'decimal-pad',
|
|
1696
|
+
numeric: 'number-pad',
|
|
1697
|
+
tel: 'phone-pad',
|
|
1698
|
+
search: Platform.OS === 'ios' ? 'web-search' : 'default',
|
|
1699
|
+
email: 'email-address',
|
|
1700
|
+
url: 'url',
|
|
1701
|
+
};
|
|
1136
1702
|
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1703
|
+
// Map HTML autocomplete values to Android autoComplete values
|
|
1704
|
+
const autoCompleteWebToAutoCompleteAndroidMap = {
|
|
1705
|
+
'address-line1': 'postal-address-region',
|
|
1706
|
+
'address-line2': 'postal-address-locality',
|
|
1707
|
+
bday: 'birthdate-full',
|
|
1708
|
+
'bday-day': 'birthdate-day',
|
|
1709
|
+
'bday-month': 'birthdate-month',
|
|
1710
|
+
'bday-year': 'birthdate-year',
|
|
1711
|
+
'cc-csc': 'cc-csc',
|
|
1712
|
+
'cc-exp': 'cc-exp',
|
|
1713
|
+
'cc-exp-month': 'cc-exp-month',
|
|
1714
|
+
'cc-exp-year': 'cc-exp-year',
|
|
1715
|
+
'cc-number': 'cc-number',
|
|
1716
|
+
country: 'postal-address-country',
|
|
1717
|
+
'current-password': 'password',
|
|
1718
|
+
email: 'email',
|
|
1719
|
+
'honorific-prefix': 'name-prefix',
|
|
1720
|
+
'honorific-suffix': 'name-suffix',
|
|
1721
|
+
name: 'name',
|
|
1722
|
+
'additional-name': 'name-middle',
|
|
1723
|
+
'family-name': 'name-family',
|
|
1724
|
+
'given-name': 'name-given',
|
|
1725
|
+
'new-password': 'password-new',
|
|
1726
|
+
off: 'off',
|
|
1727
|
+
'one-time-code': 'sms-otp',
|
|
1728
|
+
'postal-code': 'postal-code',
|
|
1729
|
+
sex: 'gender',
|
|
1730
|
+
'street-address': 'street-address',
|
|
1731
|
+
tel: 'tel',
|
|
1732
|
+
'tel-country-code': 'tel-country-code',
|
|
1733
|
+
'tel-national': 'tel-national',
|
|
1734
|
+
username: 'username',
|
|
1735
|
+
};
|
|
1141
1736
|
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1737
|
+
// Map HTML autocomplete values to iOS textContentType values
|
|
1738
|
+
const autoCompleteWebToTextContentTypeMap = {
|
|
1739
|
+
'address-line1': 'streetAddressLine1',
|
|
1740
|
+
'address-line2': 'streetAddressLine2',
|
|
1741
|
+
bday: 'birthdate',
|
|
1742
|
+
'bday-day': 'birthdateDay',
|
|
1743
|
+
'bday-month': 'birthdateMonth',
|
|
1744
|
+
'bday-year': 'birthdateYear',
|
|
1745
|
+
'cc-csc': 'creditCardSecurityCode',
|
|
1746
|
+
'cc-exp-month': 'creditCardExpirationMonth',
|
|
1747
|
+
'cc-exp-year': 'creditCardExpirationYear',
|
|
1748
|
+
'cc-exp': 'creditCardExpiration',
|
|
1749
|
+
'cc-given-name': 'creditCardGivenName',
|
|
1750
|
+
'cc-additional-name': 'creditCardMiddleName',
|
|
1751
|
+
'cc-family-name': 'creditCardFamilyName',
|
|
1752
|
+
'cc-name': 'creditCardName',
|
|
1753
|
+
'cc-number': 'creditCardNumber',
|
|
1754
|
+
'cc-type': 'creditCardType',
|
|
1755
|
+
'current-password': 'password',
|
|
1756
|
+
country: 'countryName',
|
|
1757
|
+
email: 'emailAddress',
|
|
1758
|
+
name: 'name',
|
|
1759
|
+
'additional-name': 'middleName',
|
|
1760
|
+
'family-name': 'familyName',
|
|
1761
|
+
'given-name': 'givenName',
|
|
1762
|
+
nickname: 'nickname',
|
|
1763
|
+
'honorific-prefix': 'namePrefix',
|
|
1764
|
+
'honorific-suffix': 'nameSuffix',
|
|
1765
|
+
'new-password': 'newPassword',
|
|
1766
|
+
off: 'none',
|
|
1767
|
+
'one-time-code': 'oneTimeCode',
|
|
1768
|
+
organization: 'organizationName',
|
|
1769
|
+
'organization-title': 'jobTitle',
|
|
1770
|
+
'postal-code': 'postalCode',
|
|
1771
|
+
'street-address': 'fullStreetAddress',
|
|
1772
|
+
tel: 'telephoneNumber',
|
|
1773
|
+
url: 'URL',
|
|
1774
|
+
username: 'username',
|
|
1775
|
+
};
|
|
1776
|
+
|
|
1777
|
+
const ExportedForwardRef: React.AbstractComponent<
|
|
1778
|
+
React.ElementConfig<typeof InternalTextInput>,
|
|
1779
|
+
TextInputInstance,
|
|
1780
|
+
// $FlowFixMe[incompatible-call]
|
|
1781
|
+
> = React.forwardRef(function TextInput(
|
|
1782
|
+
{
|
|
1783
|
+
allowFontScaling = true,
|
|
1784
|
+
rejectResponderTermination = true,
|
|
1785
|
+
underlineColorAndroid = 'transparent',
|
|
1786
|
+
autoComplete,
|
|
1787
|
+
textContentType,
|
|
1788
|
+
readOnly,
|
|
1789
|
+
editable,
|
|
1790
|
+
enterKeyHint,
|
|
1791
|
+
returnKeyType,
|
|
1792
|
+
inputMode,
|
|
1793
|
+
showSoftInputOnFocus,
|
|
1794
|
+
keyboardType,
|
|
1795
|
+
...restProps
|
|
1796
|
+
},
|
|
1797
|
+
forwardedRef: ReactRefSetter<TextInputInstance>,
|
|
1798
|
+
) {
|
|
1799
|
+
// $FlowFixMe[underconstrained-implicit-instantiation]
|
|
1800
|
+
let style = flattenStyle(restProps.style);
|
|
1801
|
+
|
|
1802
|
+
if (style?.verticalAlign != null) {
|
|
1803
|
+
// $FlowFixMe[prop-missing]
|
|
1804
|
+
// $FlowFixMe[cannot-write]
|
|
1805
|
+
style.textAlignVertical =
|
|
1806
|
+
// $FlowFixMe[invalid-computed-prop]
|
|
1807
|
+
verticalAlignToTextAlignVerticalMap[style.verticalAlign];
|
|
1808
|
+
// $FlowFixMe[prop-missing]
|
|
1809
|
+
// $FlowFixMe[cannot-write]
|
|
1810
|
+
delete style.verticalAlign;
|
|
1811
|
+
}
|
|
1812
|
+
|
|
1813
|
+
return (
|
|
1814
|
+
<InternalTextInput
|
|
1815
|
+
allowFontScaling={allowFontScaling}
|
|
1816
|
+
rejectResponderTermination={rejectResponderTermination}
|
|
1817
|
+
underlineColorAndroid={underlineColorAndroid}
|
|
1818
|
+
editable={readOnly !== undefined ? !readOnly : editable}
|
|
1819
|
+
returnKeyType={
|
|
1820
|
+
enterKeyHint ? enterKeyHintToReturnTypeMap[enterKeyHint] : returnKeyType
|
|
1821
|
+
}
|
|
1822
|
+
keyboardType={
|
|
1823
|
+
inputMode ? inputModeToKeyboardTypeMap[inputMode] : keyboardType
|
|
1824
|
+
}
|
|
1825
|
+
showSoftInputOnFocus={
|
|
1826
|
+
inputMode == null ? showSoftInputOnFocus : inputMode !== 'none'
|
|
1827
|
+
}
|
|
1828
|
+
autoComplete={
|
|
1829
|
+
Platform.OS === 'android'
|
|
1830
|
+
? // $FlowFixMe
|
|
1831
|
+
autoCompleteWebToAutoCompleteAndroidMap[autoComplete] ??
|
|
1832
|
+
autoComplete
|
|
1833
|
+
: undefined
|
|
1834
|
+
}
|
|
1835
|
+
textContentType={
|
|
1836
|
+
Platform.OS === 'ios' &&
|
|
1837
|
+
autoComplete &&
|
|
1838
|
+
autoComplete in autoCompleteWebToTextContentTypeMap
|
|
1839
|
+
? // $FlowFixMe
|
|
1840
|
+
autoCompleteWebToTextContentTypeMap[autoComplete]
|
|
1841
|
+
: textContentType
|
|
1842
|
+
}
|
|
1843
|
+
{...restProps}
|
|
1844
|
+
forwardedRef={forwardedRef}
|
|
1845
|
+
style={style}
|
|
1846
|
+
/>
|
|
1847
|
+
);
|
|
1848
|
+
});
|
|
1849
|
+
|
|
1850
|
+
ExportedForwardRef.displayName = 'TextInput';
|
|
1851
|
+
|
|
1852
|
+
/**
|
|
1853
|
+
* Switch to `deprecated-react-native-prop-types` for compatibility with future
|
|
1854
|
+
* releases. This is deprecated and will be removed in the future.
|
|
1855
|
+
*/
|
|
1856
|
+
ExportedForwardRef.propTypes =
|
|
1857
|
+
require('deprecated-react-native-prop-types').TextInputPropTypes;
|
|
1858
|
+
|
|
1859
|
+
// $FlowFixMe[prop-missing]
|
|
1860
|
+
ExportedForwardRef.State = {
|
|
1861
|
+
currentlyFocusedInput: TextInputState.currentlyFocusedInput,
|
|
1862
|
+
|
|
1863
|
+
currentlyFocusedField: TextInputState.currentlyFocusedField,
|
|
1864
|
+
focusTextInput: TextInputState.focusTextInput,
|
|
1865
|
+
blurTextInput: TextInputState.blurTextInput,
|
|
1866
|
+
};
|
|
1867
|
+
|
|
1868
|
+
export type TextInputComponentStatics = $ReadOnly<{|
|
|
1869
|
+
State: $ReadOnly<{|
|
|
1870
|
+
currentlyFocusedInput: typeof TextInputState.currentlyFocusedInput,
|
|
1871
|
+
currentlyFocusedField: typeof TextInputState.currentlyFocusedField,
|
|
1872
|
+
focusTextInput: typeof TextInputState.focusTextInput,
|
|
1873
|
+
blurTextInput: typeof TextInputState.blurTextInput,
|
|
1874
|
+
|}>,
|
|
1875
|
+
|}>;
|
|
1876
|
+
|
|
1877
|
+
const styles = StyleSheet.create({
|
|
1878
|
+
multilineInput: {
|
|
1879
|
+
// This default top inset makes RCTMultilineTextInputView seem as close as possible
|
|
1880
|
+
// to single-line RCTSinglelineTextInputView defaults, using the system defaults
|
|
1881
|
+
// of font size 17 and a height of 31 points.
|
|
1882
|
+
paddingTop: 5,
|
|
1883
|
+
},
|
|
1884
|
+
});
|
|
1885
|
+
|
|
1886
|
+
const verticalAlignToTextAlignVerticalMap = {
|
|
1887
|
+
auto: 'auto',
|
|
1888
|
+
top: 'top',
|
|
1889
|
+
bottom: 'bottom',
|
|
1890
|
+
middle: 'center',
|
|
1891
|
+
};
|
|
1146
1892
|
|
|
1147
|
-
|
|
1893
|
+
// $FlowFixMe[unclear-type] Unclear type. Using `any` type is not safe.
|
|
1894
|
+
module.exports = ((ExportedForwardRef: any): TextInputType);
|