@office-iss/react-native-win32 0.71.5 → 0.72.0-preview.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.flowconfig +15 -3
- package/CHANGELOG.json +302 -47
- package/CHANGELOG.md +141 -27
- package/IntegrationTests/IntegrationTestHarnessTest.js +1 -0
- package/Libraries/ActionSheetIOS/ActionSheetIOS.js +1 -1
- package/Libraries/Alert/Alert.d.ts +4 -4
- package/Libraries/Alert/Alert.win32.js +1 -0
- package/Libraries/Animated/Animated.d.ts +17 -6
- package/Libraries/Animated/NativeAnimatedHelper.js +18 -6
- package/Libraries/Animated/NativeAnimatedHelper.win32.js +606 -0
- package/Libraries/Animated/bezier.js +1 -1
- package/Libraries/Animated/components/AnimatedFlatList.js +8 -3
- package/Libraries/Animated/components/AnimatedScrollView.js +4 -1
- package/Libraries/Animated/components/AnimatedSectionList.js +12 -3
- package/Libraries/Animated/createAnimatedComponent.js +26 -239
- package/Libraries/Animated/nodes/AnimatedColor.js +47 -80
- package/Libraries/Animated/nodes/AnimatedInterpolation.js +167 -121
- package/Libraries/Animated/nodes/AnimatedNode.js +3 -5
- package/Libraries/Animated/nodes/AnimatedProps.js +7 -6
- package/Libraries/Animated/nodes/AnimatedStyle.js +42 -8
- package/Libraries/Animated/nodes/AnimatedTransform.js +1 -1
- package/Libraries/Animated/nodes/AnimatedValue.js +8 -12
- package/Libraries/Animated/nodes/AnimatedWithChildren.js +1 -1
- package/Libraries/Animated/useAnimatedProps.js +7 -10
- package/Libraries/BatchedBridge/MessageQueue.js +2 -1
- package/Libraries/BatchedBridge/NativeModules.d.ts +1 -1
- package/Libraries/BatchedBridge/NativeModules.js +1 -0
- package/Libraries/Blob/Blob.js +4 -0
- package/Libraries/Blob/FileReader.js +30 -2
- package/Libraries/Blob/URL.js +3 -1
- package/Libraries/Components/AccessibilityInfo/AccessibilityInfo.d.ts +2 -2
- package/Libraries/Components/AccessibilityInfo/AccessibilityInfo.js +2 -3
- package/Libraries/Components/AccessibilityInfo/AccessibilityInfo.win32.js +2 -3
- package/Libraries/Components/ActivityIndicator/ActivityIndicator.js +6 -4
- package/Libraries/Components/Button.js +3 -2
- package/Libraries/Components/Button.win32.js +451 -0
- package/Libraries/Components/Clipboard/Clipboard.js +1 -1
- package/Libraries/Components/DrawerAndroid/DrawerLayoutAndroid.android.js +4 -0
- package/Libraries/Components/Keyboard/KeyboardAvoidingView.js +1 -0
- package/Libraries/Components/Pressable/Pressable.d.ts +1 -1
- package/Libraries/Components/Pressable/Pressable.js +1 -1
- package/Libraries/Components/RefreshControl/RefreshControl.js +1 -0
- package/Libraries/Components/SafeAreaView/SafeAreaView.js +1 -2
- package/Libraries/Components/SafeAreaView/SafeAreaView.win32.js +1 -2
- package/Libraries/Components/ScrollView/AndroidHorizontalScrollViewNativeComponent.js +12 -6
- package/Libraries/Components/ScrollView/ScrollView.d.ts +2 -2
- package/Libraries/Components/ScrollView/ScrollView.js +149 -91
- package/Libraries/Components/ScrollView/ScrollView.win32.js +1939 -0
- package/Libraries/Components/ScrollView/ScrollViewNativeComponent.js +16 -6
- package/Libraries/Components/ScrollView/ScrollViewStickyHeader.js +5 -7
- package/Libraries/Components/ScrollView/ScrollViewViewConfig.js +1 -1
- package/Libraries/Components/StatusBar/StatusBar.js +3 -0
- package/Libraries/Components/Switch/Switch.js +3 -1
- package/Libraries/Components/TextInput/AndroidTextInputNativeComponent.js +21 -11
- package/Libraries/Components/TextInput/InputAccessoryView.d.ts +1 -1
- package/Libraries/Components/TextInput/RCTTextInputViewConfig.js +11 -5
- package/Libraries/Components/TextInput/TextInput.Types.win32.d.ts +51 -0
- package/Libraries/Components/TextInput/TextInput.Types.win32.js +3 -0
- package/Libraries/Components/TextInput/TextInput.Types.win32.js.map +1 -0
- package/Libraries/Components/TextInput/TextInput.d.ts +15 -5
- package/Libraries/Components/TextInput/TextInput.flow.js +1 -1
- package/Libraries/Components/TextInput/TextInput.js +130 -103
- package/Libraries/Components/TextInput/TextInput.win32.js +202 -890
- package/Libraries/Components/Touchable/Touchable.d.ts +1 -1
- package/Libraries/Components/Touchable/Touchable.flow.js +30 -4
- package/Libraries/Components/Touchable/Touchable.js +6 -3
- package/Libraries/Components/Touchable/Touchable.win32.js +6 -3
- package/Libraries/Components/Touchable/TouchableHighlight.js +1 -1
- package/Libraries/Components/Touchable/TouchableNativeFeedback.js +2 -2
- package/Libraries/Components/Touchable/TouchableOpacity.js +3 -0
- package/Libraries/Components/Touchable/TouchableWithoutFeedback.d.ts +1 -1
- package/Libraries/Components/Touchable/TouchableWithoutFeedback.js +2 -2
- package/Libraries/Components/TraceUpdateOverlay/TraceUpdateOverlay.js +189 -0
- package/Libraries/Components/TraceUpdateOverlay/TraceUpdateOverlayNativeComponent.js +43 -0
- package/Libraries/Components/View/ReactNativeStyleAttributes.js +26 -0
- package/Libraries/Components/View/View.js +71 -45
- package/Libraries/Components/View/View.win32.js +38 -16
- package/Libraries/Components/View/ViewAccessibility.d.ts +6 -6
- package/Libraries/Components/View/ViewAccessibility.js +10 -1
- package/Libraries/Components/View/ViewAccessibility.win32.d.ts +5 -5
- package/Libraries/Components/View/ViewNativeComponent.js +32 -8
- package/Libraries/Components/View/ViewPropTypes.d.ts +1 -1
- package/Libraries/Components/View/ViewPropTypes.js +1 -1
- package/Libraries/Components/View/ViewPropTypes.win32.d.ts +1 -1
- package/Libraries/Components/View/ViewPropTypes.win32.js +1 -1
- package/Libraries/Components/View/ViewWin32.js +3 -3
- package/Libraries/Core/Devtools/openFileInEditor.js +1 -0
- package/Libraries/Core/Devtools/openURLInBrowser.js +1 -0
- package/Libraries/Core/Devtools/parseErrorStack.js +2 -2
- package/Libraries/Core/Devtools/parseHermesStack.js +54 -34
- package/Libraries/Core/ExceptionsManager.js +2 -2
- package/Libraries/Core/InitializeCore.js +2 -1
- package/Libraries/Core/ReactNativeVersion.js +3 -3
- package/Libraries/Core/ReactNativeVersionCheck.js +1 -9
- package/Libraries/Core/ReactNativeVersionCheck.win32.js +1 -9
- package/Libraries/Core/Timers/JSTimers.js +1 -1
- package/Libraries/Core/Timers/immediateShim.js +1 -0
- package/Libraries/Core/Timers/queueMicrotask.js +1 -1
- package/Libraries/Core/setUpAlert.js +1 -1
- package/Libraries/Core/setUpDOM.js +18 -0
- package/Libraries/Core/setUpDeveloperTools.js +1 -1
- package/Libraries/Core/setUpGlobals.js +5 -2
- package/Libraries/Core/setUpNavigator.js +6 -5
- package/Libraries/Core/setUpPerformance.js +23 -13
- package/Libraries/Core/setUpReactDevTools.js +2 -0
- package/Libraries/Core/setUpSegmentFetcher.js +0 -41
- package/Libraries/Core/setUpTimers.js +2 -2
- package/Libraries/DOM/Geometry/DOMRect.js +82 -0
- package/Libraries/DOM/Geometry/DOMRectReadOnly.js +188 -0
- package/Libraries/DOM/Nodes/ReactNativeElement.js +75 -0
- package/Libraries/DOM/Nodes/ReadOnlyElement.js +89 -0
- package/Libraries/DOM/Nodes/ReadOnlyNode.js +167 -0
- package/Libraries/DOM/OldStyleCollections/ArrayLikeUtils.js +46 -0
- package/Libraries/DOM/OldStyleCollections/DOMRectList.js +76 -0
- package/Libraries/DOM/OldStyleCollections/HTMLCollection.js +82 -0
- package/Libraries/DOM/OldStyleCollections/NodeList.js +104 -0
- package/Libraries/DevToolsSettings/DevToolsSettingsManager.android.js +35 -0
- package/Libraries/DevToolsSettings/DevToolsSettingsManager.d.ts +20 -0
- package/Libraries/DevToolsSettings/DevToolsSettingsManager.ios.js +49 -0
- package/Libraries/DevToolsSettings/DevToolsSettingsManager.win32.js +35 -0
- package/Libraries/{Utilities/NativeDevSplitBundleLoader.js → DevToolsSettings/NativeDevToolsSettingsManager.js} +7 -2
- package/Libraries/EventEmitter/NativeEventEmitter.d.ts +1 -2
- package/Libraries/EventEmitter/RCTDeviceEventEmitter.d.ts +1 -2
- package/Libraries/EventEmitter/RCTDeviceEventEmitter.js +9 -1
- package/Libraries/Events/EventPolyfill.js +1 -1
- package/Libraries/Image/AssetRegistry.js +1 -1
- package/Libraries/Image/AssetSourceResolver.js +3 -3
- package/Libraries/Image/Image.android.js +4 -1
- package/Libraries/Image/Image.d.ts +63 -2
- package/Libraries/Image/Image.ios.js +3 -0
- package/Libraries/Image/Image.win32.js +3 -0
- package/Libraries/Image/ImageBackground.js +1 -0
- package/Libraries/Image/ImageProps.js +1 -1
- package/Libraries/Image/ImageViewNativeComponent.js +4 -4
- package/Libraries/Image/RelativeImageStub.js +1 -1
- package/Libraries/Image/TextInlineImageNativeComponent.js +1 -1
- package/Libraries/Image/resolveAssetSource.js +1 -1
- package/Libraries/Inspector/DevtoolsOverlay.js +29 -19
- package/Libraries/Inspector/ElementBox.js +4 -1
- package/Libraries/Inspector/Inspector.js +5 -6
- package/Libraries/Inspector/Inspector.win32.js +7 -6
- package/Libraries/Inspector/InspectorOverlay.js +3 -3
- package/Libraries/Inspector/InspectorOverlay.win32.js +2 -1
- package/Libraries/Inspector/NetworkOverlay.js +1 -1
- package/Libraries/Interaction/JSEventLoopWatchdog.js +1 -1
- package/Libraries/Interaction/PanResponder.js +5 -6
- package/Libraries/LayoutAnimation/LayoutAnimation.js +2 -1
- package/Libraries/Linking/Linking.js +1 -4
- package/Libraries/Lists/FillRateHelper.js +4 -238
- package/Libraries/Lists/FlatList.d.ts +15 -22
- package/Libraries/Lists/FlatList.js +9 -6
- package/Libraries/Lists/SectionList.d.ts +10 -6
- package/Libraries/Lists/SectionList.js +5 -3
- package/Libraries/Lists/SectionListModern.js +3 -3
- package/Libraries/Lists/ViewabilityHelper.js +8 -344
- package/Libraries/Lists/VirtualizeUtils.js +4 -244
- package/Libraries/Lists/VirtualizedList.js +10 -1867
- package/Libraries/Lists/VirtualizedListContext.js +6 -104
- package/Libraries/Lists/VirtualizedSectionList.js +9 -602
- package/Libraries/Lists/__flowtests__/FlatList-flowtest.js +1 -0
- package/Libraries/Lists/__flowtests__/SectionList-flowtest.js +1 -1
- package/Libraries/LogBox/Data/LogBoxData.js +1 -1
- package/Libraries/LogBox/Data/parseLogBoxLog.js +1 -1
- package/Libraries/LogBox/LogBox.js +1 -1
- package/Libraries/LogBox/UI/LogBoxInspector.js +1 -3
- package/Libraries/LogBox/UI/LogBoxInspectorCodeFrame.win32.js +168 -0
- package/Libraries/LogBox/UI/LogBoxInspectorHeader.win32.js +3 -0
- package/Libraries/LogBox/UI/LogBoxInspectorReactFrames.win32.js +193 -0
- package/Libraries/LogBox/UI/LogBoxInspectorSourceMapStatus.js +1 -0
- package/Libraries/LogBox/UI/LogBoxInspectorStackFrame.js +2 -2
- package/Libraries/LogBox/UI/LogBoxInspectorStackFrame.win32.js +7 -3
- package/Libraries/LogBox/UI/LogBoxMessage.js +87 -5
- package/Libraries/LogBox/UI/LogBoxNotification.js +5 -7
- package/Libraries/Modal/Modal.js +2 -2
- package/Libraries/NativeComponent/BaseViewConfig.android.js +32 -12
- package/Libraries/NativeComponent/BaseViewConfig.ios.js +43 -19
- package/Libraries/NativeComponent/BaseViewConfig.win32.js +43 -19
- package/Libraries/NativeComponent/NativeComponentRegistryUnstable.js +4 -1
- package/Libraries/NativeComponent/ViewConfig.js +1 -0
- package/Libraries/NativeComponent/ViewConfigIgnore.js +1 -4
- package/Libraries/Network/RCTNetworking.android.js +2 -2
- package/Libraries/Network/RCTNetworking.ios.js +1 -1
- package/Libraries/Network/RCTNetworking.win32.js +1 -1
- package/Libraries/Network/XMLHttpRequest.js +1 -1
- package/Libraries/Pressability/Pressability.js +11 -5
- package/Libraries/Pressability/Pressability.win32.js +9 -3
- package/Libraries/ReactNative/AppContainer.js +7 -1
- package/Libraries/ReactNative/AppRegistry.d.ts +1 -1
- package/Libraries/ReactNative/AppRegistry.js +10 -13
- package/Libraries/ReactNative/FabricUIManager.js +24 -8
- package/Libraries/ReactNative/NativeUIManager.js +5 -5
- package/Libraries/ReactNative/ReactNativeFeatureFlags.js +10 -10
- package/Libraries/ReactNative/UIManager.js +142 -1
- package/Libraries/ReactNative/getCachedComponentWithDebugName.js +5 -5
- package/Libraries/ReactNative/getNativeComponentAttributes.js +1 -1
- package/Libraries/ReactNative/requireNativeComponent.d.ts +1 -1
- package/Libraries/ReactNative/requireNativeComponent.js +1 -1
- package/Libraries/ReactPrivate/ReactNativePrivateInterface.js +1 -0
- package/Libraries/Renderer/implementations/ReactFabric-dev.js +26 -3
- package/Libraries/Renderer/implementations/ReactFabric-prod.js +13 -1
- package/Libraries/Renderer/implementations/ReactFabric-profiling.js +13 -1
- package/Libraries/Renderer/public/ReactFabricPublicInstanceUtils.js +38 -0
- package/Libraries/Renderer/shims/ReactNativeTypes.js +38 -20
- package/Libraries/Renderer/shims/ReactNativeViewConfigRegistry.js +7 -7
- package/Libraries/Renderer/shims/createReactNativeComponentClass.js +2 -2
- package/Libraries/Share/Share.js +1 -1
- package/Libraries/StyleSheet/PlatformColorValueTypes.ios.js +1 -1
- package/Libraries/StyleSheet/StyleSheet.js +1 -1
- package/Libraries/StyleSheet/StyleSheet.win32.js +1 -1
- package/Libraries/StyleSheet/StyleSheetTypes.d.ts +115 -76
- package/Libraries/StyleSheet/StyleSheetTypes.js +188 -33
- package/Libraries/StyleSheet/flattenStyle.js +2 -0
- package/Libraries/StyleSheet/normalizeColor.js +1 -1
- package/Libraries/StyleSheet/processColor.js +1 -1
- package/Libraries/Text/Text.d.ts +12 -2
- package/Libraries/Text/Text.js +50 -41
- package/Libraries/Text/TextProps.js +3 -4
- package/Libraries/TurboModule/samples/NativeSampleTurboModule.js +6 -0
- package/Libraries/Types/CodegenTypes.js +1 -0
- package/Libraries/UTFSequence.js +3 -1
- package/Libraries/Utilities/Appearance.d.ts +10 -0
- package/Libraries/Utilities/Appearance.js +13 -0
- package/Libraries/Utilities/Dimensions.js +1 -1
- package/Libraries/Utilities/Dimensions.win32.js +1 -1
- package/Libraries/Utilities/GlobalPerformanceLogger.js +12 -1
- package/Libraries/Utilities/HMRClient.js +16 -10
- package/Libraries/Utilities/{createPerformanceLogger.d.ts → IPerformanceLogger.d.ts} +4 -4
- package/Libraries/Utilities/IPerformanceLogger.js +49 -0
- package/Libraries/Utilities/LoadingView.android.js +28 -11
- package/Libraries/Utilities/NativeAppearance.js +1 -0
- package/Libraries/Utilities/NativePlatformConstantsWin.js +1 -1
- package/Libraries/Utilities/PixelRatio.js +2 -2
- package/Libraries/Utilities/Platform.win32.js +1 -1
- package/Libraries/Utilities/ReactNativeTestTools.js +1 -1
- package/Libraries/Utilities/__mocks__/PixelRatio.js +1 -1
- package/Libraries/Utilities/codegenNativeCommands.js +2 -0
- package/Libraries/Utilities/createPerformanceLogger.js +55 -43
- package/Libraries/Utilities/stringifySafe.js +2 -7
- package/Libraries/Utilities/useColorScheme.js +1 -1
- package/Libraries/Utilities/useWindowDimensions.js +3 -3
- package/Libraries/WebPerformance/EventCounts.js +78 -0
- package/Libraries/WebPerformance/MemoryInfo.js +54 -0
- package/Libraries/WebPerformance/NativePerformance.js +38 -0
- package/Libraries/WebPerformance/NativePerformanceObserver.js +22 -7
- package/Libraries/WebPerformance/Performance.js +312 -0
- package/Libraries/WebPerformance/PerformanceEntry.js +45 -0
- package/Libraries/WebPerformance/PerformanceEventTiming.js +38 -0
- package/Libraries/WebPerformance/PerformanceObserver.js +196 -101
- package/Libraries/WebPerformance/RawPerformanceEntry.js +87 -0
- package/Libraries/WebPerformance/ReactNativeStartupTiming.js +65 -0
- package/Libraries/WebPerformance/__mocks__/NativePerformance.js +65 -0
- package/Libraries/WebPerformance/__mocks__/NativePerformanceObserver.js +101 -0
- package/Libraries/YellowBox/YellowBoxDeprecated.js +1 -1
- package/Libraries/vendor/core/ErrorUtils.js +1 -1
- package/Libraries/vendor/emitter/EventEmitter.d.ts +2 -2
- package/Libraries/vendor/emitter/EventEmitter.js +9 -1
- package/flow/global.js +29 -4
- package/flow/jest.js +258 -164
- package/index.js +56 -42
- package/index.win32.js +56 -42
- package/interface.js +1 -1
- package/jest/local-setup.js +33 -0
- package/jest/mockComponent.js +4 -2
- package/jest/mockNativeComponent.js +1 -1
- package/jest/mockScrollView.js +2 -1
- package/jest/react-native-env.js +1 -3
- package/jest/setup.js +11 -8
- package/overrides.json +115 -85
- package/package.json +38 -28
- package/rn-get-polyfills.js +1 -1
- package/src/Libraries/Components/TextInput/TextInput.Types.win32.ts +68 -0
- package/src/Libraries/Components/View/ViewAccessibility.win32.d.ts +5 -5
- package/src/Libraries/Components/View/ViewPropTypes.win32.d.ts +1 -1
- package/types/index.d.ts +2 -6
- package/types/modules/Codegen.d.ts +4 -4
- package/types/modules/globals.d.ts +27 -25
- package/types/public/DeprecatedPropertiesAlias.d.ts +0 -20
- package/types/public/ReactNativeRenderer.d.ts +2 -7
- package/Libraries/Animated/createAnimatedComponentInjection.js +0 -48
- package/Libraries/Animated/createAnimatedComponent_EXPERIMENTAL.js +0 -48
- package/Libraries/Components/AccessibilityInfo/AccessibilityInfo.flow.js +0 -208
- package/Libraries/Components/ActivityIndicator/ActivityIndicator.flow.js +0 -58
- package/Libraries/Components/DatePicker/DatePickerIOS.android.js +0 -47
- package/Libraries/Components/DatePicker/DatePickerIOS.d.ts +0 -92
- package/Libraries/Components/DatePicker/DatePickerIOS.flow.android.js +0 -14
- package/Libraries/Components/DatePicker/DatePickerIOS.flow.ios.js +0 -113
- package/Libraries/Components/DatePicker/DatePickerIOS.ios.js +0 -242
- package/Libraries/Components/DatePicker/DatePickerIOS.win32.js +0 -47
- package/Libraries/Components/DatePicker/RCTDatePickerNativeComponent.js +0 -60
- package/Libraries/Components/DatePickerAndroid/NativeDatePickerAndroid.js +0 -26
- package/Libraries/Components/ProgressViewIOS/ProgressViewIOS.android.js +0 -45
- package/Libraries/Components/ProgressViewIOS/ProgressViewIOS.d.ts +0 -62
- package/Libraries/Components/ProgressViewIOS/ProgressViewIOS.ios.js +0 -75
- package/Libraries/Components/ProgressViewIOS/ProgressViewIOS.win32.js +0 -45
- package/Libraries/Components/ProgressViewIOS/RCTProgressViewNativeComponent.js +0 -33
- package/Libraries/Components/SafeAreaView/SafeAreaView.flow.js +0 -19
- package/Libraries/Components/Slider/Slider.d.ts +0 -132
- package/Libraries/Components/Slider/Slider.js +0 -282
- package/Libraries/Components/Slider/SliderNativeComponent.js +0 -56
- package/Libraries/Components/TextInput/Win32TextInputNativeComponent.js +0 -23
- package/Libraries/Interaction/Batchinator.js +0 -76
- package/Libraries/Interaction/BridgeSpyStallHandler.js +0 -63
- package/Libraries/Interaction/InteractionStallDebugger.js +0 -23
- package/Libraries/Interaction/PanResponder.flow.js +0 -257
- package/Libraries/Lists/CellRenderMask.js +0 -155
- package/Libraries/Lists/ChildListCollection.js +0 -72
- package/Libraries/Lists/StateSafePureComponent.js +0 -85
- package/Libraries/Lists/VirtualizedList.d.ts +0 -347
- package/Libraries/Lists/VirtualizedListCellRenderer.js +0 -259
- package/Libraries/Lists/VirtualizedListProps.js +0 -279
- package/Libraries/Performance/PureComponentDebug.js +0 -74
- package/Libraries/Reliability/UserFlow.js +0 -158
- package/Libraries/Renderer/implementations/ReactNativeRenderer.d.ts +0 -149
- package/Libraries/Renderer/shims/ReactNativeTypes.d.ts +0 -141
- package/Libraries/Utilities/MatrixMath.js +0 -748
- package/Libraries/Utilities/buildStyleInterpolator.js +0 -209
- package/Libraries/Utilities/clamp.js +0 -23
- package/Libraries/Utilities/deprecatedPropType.js +0 -36
- package/Libraries/Utilities/groupByEveryN.js +0 -51
- package/Libraries/Utilities/mergeIntoFast.js +0 -26
- package/Libraries/Utilities/setAndForwardRef.js +0 -71
- package/Libraries/Utilities/truncate.js +0 -51
- package/flow/JSITimerInternalType.js +0 -30
- package/flow/use-sync-external-store.js +0 -19
|
@@ -1,38 +1,44 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* This is a forked and slightly modified version of React Native's TextInput.
|
|
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.
|
|
3
6
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
7
|
+
* More general documentation on this control can be found at
|
|
8
|
+
* https://facebook.github.io/react-native/docs/textinput.html
|
|
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
|
|
6
19
|
*
|
|
7
20
|
* @flow strict-local
|
|
8
21
|
* @format
|
|
9
22
|
*/
|
|
10
23
|
|
|
11
24
|
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';
|
|
12
32
|
import type {
|
|
13
33
|
PressEvent,
|
|
14
34
|
ScrollEvent,
|
|
15
35
|
SyntheticEvent,
|
|
16
36
|
} 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';
|
|
22
37
|
import StyleSheet, {
|
|
23
38
|
type ColorValue,
|
|
24
39
|
type TextStyleProp,
|
|
25
40
|
type ViewStyleProp,
|
|
26
41
|
} 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';
|
|
36
42
|
|
|
37
43
|
type ReactRefSetter<T> = {current: null | T, ...} | ((ref: null | T) => mixed);
|
|
38
44
|
type TextInputInstance = React.ElementRef<HostComponent<mixed>> & {
|
|
@@ -42,39 +48,6 @@ type TextInputInstance = React.ElementRef<HostComponent<mixed>> & {
|
|
|
42
48
|
+setSelection: (start: number, end: number) => void,
|
|
43
49
|
};
|
|
44
50
|
|
|
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
|
-
|
|
78
51
|
export type ChangeEvent = SyntheticEvent<
|
|
79
52
|
$ReadOnly<{|
|
|
80
53
|
eventCount: number,
|
|
@@ -365,9 +338,6 @@ type IOSProps = $ReadOnly<{|
|
|
|
365
338
|
/**
|
|
366
339
|
* Give the keyboard and the system information about the
|
|
367
340
|
* expected semantic meaning for the content that users enter.
|
|
368
|
-
* `autoComplete` property accomplishes same behavior and is recommended as its supported by both platforms.
|
|
369
|
-
* Avoid using both `autoComplete` and `textContentType`, you can use `Platform.select` for differing platform behaviors.
|
|
370
|
-
* For backwards compatibility, when both set, `textContentType` takes precedence on iOS.
|
|
371
341
|
* @platform ios
|
|
372
342
|
*/
|
|
373
343
|
textContentType?: ?TextContentType,
|
|
@@ -570,37 +540,18 @@ type AndroidProps = $ReadOnly<{|
|
|
|
570
540
|
underlineColorAndroid?: ?ColorValue,
|
|
571
541
|
|}>;
|
|
572
542
|
|
|
573
|
-
// [Windows
|
|
574
|
-
|
|
575
|
-
type SubmitKeyEvent = $ReadOnly<{|
|
|
576
|
-
altKey?: ?boolean,
|
|
577
|
-
ctrlKey?: ?boolean,
|
|
578
|
-
metaKey?: ?boolean,
|
|
579
|
-
shiftKey?: ?boolean,
|
|
580
|
-
code: string,
|
|
581
|
-
|}>;
|
|
582
|
-
|
|
583
|
-
type WindowsProps = $ReadOnly<{|
|
|
584
|
-
/**
|
|
585
|
-
* If `true`, clears the text field synchronously before `onSubmitEditing` is emitted.
|
|
586
|
-
* @platform windows
|
|
587
|
-
*/
|
|
588
|
-
clearTextOnSubmit?: ?boolean,
|
|
589
|
-
|
|
590
|
-
/**
|
|
591
|
-
* Configures keys that can be used to submit editing for the TextInput.
|
|
592
|
-
* @platform windows
|
|
593
|
-
*/
|
|
594
|
-
submitKeyEvents?: ?$ReadOnlyArray<SubmitKeyEvent>,
|
|
595
|
-
|}>;
|
|
596
|
-
|
|
597
|
-
// Windows]
|
|
598
|
-
|
|
599
543
|
export type Props = $ReadOnly<{|
|
|
600
544
|
...$Diff<ViewProps, $ReadOnly<{|style: ?ViewStyleProp|}>>,
|
|
601
545
|
...IOSProps,
|
|
602
546
|
...AndroidProps,
|
|
603
|
-
|
|
547
|
+
|
|
548
|
+
/**
|
|
549
|
+
* String to be read by screenreaders to indicate an error state. The acceptable parameters
|
|
550
|
+
* of accessibilityErrorMessage is a string. Setting accessibilityInvalid to true activates
|
|
551
|
+
* the error message. Setting accessibilityInvalid to false removes the error message.
|
|
552
|
+
*/
|
|
553
|
+
accessibilityErrorMessage?: ?Stringish,
|
|
554
|
+
accessibilityInvalid?: ?boolean,
|
|
604
555
|
|
|
605
556
|
/**
|
|
606
557
|
* Can tell `TextInput` to automatically capitalize certain characters.
|
|
@@ -993,854 +944,215 @@ export type Props = $ReadOnly<{|
|
|
|
993
944
|
* unwanted edits without flicker.
|
|
994
945
|
*/
|
|
995
946
|
value?: ?Stringish,
|
|
947
|
+
|
|
948
|
+
text?: ?Stringish, // Win32
|
|
996
949
|
|}>;
|
|
997
950
|
|
|
998
|
-
|
|
951
|
+
/*
|
|
952
|
+
import {
|
|
953
|
+
TextInputProps,
|
|
954
|
+
NativeMethods,
|
|
955
|
+
} from 'react-native';
|
|
956
|
+
import {
|
|
957
|
+
IBlurEvent,
|
|
958
|
+
IChangeEvent,
|
|
959
|
+
IFocusEvent,
|
|
960
|
+
} from './TextInput.Types.win32';
|
|
961
|
+
import React from 'react'
|
|
962
|
+
|
|
963
|
+
type RCTTextInputProps = TextInputProps & {
|
|
964
|
+
text: string;
|
|
965
|
+
};
|
|
966
|
+
*/
|
|
999
967
|
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
* keyboard. Props provide configurability for several features, such as
|
|
1003
|
-
* auto-correction, auto-capitalization, placeholder text, and different keyboard
|
|
1004
|
-
* types, such as a numeric keypad.
|
|
1005
|
-
*
|
|
1006
|
-
* The simplest use case is to plop down a `TextInput` and subscribe to the
|
|
1007
|
-
* `onChangeText` events to read the user input. There are also other events,
|
|
1008
|
-
* such as `onSubmitEditing` and `onFocus` that can be subscribed to. A simple
|
|
1009
|
-
* example:
|
|
1010
|
-
*
|
|
1011
|
-
* ```ReactNativeWebPlayer
|
|
1012
|
-
* import React, { Component } from 'react';
|
|
1013
|
-
* import { AppRegistry, TextInput } from 'react-native';
|
|
1014
|
-
*
|
|
1015
|
-
* export default class UselessTextInput extends Component {
|
|
1016
|
-
* constructor(props) {
|
|
1017
|
-
* super(props);
|
|
1018
|
-
* this.state = { text: 'Useless Placeholder' };
|
|
1019
|
-
* }
|
|
1020
|
-
*
|
|
1021
|
-
* render() {
|
|
1022
|
-
* return (
|
|
1023
|
-
* <TextInput
|
|
1024
|
-
* style={{height: 40, borderColor: 'gray', borderWidth: 1}}
|
|
1025
|
-
* onChangeText={(text) => this.setState({text})}
|
|
1026
|
-
* value={this.state.text}
|
|
1027
|
-
* />
|
|
1028
|
-
* );
|
|
1029
|
-
* }
|
|
1030
|
-
* }
|
|
1031
|
-
*
|
|
1032
|
-
* // skip this line if using Create React Native App
|
|
1033
|
-
* AppRegistry.registerComponent('AwesomeProject', () => UselessTextInput);
|
|
1034
|
-
* ```
|
|
1035
|
-
*
|
|
1036
|
-
* Two methods exposed via the native element are .focus() and .blur() that
|
|
1037
|
-
* will focus or blur the TextInput programmatically.
|
|
1038
|
-
*
|
|
1039
|
-
* Note that some props are only available with `multiline={true/false}`.
|
|
1040
|
-
* Additionally, border styles that apply to only one side of the element
|
|
1041
|
-
* (e.g., `borderBottomColor`, `borderLeftWidth`, etc.) will not be applied if
|
|
1042
|
-
* `multiline=false`. To achieve the same effect, you can wrap your `TextInput`
|
|
1043
|
-
* in a `View`:
|
|
1044
|
-
*
|
|
1045
|
-
* ```ReactNativeWebPlayer
|
|
1046
|
-
* import React, { Component } from 'react';
|
|
1047
|
-
* import { AppRegistry, View, TextInput } from 'react-native';
|
|
1048
|
-
*
|
|
1049
|
-
* class UselessTextInput extends Component {
|
|
1050
|
-
* render() {
|
|
1051
|
-
* return (
|
|
1052
|
-
* <TextInput
|
|
1053
|
-
* {...this.props} // Inherit any props passed to it; e.g., multiline, numberOfLines below
|
|
1054
|
-
* editable = {true}
|
|
1055
|
-
* maxLength = {40}
|
|
1056
|
-
* />
|
|
1057
|
-
* );
|
|
1058
|
-
* }
|
|
1059
|
-
* }
|
|
1060
|
-
*
|
|
1061
|
-
* export default class UselessTextInputMultiline extends Component {
|
|
1062
|
-
* constructor(props) {
|
|
1063
|
-
* super(props);
|
|
1064
|
-
* this.state = {
|
|
1065
|
-
* text: 'Useless Multiline Placeholder',
|
|
1066
|
-
* };
|
|
1067
|
-
* }
|
|
1068
|
-
*
|
|
1069
|
-
* // If you type something in the text box that is a color, the background will change to that
|
|
1070
|
-
* // color.
|
|
1071
|
-
* render() {
|
|
1072
|
-
* return (
|
|
1073
|
-
* <View style={{
|
|
1074
|
-
* backgroundColor: this.state.text,
|
|
1075
|
-
* borderBottomColor: '#000000',
|
|
1076
|
-
* borderBottomWidth: 1 }}
|
|
1077
|
-
* >
|
|
1078
|
-
* <UselessTextInput
|
|
1079
|
-
* multiline = {true}
|
|
1080
|
-
* numberOfLines = {4}
|
|
1081
|
-
* onChangeText={(text) => this.setState({text})}
|
|
1082
|
-
* value={this.state.text}
|
|
1083
|
-
* />
|
|
1084
|
-
* </View>
|
|
1085
|
-
* );
|
|
1086
|
-
* }
|
|
1087
|
-
* }
|
|
1088
|
-
*
|
|
1089
|
-
* // skip these lines if using Create React Native App
|
|
1090
|
-
* AppRegistry.registerComponent(
|
|
1091
|
-
* 'AwesomeProject',
|
|
1092
|
-
* () => UselessTextInputMultiline
|
|
1093
|
-
* );
|
|
1094
|
-
* ```
|
|
1095
|
-
*
|
|
1096
|
-
* `TextInput` has by default a border at the bottom of its view. This border
|
|
1097
|
-
* has its padding set by the background image provided by the system, and it
|
|
1098
|
-
* cannot be changed. Solutions to avoid this is to either not set height
|
|
1099
|
-
* explicitly, case in which the system will take care of displaying the border
|
|
1100
|
-
* in the correct position, or to not display the border by setting
|
|
1101
|
-
* `underlineColorAndroid` to transparent.
|
|
1102
|
-
*
|
|
1103
|
-
* Note that on Android performing text selection in input can change
|
|
1104
|
-
* app's activity `windowSoftInputMode` param to `adjustResize`.
|
|
1105
|
-
* This may cause issues with components that have position: 'absolute'
|
|
1106
|
-
* while keyboard is active. To avoid this behavior either specify `windowSoftInputMode`
|
|
1107
|
-
* in AndroidManifest.xml ( https://developer.android.com/guide/topics/manifest/activity-element.html )
|
|
1108
|
-
* or control this param programmatically with native code.
|
|
1109
|
-
*
|
|
1110
|
-
*/
|
|
1111
|
-
function InternalTextInput(props: Props): React.Node {
|
|
1112
|
-
const {
|
|
1113
|
-
'aria-busy': ariaBusy,
|
|
1114
|
-
'aria-checked': ariaChecked,
|
|
1115
|
-
'aria-disabled': ariaDisabled,
|
|
1116
|
-
'aria-expanded': ariaExpanded,
|
|
1117
|
-
'aria-selected': ariaSelected,
|
|
1118
|
-
accessibilityState,
|
|
1119
|
-
id,
|
|
1120
|
-
tabIndex,
|
|
1121
|
-
...otherProps
|
|
1122
|
-
} = props;
|
|
1123
|
-
|
|
1124
|
-
const inputRef = useRef<null | React.ElementRef<HostComponent<mixed>>>(null);
|
|
1125
|
-
|
|
1126
|
-
// Android sends a "onTextChanged" event followed by a "onSelectionChanged" event, for
|
|
1127
|
-
// the same "most recent event count".
|
|
1128
|
-
// For controlled selection, that means that immediately after text is updated,
|
|
1129
|
-
// a controlled component will pass in the *previous* selection, even if the controlled
|
|
1130
|
-
// component didn't mean to modify the selection at all.
|
|
1131
|
-
// Therefore, we ignore selections and pass them through until the selection event has
|
|
1132
|
-
// been sent.
|
|
1133
|
-
// Note that this mitigation is NOT needed for Fabric.
|
|
1134
|
-
// discovered when upgrading react-hooks
|
|
1135
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
1136
|
-
let selection: ?Selection =
|
|
1137
|
-
props.selection == null
|
|
1138
|
-
? null
|
|
1139
|
-
: {
|
|
1140
|
-
start: props.selection.start,
|
|
1141
|
-
end: props.selection.end ?? props.selection.start,
|
|
1142
|
-
};
|
|
1143
|
-
|
|
1144
|
-
const [mostRecentEventCount, setMostRecentEventCount] = useState<number>(0);
|
|
1145
|
-
|
|
1146
|
-
const [lastNativeText, setLastNativeText] = useState<?Stringish>(props.value);
|
|
1147
|
-
const [lastNativeSelectionState, setLastNativeSelection] = useState<{|
|
|
1148
|
-
selection: ?Selection,
|
|
1149
|
-
mostRecentEventCount: number,
|
|
1150
|
-
|}>({selection, mostRecentEventCount});
|
|
1151
|
-
|
|
1152
|
-
const lastNativeSelection = lastNativeSelectionState.selection;
|
|
1153
|
-
const lastNativeSelectionEventCount =
|
|
1154
|
-
lastNativeSelectionState.mostRecentEventCount;
|
|
1155
|
-
|
|
1156
|
-
if (lastNativeSelectionEventCount < mostRecentEventCount) {
|
|
1157
|
-
selection = null;
|
|
1158
|
-
}
|
|
968
|
+
// RCTTextInput is the native component that win32 understands
|
|
969
|
+
const RCTTextInput = requireNativeComponent<Props>('RCTTextInput');
|
|
1159
970
|
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
}
|
|
1164
|
-
// [Windows
|
|
1165
|
-
else if (WindowsTextInputCommands) {
|
|
1166
|
-
viewCommands = WindowsTextInputCommands;
|
|
1167
|
-
}
|
|
1168
|
-
// Windows]
|
|
1169
|
-
else {
|
|
1170
|
-
viewCommands =
|
|
1171
|
-
props.multiline === true
|
|
1172
|
-
? RCTMultilineTextInputNativeCommands
|
|
1173
|
-
: RCTSinglelineTextInputNativeCommands;
|
|
1174
|
-
}
|
|
971
|
+
// Adding typings on ViewManagers is problematic as available functionality is not known until
|
|
972
|
+
// registration at runtime and would require native and js to always be in sync.
|
|
973
|
+
const TextInputViewManager = UIManager.getViewManagerConfig('RCTTextInput');
|
|
1175
974
|
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
? props.defaultValue
|
|
1181
|
-
: '';
|
|
1182
|
-
|
|
1183
|
-
// This is necessary in case native updates the text and JS decides
|
|
1184
|
-
// that the update should be ignored and we should stick with the value
|
|
1185
|
-
// that we have in JS.
|
|
1186
|
-
useLayoutEffect(() => {
|
|
1187
|
-
const nativeUpdate: {text?: string, selection?: Selection} = {};
|
|
1188
|
-
|
|
1189
|
-
if (lastNativeText !== props.value && typeof props.value === 'string') {
|
|
1190
|
-
nativeUpdate.text = props.value;
|
|
1191
|
-
setLastNativeText(props.value);
|
|
1192
|
-
}
|
|
975
|
+
class TextInput extends React.Component<Props, {}> {
|
|
976
|
+
// TODO: Once the native side begins supporting programmatic selection
|
|
977
|
+
// this will become important for selection management
|
|
978
|
+
// private _lastNativeTextSelection: any;
|
|
1193
979
|
|
|
1194
|
-
|
|
1195
|
-
selection &&
|
|
1196
|
-
lastNativeSelection &&
|
|
1197
|
-
(lastNativeSelection.start !== selection.start ||
|
|
1198
|
-
lastNativeSelection.end !== selection.end)
|
|
1199
|
-
) {
|
|
1200
|
-
nativeUpdate.selection = selection;
|
|
1201
|
-
setLastNativeSelection({selection, mostRecentEventCount});
|
|
1202
|
-
}
|
|
980
|
+
_rafID: AnimationFrameID;
|
|
1203
981
|
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
}
|
|
982
|
+
_lastNativeText: ?Stringish;
|
|
983
|
+
_eventCount: number = 0;
|
|
1207
984
|
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
mostRecentEventCount,
|
|
1212
|
-
text,
|
|
1213
|
-
selection?.start ?? -1,
|
|
1214
|
-
selection?.end ?? -1,
|
|
1215
|
-
);
|
|
1216
|
-
}
|
|
1217
|
-
}, [
|
|
1218
|
-
mostRecentEventCount,
|
|
1219
|
-
inputRef,
|
|
1220
|
-
props.value,
|
|
1221
|
-
props.defaultValue,
|
|
1222
|
-
lastNativeText,
|
|
1223
|
-
selection,
|
|
1224
|
-
lastNativeSelection,
|
|
1225
|
-
text,
|
|
1226
|
-
viewCommands,
|
|
1227
|
-
]);
|
|
1228
|
-
|
|
1229
|
-
useLayoutEffect(() => {
|
|
1230
|
-
const inputRefValue = inputRef.current;
|
|
1231
|
-
|
|
1232
|
-
if (inputRefValue != null) {
|
|
1233
|
-
TextInputState.registerInput(inputRefValue);
|
|
1234
|
-
|
|
1235
|
-
return () => {
|
|
1236
|
-
TextInputState.unregisterInput(inputRefValue);
|
|
1237
|
-
|
|
1238
|
-
if (TextInputState.currentlyFocusedInput() === inputRefValue) {
|
|
1239
|
-
nullthrows(inputRefValue).blur();
|
|
1240
|
-
}
|
|
1241
|
-
};
|
|
1242
|
-
}
|
|
1243
|
-
}, [inputRef]);
|
|
1244
|
-
|
|
1245
|
-
const setLocalRef = useCallback(
|
|
1246
|
-
(instance: TextInputInstance | null) => {
|
|
1247
|
-
inputRef.current = instance;
|
|
1248
|
-
|
|
1249
|
-
/*
|
|
1250
|
-
Hi reader from the future. I'm sorry for this.
|
|
1251
|
-
|
|
1252
|
-
This is a hack. Ideally we would forwardRef to the underlying
|
|
1253
|
-
host component. However, since TextInput has it's own methods that can be
|
|
1254
|
-
called as well, if we used the standard forwardRef then these
|
|
1255
|
-
methods wouldn't be accessible and thus be a breaking change.
|
|
1256
|
-
|
|
1257
|
-
We have a couple of options of how to handle this:
|
|
1258
|
-
- Return a new ref with everything we methods from both. This is problematic
|
|
1259
|
-
because we need React to also know it is a host component which requires
|
|
1260
|
-
internals of the class implementation of the ref.
|
|
1261
|
-
- Break the API and have some other way to call one set of the methods or
|
|
1262
|
-
the other. This is our long term approach as we want to eventually
|
|
1263
|
-
get the methods on host components off the ref. So instead of calling
|
|
1264
|
-
ref.measure() you might call ReactNative.measure(ref). This would hopefully
|
|
1265
|
-
let the ref for TextInput then have the methods like `.clear`. Or we do it
|
|
1266
|
-
the other way and make it TextInput.clear(textInputRef) which would be fine
|
|
1267
|
-
too. Either way though is a breaking change that is longer term.
|
|
1268
|
-
- Mutate this ref. :( Gross, but accomplishes what we need in the meantime
|
|
1269
|
-
before we can get to the long term breaking change.
|
|
1270
|
-
*/
|
|
1271
|
-
if (instance != null) {
|
|
1272
|
-
// $FlowFixMe[incompatible-use] - See the explanation above.
|
|
1273
|
-
Object.assign(instance, {
|
|
1274
|
-
clear(): void {
|
|
1275
|
-
if (inputRef.current != null) {
|
|
1276
|
-
viewCommands.setTextAndSelection(
|
|
1277
|
-
inputRef.current,
|
|
1278
|
-
mostRecentEventCount,
|
|
1279
|
-
'',
|
|
1280
|
-
0,
|
|
1281
|
-
0,
|
|
1282
|
-
);
|
|
1283
|
-
}
|
|
1284
|
-
},
|
|
1285
|
-
// TODO: Fix this returning true on null === null, when no input is focused
|
|
1286
|
-
isFocused(): boolean {
|
|
1287
|
-
return TextInputState.currentlyFocusedInput() === inputRef.current;
|
|
1288
|
-
},
|
|
1289
|
-
getNativeRef(): ?React.ElementRef<HostComponent<mixed>> {
|
|
1290
|
-
return inputRef.current;
|
|
1291
|
-
},
|
|
1292
|
-
setSelection(start: number, end: number): void {
|
|
1293
|
-
if (inputRef.current != null) {
|
|
1294
|
-
viewCommands.setTextAndSelection(
|
|
1295
|
-
inputRef.current,
|
|
1296
|
-
mostRecentEventCount,
|
|
1297
|
-
null,
|
|
1298
|
-
start,
|
|
1299
|
-
end,
|
|
1300
|
-
);
|
|
1301
|
-
}
|
|
1302
|
-
},
|
|
1303
|
-
});
|
|
1304
|
-
}
|
|
1305
|
-
},
|
|
1306
|
-
[mostRecentEventCount, viewCommands],
|
|
1307
|
-
);
|
|
1308
|
-
|
|
1309
|
-
const ref = useMergeRefs<TextInputInstance | null>(
|
|
1310
|
-
setLocalRef,
|
|
1311
|
-
props.forwardedRef,
|
|
1312
|
-
);
|
|
1313
|
-
|
|
1314
|
-
const _onChange = (event: ChangeEvent) => {
|
|
1315
|
-
const currentText = event.nativeEvent.text;
|
|
1316
|
-
props.onChange && props.onChange(event);
|
|
1317
|
-
props.onChangeText && props.onChangeText(currentText);
|
|
1318
|
-
|
|
1319
|
-
if (inputRef.current == null) {
|
|
1320
|
-
// calling `props.onChange` or `props.onChangeText`
|
|
1321
|
-
// may clean up the input itself. Exits here.
|
|
1322
|
-
return;
|
|
1323
|
-
}
|
|
985
|
+
constructor(props: Props) {
|
|
986
|
+
super(props);
|
|
987
|
+
}
|
|
1324
988
|
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
};
|
|
989
|
+
/**
|
|
990
|
+
* On mount TextInput needs to register itself with TextInputState
|
|
991
|
+
* and conditionally request an animation frame for focus.
|
|
992
|
+
*/
|
|
993
|
+
componentDidMount() {
|
|
994
|
+
this._lastNativeText = this.props.value;
|
|
1332
995
|
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
props.unstable_onChangeSync && props.unstable_onChangeSync(event);
|
|
1336
|
-
props.unstable_onChangeTextSync &&
|
|
1337
|
-
props.unstable_onChangeTextSync(currentText);
|
|
996
|
+
// $FlowFixMe - // Win32
|
|
997
|
+
TextInputState.registerInput(this);
|
|
1338
998
|
|
|
1339
|
-
if (
|
|
1340
|
-
|
|
1341
|
-
// may clean up the input itself. Exits here.
|
|
1342
|
-
return;
|
|
999
|
+
if (this.props.autoFocus === true) {
|
|
1000
|
+
this._rafID = requestAnimationFrame(this.focus);
|
|
1343
1001
|
}
|
|
1002
|
+
}
|
|
1344
1003
|
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
const _onSelectionChange = (event: SelectionChangeEvent) => {
|
|
1354
|
-
props.onSelectionChange && props.onSelectionChange(event);
|
|
1355
|
-
|
|
1356
|
-
if (inputRef.current == null) {
|
|
1357
|
-
// calling `props.onSelectionChange`
|
|
1358
|
-
// may clean up the input itself. Exits here.
|
|
1359
|
-
return;
|
|
1004
|
+
/**
|
|
1005
|
+
* This is an unfortunate consequence of having controlled TextInputs.
|
|
1006
|
+
* Tree diffing reconciliation will not always send down text values
|
|
1007
|
+
* This sets text explicitly.
|
|
1008
|
+
*/
|
|
1009
|
+
componentDidUpdate() {
|
|
1010
|
+
if (this._lastNativeText !== this._getText()) {
|
|
1011
|
+
this._getText() && this.setNativeText(this._getText());
|
|
1360
1012
|
}
|
|
1361
1013
|
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
mostRecentEventCount,
|
|
1365
|
-
});
|
|
1366
|
-
};
|
|
1367
|
-
|
|
1368
|
-
const _onFocus = (event: FocusEvent) => {
|
|
1369
|
-
TextInputState.focusInput(inputRef.current);
|
|
1370
|
-
if (props.onFocus) {
|
|
1371
|
-
props.onFocus(event);
|
|
1372
|
-
}
|
|
1373
|
-
};
|
|
1014
|
+
return;
|
|
1015
|
+
}
|
|
1374
1016
|
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1017
|
+
/**
|
|
1018
|
+
* Pre-unmoun the TextInput should blur, unregister and clean up
|
|
1019
|
+
* the animation frame for focus (edge cases)
|
|
1020
|
+
*/
|
|
1021
|
+
componentWillUnmount() {
|
|
1022
|
+
// blur
|
|
1023
|
+
if (this.isFocused()) {
|
|
1024
|
+
this.blur();
|
|
1379
1025
|
}
|
|
1380
|
-
};
|
|
1381
|
-
|
|
1382
|
-
const _onScroll = (event: ScrollEvent) => {
|
|
1383
|
-
props.onScroll && props.onScroll(event);
|
|
1384
|
-
};
|
|
1385
1026
|
|
|
1386
|
-
|
|
1027
|
+
// unregister
|
|
1028
|
+
// $FlowFixMe - // Win32
|
|
1029
|
+
TextInputState.unregisterInput(this);
|
|
1387
1030
|
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
if (props.submitBehavior != null) {
|
|
1392
|
-
// `submitBehavior` is set explicitly
|
|
1393
|
-
if (!multiline && props.submitBehavior === 'newline') {
|
|
1394
|
-
// For single line text inputs, `'newline'` is not a valid option
|
|
1395
|
-
submitBehavior = 'blurAndSubmit';
|
|
1396
|
-
} else {
|
|
1397
|
-
submitBehavior = props.submitBehavior;
|
|
1398
|
-
}
|
|
1399
|
-
} else if (multiline) {
|
|
1400
|
-
if (props.blurOnSubmit === true) {
|
|
1401
|
-
submitBehavior = 'blurAndSubmit';
|
|
1402
|
-
} else {
|
|
1403
|
-
submitBehavior = 'newline';
|
|
1031
|
+
// cancel animationFrame
|
|
1032
|
+
if (this._rafID !== null) {
|
|
1033
|
+
cancelAnimationFrame(this._rafID);
|
|
1404
1034
|
}
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
if (props.blurOnSubmit !== false) {
|
|
1408
|
-
submitBehavior = 'blurAndSubmit';
|
|
1409
|
-
} else {
|
|
1410
|
-
submitBehavior = 'submit';
|
|
1035
|
+
if (this._rafID) {
|
|
1036
|
+
return;
|
|
1411
1037
|
}
|
|
1038
|
+
return;
|
|
1412
1039
|
}
|
|
1413
1040
|
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
props.rejectResponderTermination,
|
|
1436
|
-
],
|
|
1437
|
-
);
|
|
1438
|
-
|
|
1439
|
-
// Hide caret during test runs due to a flashing caret
|
|
1440
|
-
// makes screenshot tests flakey
|
|
1441
|
-
let caretHidden = props.caretHidden;
|
|
1442
|
-
if (Platform.isTesting) {
|
|
1443
|
-
caretHidden = true;
|
|
1041
|
+
render(): React.Node {
|
|
1042
|
+
let {allowFontScaling, ...otherProps} = this.props;
|
|
1043
|
+
|
|
1044
|
+
allowFontScaling =
|
|
1045
|
+
this.props.allowFontScaling === null ||
|
|
1046
|
+
this.props.allowFontScaling === undefined
|
|
1047
|
+
? true
|
|
1048
|
+
: this.props.allowFontScaling;
|
|
1049
|
+
|
|
1050
|
+
return (
|
|
1051
|
+
<TextAncestor.Provider value={true}>
|
|
1052
|
+
<RCTTextInput
|
|
1053
|
+
{...otherProps}
|
|
1054
|
+
allowFontScaling={allowFontScaling}
|
|
1055
|
+
text={this._getText()}
|
|
1056
|
+
onFocus={this._onFocus}
|
|
1057
|
+
onBlur={this._onBlur}
|
|
1058
|
+
onChange={this._onChange}
|
|
1059
|
+
/>
|
|
1060
|
+
</TextAncestor.Provider>
|
|
1061
|
+
);
|
|
1444
1062
|
}
|
|
1445
1063
|
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
// $FlowFixMe - keyDownEvents was already checked to not be undefined
|
|
1453
|
-
for (const el of props.keyDownEvents) {
|
|
1454
|
-
if (
|
|
1455
|
-
event.nativeEvent.code == el.code &&
|
|
1456
|
-
el.handledEventPhase == eventPhase.Bubbling
|
|
1457
|
-
) {
|
|
1458
|
-
event.stopPropagation();
|
|
1459
|
-
}
|
|
1460
|
-
}
|
|
1461
|
-
}
|
|
1462
|
-
props.onKeyDown && props.onKeyDown(event);
|
|
1463
|
-
};
|
|
1064
|
+
/**
|
|
1065
|
+
* Returns true if the TextInput is focused
|
|
1066
|
+
*/
|
|
1067
|
+
isFocused(): boolean {
|
|
1068
|
+
return TextInputState.currentlyFocusedInput() === this;
|
|
1069
|
+
}
|
|
1464
1070
|
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1071
|
+
/**
|
|
1072
|
+
* Focuses the TextInput
|
|
1073
|
+
*/
|
|
1074
|
+
focus: () => void = (): void => {
|
|
1075
|
+
// $FlowFixMe - // Win32
|
|
1076
|
+
TextInputState.setFocusedTextInput(this);
|
|
1077
|
+
UIManager.dispatchViewManagerCommand(
|
|
1078
|
+
findNodeHandle(this),
|
|
1079
|
+
TextInputViewManager.Commands.focus,
|
|
1080
|
+
null,
|
|
1081
|
+
);
|
|
1475
1082
|
};
|
|
1476
1083
|
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1084
|
+
/**
|
|
1085
|
+
* Blurs the TextInput
|
|
1086
|
+
*/
|
|
1087
|
+
blur: () => void = (): void => {
|
|
1088
|
+
// $FlowFixMe - // Win32
|
|
1089
|
+
TextInputState.blurTextInput(this);
|
|
1090
|
+
UIManager.dispatchViewManagerCommand(
|
|
1091
|
+
findNodeHandle(this),
|
|
1092
|
+
TextInputViewManager.Commands.blur,
|
|
1093
|
+
null,
|
|
1094
|
+
);
|
|
1487
1095
|
};
|
|
1488
1096
|
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
event.stopPropagation();
|
|
1495
|
-
}
|
|
1496
|
-
}
|
|
1497
|
-
}
|
|
1498
|
-
props.onKeyUpCapture && props.onKeyUpCapture(event);
|
|
1097
|
+
/**
|
|
1098
|
+
* Use clear for programmatic clearing of the text
|
|
1099
|
+
*/
|
|
1100
|
+
clear: () => void = (): void => {
|
|
1101
|
+
this.setNativeText('');
|
|
1499
1102
|
};
|
|
1500
1103
|
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
ariaDisabled != null ||
|
|
1507
|
-
ariaExpanded != null ||
|
|
1508
|
-
ariaSelected != null
|
|
1509
|
-
) {
|
|
1510
|
-
_accessibilityState = {
|
|
1511
|
-
busy: ariaBusy ?? accessibilityState?.busy,
|
|
1512
|
-
checked: ariaChecked ?? accessibilityState?.checked,
|
|
1513
|
-
disabled: ariaDisabled ?? accessibilityState?.disabled,
|
|
1514
|
-
expanded: ariaExpanded ?? accessibilityState?.expanded,
|
|
1515
|
-
selected: ariaSelected ?? accessibilityState?.selected,
|
|
1516
|
-
};
|
|
1517
|
-
}
|
|
1518
|
-
|
|
1519
|
-
// $FlowFixMe[underconstrained-implicit-instantiation]
|
|
1520
|
-
let style = flattenStyle(props.style);
|
|
1521
|
-
|
|
1522
|
-
if (Platform.OS === 'ios') {
|
|
1523
|
-
const RCTTextInputView =
|
|
1524
|
-
props.multiline === true
|
|
1525
|
-
? RCTMultilineTextInputView
|
|
1526
|
-
: RCTSinglelineTextInputView;
|
|
1527
|
-
|
|
1528
|
-
style = props.multiline === true ? [styles.multilineInput, style] : style;
|
|
1529
|
-
|
|
1530
|
-
const useOnChangeSync =
|
|
1531
|
-
(props.unstable_onChangeSync || props.unstable_onChangeTextSync) &&
|
|
1532
|
-
!(props.onChange || props.onChangeText);
|
|
1533
|
-
|
|
1534
|
-
textInput = (
|
|
1535
|
-
<RCTTextInputView
|
|
1536
|
-
// $FlowFixMe[incompatible-type] - Figure out imperative + forward refs.
|
|
1537
|
-
ref={ref}
|
|
1538
|
-
{...otherProps}
|
|
1539
|
-
{...eventHandlers}
|
|
1540
|
-
accessibilityState={_accessibilityState}
|
|
1541
|
-
accessible={accessible}
|
|
1542
|
-
submitBehavior={submitBehavior}
|
|
1543
|
-
caretHidden={caretHidden}
|
|
1544
|
-
dataDetectorTypes={props.dataDetectorTypes}
|
|
1545
|
-
focusable={tabIndex !== undefined ? !tabIndex : focusable}
|
|
1546
|
-
mostRecentEventCount={mostRecentEventCount}
|
|
1547
|
-
nativeID={id ?? props.nativeID}
|
|
1548
|
-
onBlur={_onBlur}
|
|
1549
|
-
onKeyPressSync={props.unstable_onKeyPressSync}
|
|
1550
|
-
onChange={_onChange}
|
|
1551
|
-
onChangeSync={useOnChangeSync === true ? _onChangeSync : null}
|
|
1552
|
-
onContentSizeChange={props.onContentSizeChange}
|
|
1553
|
-
onFocus={_onFocus}
|
|
1554
|
-
onScroll={_onScroll}
|
|
1555
|
-
onSelectionChange={_onSelectionChange}
|
|
1556
|
-
onSelectionChangeShouldSetResponder={emptyFunctionThatReturnsTrue}
|
|
1557
|
-
selection={selection}
|
|
1558
|
-
style={style}
|
|
1559
|
-
text={text}
|
|
1560
|
-
/>
|
|
1561
|
-
);
|
|
1562
|
-
} else if (Platform.OS === 'android') {
|
|
1563
|
-
const autoCapitalize = props.autoCapitalize || 'sentences';
|
|
1564
|
-
const _accessibilityLabelledBy =
|
|
1565
|
-
props?.['aria-labelledby'] ?? props?.accessibilityLabelledBy;
|
|
1566
|
-
const placeholder = props.placeholder ?? '';
|
|
1567
|
-
let children = props.children;
|
|
1568
|
-
const childCount = React.Children.count(children);
|
|
1569
|
-
invariant(
|
|
1570
|
-
!(props.value != null && childCount),
|
|
1571
|
-
'Cannot specify both value and children.',
|
|
1572
|
-
);
|
|
1573
|
-
if (childCount > 1) {
|
|
1574
|
-
children = <Text>{children}</Text>;
|
|
1575
|
-
}
|
|
1576
|
-
|
|
1577
|
-
textInput = (
|
|
1578
|
-
/* $FlowFixMe[prop-missing] the types for AndroidTextInput don't match up
|
|
1579
|
-
* exactly with the props for TextInput. This will need to get fixed */
|
|
1580
|
-
/* $FlowFixMe[incompatible-type] the types for AndroidTextInput don't
|
|
1581
|
-
* match up exactly with the props for TextInput. This will need to get
|
|
1582
|
-
* fixed */
|
|
1583
|
-
/* $FlowFixMe[incompatible-type-arg] the types for AndroidTextInput don't
|
|
1584
|
-
* match up exactly with the props for TextInput. This will need to get
|
|
1585
|
-
* fixed */
|
|
1586
|
-
<AndroidTextInput
|
|
1587
|
-
// $FlowFixMe[incompatible-type] - Figure out imperative + forward refs.
|
|
1588
|
-
ref={ref}
|
|
1589
|
-
{...otherProps}
|
|
1590
|
-
{...eventHandlers}
|
|
1591
|
-
accessibilityState={_accessibilityState}
|
|
1592
|
-
accessibilityLabelledBy={_accessibilityLabelledBy}
|
|
1593
|
-
accessible={accessible}
|
|
1594
|
-
autoCapitalize={autoCapitalize}
|
|
1595
|
-
submitBehavior={submitBehavior}
|
|
1596
|
-
caretHidden={caretHidden}
|
|
1597
|
-
children={children}
|
|
1598
|
-
disableFullscreenUI={props.disableFullscreenUI}
|
|
1599
|
-
focusable={tabIndex !== undefined ? !tabIndex : focusable}
|
|
1600
|
-
mostRecentEventCount={mostRecentEventCount}
|
|
1601
|
-
nativeID={id ?? props.nativeID}
|
|
1602
|
-
numberOfLines={props.rows ?? props.numberOfLines}
|
|
1603
|
-
onBlur={_onBlur}
|
|
1604
|
-
onChange={_onChange}
|
|
1605
|
-
onFocus={_onFocus}
|
|
1606
|
-
/* $FlowFixMe[prop-missing] the types for AndroidTextInput don't match
|
|
1607
|
-
* up exactly with the props for TextInput. This will need to get fixed
|
|
1608
|
-
*/
|
|
1609
|
-
/* $FlowFixMe[incompatible-type-arg] the types for AndroidTextInput
|
|
1610
|
-
* don't match up exactly with the props for TextInput. This will need
|
|
1611
|
-
* to get fixed */
|
|
1612
|
-
onScroll={_onScroll}
|
|
1613
|
-
onSelectionChange={_onSelectionChange}
|
|
1614
|
-
placeholder={placeholder}
|
|
1615
|
-
selection={selection}
|
|
1616
|
-
style={style}
|
|
1617
|
-
text={text}
|
|
1618
|
-
textBreakStrategy={props.textBreakStrategy}
|
|
1619
|
-
/>
|
|
1104
|
+
setEventCount: () => void = (): void => {
|
|
1105
|
+
UIManager.dispatchViewManagerCommand(
|
|
1106
|
+
findNodeHandle(this),
|
|
1107
|
+
TextInputViewManager.Commands.setEventCount,
|
|
1108
|
+
[this._eventCount],
|
|
1620
1109
|
);
|
|
1621
|
-
}
|
|
1622
|
-
else if (Platform.OS === 'win32') {
|
|
1623
|
-
textInput = (
|
|
1624
|
-
<WindowsTextInput
|
|
1625
|
-
// $FlowFixMe[incompatible-type] - Figure out imperative + forward refs.
|
|
1626
|
-
ref={ref}
|
|
1627
|
-
{...props}
|
|
1628
|
-
accessible={accessible}
|
|
1629
|
-
focusable={focusable}
|
|
1630
|
-
dataDetectorTypes={props.dataDetectorTypes}
|
|
1631
|
-
mostRecentEventCount={mostRecentEventCount}
|
|
1632
|
-
onBlur={_onBlur}
|
|
1633
|
-
onChange={_onChange}
|
|
1634
|
-
onContentSizeChange={props.onContentSizeChange}
|
|
1635
|
-
onFocus={_onFocus}
|
|
1636
|
-
onScroll={_onScroll}
|
|
1637
|
-
onSelectionChange={_onSelectionChange}
|
|
1638
|
-
onSelectionChangeShouldSetResponder={emptyFunctionThatReturnsTrue}
|
|
1639
|
-
selection={selection}
|
|
1640
|
-
text={text}
|
|
1641
|
-
onKeyDown={_keyDown}
|
|
1642
|
-
onKeyDownCapture={_keyDownCapture}
|
|
1643
|
-
onKeyUp={_keyUp}
|
|
1644
|
-
onKeyUpCapture={_keyUpCapture}
|
|
1645
|
-
/>
|
|
1646
|
-
);
|
|
1647
|
-
} // Windows]
|
|
1648
|
-
return (
|
|
1649
|
-
<TextAncestor.Provider value={true}>{textInput}</TextAncestor.Provider>
|
|
1650
|
-
);
|
|
1651
|
-
}
|
|
1652
|
-
|
|
1653
|
-
const enterKeyHintToReturnTypeMap = {
|
|
1654
|
-
enter: 'default',
|
|
1655
|
-
done: 'done',
|
|
1656
|
-
go: 'go',
|
|
1657
|
-
next: 'next',
|
|
1658
|
-
previous: 'previous',
|
|
1659
|
-
search: 'search',
|
|
1660
|
-
send: 'send',
|
|
1661
|
-
};
|
|
1662
|
-
|
|
1663
|
-
const inputModeToKeyboardTypeMap = {
|
|
1664
|
-
none: 'default',
|
|
1665
|
-
text: 'default',
|
|
1666
|
-
decimal: 'decimal-pad',
|
|
1667
|
-
numeric: 'number-pad',
|
|
1668
|
-
tel: 'phone-pad',
|
|
1669
|
-
search: Platform.OS === 'ios' ? 'web-search' : 'default',
|
|
1670
|
-
email: 'email-address',
|
|
1671
|
-
url: 'url',
|
|
1672
|
-
};
|
|
1673
|
-
|
|
1674
|
-
// Map HTML autocomplete values to Android autoComplete values
|
|
1675
|
-
const autoCompleteWebToAutoCompleteAndroidMap = {
|
|
1676
|
-
'address-line1': 'postal-address-region',
|
|
1677
|
-
'address-line2': 'postal-address-locality',
|
|
1678
|
-
bday: 'birthdate-full',
|
|
1679
|
-
'bday-day': 'birthdate-day',
|
|
1680
|
-
'bday-month': 'birthdate-month',
|
|
1681
|
-
'bday-year': 'birthdate-year',
|
|
1682
|
-
'cc-csc': 'cc-csc',
|
|
1683
|
-
'cc-exp': 'cc-exp',
|
|
1684
|
-
'cc-exp-month': 'cc-exp-month',
|
|
1685
|
-
'cc-exp-year': 'cc-exp-year',
|
|
1686
|
-
'cc-number': 'cc-number',
|
|
1687
|
-
country: 'postal-address-country',
|
|
1688
|
-
'current-password': 'password',
|
|
1689
|
-
email: 'email',
|
|
1690
|
-
'honorific-prefix': 'name-prefix',
|
|
1691
|
-
'honorific-suffix': 'name-suffix',
|
|
1692
|
-
name: 'name',
|
|
1693
|
-
'additional-name': 'name-middle',
|
|
1694
|
-
'family-name': 'name-family',
|
|
1695
|
-
'given-name': 'name-given',
|
|
1696
|
-
'new-password': 'password-new',
|
|
1697
|
-
off: 'off',
|
|
1698
|
-
'one-time-code': 'sms-otp',
|
|
1699
|
-
'postal-code': 'postal-code',
|
|
1700
|
-
sex: 'gender',
|
|
1701
|
-
'street-address': 'street-address',
|
|
1702
|
-
tel: 'tel',
|
|
1703
|
-
'tel-country-code': 'tel-country-code',
|
|
1704
|
-
'tel-national': 'tel-national',
|
|
1705
|
-
username: 'username',
|
|
1706
|
-
};
|
|
1707
|
-
|
|
1708
|
-
// Map HTML autocomplete values to iOS textContentType values
|
|
1709
|
-
const autoCompleteWebToTextContentTypeMap = {
|
|
1710
|
-
'address-line1': 'streetAddressLine1',
|
|
1711
|
-
'address-line2': 'streetAddressLine2',
|
|
1712
|
-
'cc-number': 'creditCardNumber',
|
|
1713
|
-
'current-password': 'password',
|
|
1714
|
-
country: 'countryName',
|
|
1715
|
-
email: 'emailAddress',
|
|
1716
|
-
name: 'name',
|
|
1717
|
-
'additional-name': 'middleName',
|
|
1718
|
-
'family-name': 'familyName',
|
|
1719
|
-
'given-name': 'givenName',
|
|
1720
|
-
nickname: 'nickname',
|
|
1721
|
-
'honorific-prefix': 'namePrefix',
|
|
1722
|
-
'honorific-suffix': 'nameSuffix',
|
|
1723
|
-
'new-password': 'newPassword',
|
|
1724
|
-
off: 'none',
|
|
1725
|
-
'one-time-code': 'oneTimeCode',
|
|
1726
|
-
organization: 'organizationName',
|
|
1727
|
-
'organization-title': 'jobTitle',
|
|
1728
|
-
'postal-code': 'postalCode',
|
|
1729
|
-
'street-address': 'fullStreetAddress',
|
|
1730
|
-
tel: 'telephoneNumber',
|
|
1731
|
-
url: 'URL',
|
|
1732
|
-
username: 'username',
|
|
1733
|
-
};
|
|
1110
|
+
};
|
|
1734
1111
|
|
|
1735
|
-
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
|
|
1743
|
-
|
|
1744
|
-
textContentType,
|
|
1745
|
-
readOnly,
|
|
1746
|
-
editable,
|
|
1747
|
-
enterKeyHint,
|
|
1748
|
-
returnKeyType,
|
|
1749
|
-
inputMode,
|
|
1750
|
-
showSoftInputOnFocus,
|
|
1751
|
-
keyboardType,
|
|
1752
|
-
...restProps
|
|
1753
|
-
},
|
|
1754
|
-
forwardedRef: ReactRefSetter<TextInputInstance>,
|
|
1755
|
-
) {
|
|
1756
|
-
// $FlowFixMe[underconstrained-implicit-instantiation]
|
|
1757
|
-
let style = flattenStyle(restProps.style);
|
|
1758
|
-
|
|
1759
|
-
if (style?.verticalAlign != null) {
|
|
1760
|
-
style.textAlignVertical =
|
|
1761
|
-
verticalAlignToTextAlignVerticalMap[style.verticalAlign];
|
|
1762
|
-
delete style.verticalAlign;
|
|
1763
|
-
}
|
|
1112
|
+
setNativeText: (val: ?Stringish) => void = (val: ?Stringish): void => {
|
|
1113
|
+
if (this._lastNativeText !== val) {
|
|
1114
|
+
UIManager.dispatchViewManagerCommand(
|
|
1115
|
+
findNodeHandle(this),
|
|
1116
|
+
TextInputViewManager.Commands.setNativeText,
|
|
1117
|
+
[val],
|
|
1118
|
+
);
|
|
1119
|
+
}
|
|
1120
|
+
};
|
|
1764
1121
|
|
|
1765
|
-
|
|
1766
|
-
|
|
1767
|
-
|
|
1768
|
-
|
|
1769
|
-
|
|
1770
|
-
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
showSoftInputOnFocus={
|
|
1778
|
-
inputMode == null ? showSoftInputOnFocus : inputMode !== 'none'
|
|
1779
|
-
}
|
|
1780
|
-
autoComplete={
|
|
1781
|
-
Platform.OS === 'android'
|
|
1782
|
-
? // $FlowFixMe
|
|
1783
|
-
autoCompleteWebToAutoCompleteAndroidMap[autoComplete] ??
|
|
1784
|
-
autoComplete
|
|
1785
|
-
: undefined
|
|
1786
|
-
}
|
|
1787
|
-
textContentType={
|
|
1788
|
-
Platform.OS === 'ios' &&
|
|
1789
|
-
autoComplete &&
|
|
1790
|
-
autoComplete in autoCompleteWebToTextContentTypeMap
|
|
1791
|
-
? // $FlowFixMe
|
|
1792
|
-
autoCompleteWebToTextContentTypeMap[autoComplete]
|
|
1793
|
-
: textContentType
|
|
1794
|
-
}
|
|
1795
|
-
{...restProps}
|
|
1796
|
-
forwardedRef={forwardedRef}
|
|
1797
|
-
style={style}
|
|
1798
|
-
/>
|
|
1799
|
-
);
|
|
1800
|
-
});
|
|
1801
|
-
|
|
1802
|
-
ExportedForwardRef.displayName = 'TextInput';
|
|
1122
|
+
_getText = (): string | null => {
|
|
1123
|
+
if (this.props.value != null && this.props.value != undefined) {
|
|
1124
|
+
return this.props.value;
|
|
1125
|
+
}
|
|
1126
|
+
if (
|
|
1127
|
+
this.props.defaultValue != null &&
|
|
1128
|
+
this.props.defaultValue != undefined
|
|
1129
|
+
) {
|
|
1130
|
+
return this.props.defaultValue;
|
|
1131
|
+
}
|
|
1132
|
+
return null;
|
|
1133
|
+
};
|
|
1803
1134
|
|
|
1804
|
-
|
|
1805
|
-
|
|
1806
|
-
|
|
1807
|
-
|
|
1808
|
-
ExportedForwardRef.propTypes =
|
|
1809
|
-
require('deprecated-react-native-prop-types').TextInputPropTypes;
|
|
1135
|
+
_onChange = (e: ChangeEvent): void => {
|
|
1136
|
+
const text = e.nativeEvent.text;
|
|
1137
|
+
this._eventCount = e.nativeEvent.eventCount;
|
|
1138
|
+
this.setEventCount();
|
|
1810
1139
|
|
|
1811
|
-
|
|
1812
|
-
|
|
1813
|
-
|
|
1140
|
+
this.props.onChange && this.props.onChange(e);
|
|
1141
|
+
this.props.onChangeText && this.props.onChangeText(text);
|
|
1142
|
+
this._lastNativeText = text;
|
|
1814
1143
|
|
|
1815
|
-
|
|
1816
|
-
|
|
1817
|
-
|
|
1818
|
-
};
|
|
1144
|
+
this.forceUpdate();
|
|
1145
|
+
return;
|
|
1146
|
+
};
|
|
1819
1147
|
|
|
1820
|
-
|
|
1821
|
-
|
|
1822
|
-
|
|
1823
|
-
|
|
1824
|
-
focusTextInput: typeof TextInputState.focusTextInput,
|
|
1825
|
-
blurTextInput: typeof TextInputState.blurTextInput,
|
|
1826
|
-
|}>,
|
|
1827
|
-
|}>;
|
|
1148
|
+
_onFocus = (e: FocusEvent): void => {
|
|
1149
|
+
this.focus();
|
|
1150
|
+
this.props.onFocus && this.props.onFocus(e);
|
|
1151
|
+
};
|
|
1828
1152
|
|
|
1829
|
-
|
|
1830
|
-
|
|
1831
|
-
|
|
1832
|
-
|
|
1833
|
-
// of font size 17 and a height of 31 points.
|
|
1834
|
-
paddingTop: 5,
|
|
1835
|
-
},
|
|
1836
|
-
});
|
|
1837
|
-
|
|
1838
|
-
const verticalAlignToTextAlignVerticalMap = {
|
|
1839
|
-
auto: 'auto',
|
|
1840
|
-
top: 'top',
|
|
1841
|
-
bottom: 'bottom',
|
|
1842
|
-
middle: 'center',
|
|
1843
|
-
};
|
|
1153
|
+
_onBlur = (e: BlurEvent): void => {
|
|
1154
|
+
this.props.onBlur && this.props.onBlur(e);
|
|
1155
|
+
};
|
|
1156
|
+
}
|
|
1844
1157
|
|
|
1845
|
-
|
|
1846
|
-
module.exports = ((ExportedForwardRef: any): TextInputType);
|
|
1158
|
+
module.exports = TextInput;
|