@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.
Files changed (324) hide show
  1. package/.flowconfig +15 -3
  2. package/CHANGELOG.json +302 -47
  3. package/CHANGELOG.md +141 -27
  4. package/IntegrationTests/IntegrationTestHarnessTest.js +1 -0
  5. package/Libraries/ActionSheetIOS/ActionSheetIOS.js +1 -1
  6. package/Libraries/Alert/Alert.d.ts +4 -4
  7. package/Libraries/Alert/Alert.win32.js +1 -0
  8. package/Libraries/Animated/Animated.d.ts +17 -6
  9. package/Libraries/Animated/NativeAnimatedHelper.js +18 -6
  10. package/Libraries/Animated/NativeAnimatedHelper.win32.js +606 -0
  11. package/Libraries/Animated/bezier.js +1 -1
  12. package/Libraries/Animated/components/AnimatedFlatList.js +8 -3
  13. package/Libraries/Animated/components/AnimatedScrollView.js +4 -1
  14. package/Libraries/Animated/components/AnimatedSectionList.js +12 -3
  15. package/Libraries/Animated/createAnimatedComponent.js +26 -239
  16. package/Libraries/Animated/nodes/AnimatedColor.js +47 -80
  17. package/Libraries/Animated/nodes/AnimatedInterpolation.js +167 -121
  18. package/Libraries/Animated/nodes/AnimatedNode.js +3 -5
  19. package/Libraries/Animated/nodes/AnimatedProps.js +7 -6
  20. package/Libraries/Animated/nodes/AnimatedStyle.js +42 -8
  21. package/Libraries/Animated/nodes/AnimatedTransform.js +1 -1
  22. package/Libraries/Animated/nodes/AnimatedValue.js +8 -12
  23. package/Libraries/Animated/nodes/AnimatedWithChildren.js +1 -1
  24. package/Libraries/Animated/useAnimatedProps.js +7 -10
  25. package/Libraries/BatchedBridge/MessageQueue.js +2 -1
  26. package/Libraries/BatchedBridge/NativeModules.d.ts +1 -1
  27. package/Libraries/BatchedBridge/NativeModules.js +1 -0
  28. package/Libraries/Blob/Blob.js +4 -0
  29. package/Libraries/Blob/FileReader.js +30 -2
  30. package/Libraries/Blob/URL.js +3 -1
  31. package/Libraries/Components/AccessibilityInfo/AccessibilityInfo.d.ts +2 -2
  32. package/Libraries/Components/AccessibilityInfo/AccessibilityInfo.js +2 -3
  33. package/Libraries/Components/AccessibilityInfo/AccessibilityInfo.win32.js +2 -3
  34. package/Libraries/Components/ActivityIndicator/ActivityIndicator.js +6 -4
  35. package/Libraries/Components/Button.js +3 -2
  36. package/Libraries/Components/Button.win32.js +451 -0
  37. package/Libraries/Components/Clipboard/Clipboard.js +1 -1
  38. package/Libraries/Components/DrawerAndroid/DrawerLayoutAndroid.android.js +4 -0
  39. package/Libraries/Components/Keyboard/KeyboardAvoidingView.js +1 -0
  40. package/Libraries/Components/Pressable/Pressable.d.ts +1 -1
  41. package/Libraries/Components/Pressable/Pressable.js +1 -1
  42. package/Libraries/Components/RefreshControl/RefreshControl.js +1 -0
  43. package/Libraries/Components/SafeAreaView/SafeAreaView.js +1 -2
  44. package/Libraries/Components/SafeAreaView/SafeAreaView.win32.js +1 -2
  45. package/Libraries/Components/ScrollView/AndroidHorizontalScrollViewNativeComponent.js +12 -6
  46. package/Libraries/Components/ScrollView/ScrollView.d.ts +2 -2
  47. package/Libraries/Components/ScrollView/ScrollView.js +149 -91
  48. package/Libraries/Components/ScrollView/ScrollView.win32.js +1939 -0
  49. package/Libraries/Components/ScrollView/ScrollViewNativeComponent.js +16 -6
  50. package/Libraries/Components/ScrollView/ScrollViewStickyHeader.js +5 -7
  51. package/Libraries/Components/ScrollView/ScrollViewViewConfig.js +1 -1
  52. package/Libraries/Components/StatusBar/StatusBar.js +3 -0
  53. package/Libraries/Components/Switch/Switch.js +3 -1
  54. package/Libraries/Components/TextInput/AndroidTextInputNativeComponent.js +21 -11
  55. package/Libraries/Components/TextInput/InputAccessoryView.d.ts +1 -1
  56. package/Libraries/Components/TextInput/RCTTextInputViewConfig.js +11 -5
  57. package/Libraries/Components/TextInput/TextInput.Types.win32.d.ts +51 -0
  58. package/Libraries/Components/TextInput/TextInput.Types.win32.js +3 -0
  59. package/Libraries/Components/TextInput/TextInput.Types.win32.js.map +1 -0
  60. package/Libraries/Components/TextInput/TextInput.d.ts +15 -5
  61. package/Libraries/Components/TextInput/TextInput.flow.js +1 -1
  62. package/Libraries/Components/TextInput/TextInput.js +130 -103
  63. package/Libraries/Components/TextInput/TextInput.win32.js +202 -890
  64. package/Libraries/Components/Touchable/Touchable.d.ts +1 -1
  65. package/Libraries/Components/Touchable/Touchable.flow.js +30 -4
  66. package/Libraries/Components/Touchable/Touchable.js +6 -3
  67. package/Libraries/Components/Touchable/Touchable.win32.js +6 -3
  68. package/Libraries/Components/Touchable/TouchableHighlight.js +1 -1
  69. package/Libraries/Components/Touchable/TouchableNativeFeedback.js +2 -2
  70. package/Libraries/Components/Touchable/TouchableOpacity.js +3 -0
  71. package/Libraries/Components/Touchable/TouchableWithoutFeedback.d.ts +1 -1
  72. package/Libraries/Components/Touchable/TouchableWithoutFeedback.js +2 -2
  73. package/Libraries/Components/TraceUpdateOverlay/TraceUpdateOverlay.js +189 -0
  74. package/Libraries/Components/TraceUpdateOverlay/TraceUpdateOverlayNativeComponent.js +43 -0
  75. package/Libraries/Components/View/ReactNativeStyleAttributes.js +26 -0
  76. package/Libraries/Components/View/View.js +71 -45
  77. package/Libraries/Components/View/View.win32.js +38 -16
  78. package/Libraries/Components/View/ViewAccessibility.d.ts +6 -6
  79. package/Libraries/Components/View/ViewAccessibility.js +10 -1
  80. package/Libraries/Components/View/ViewAccessibility.win32.d.ts +5 -5
  81. package/Libraries/Components/View/ViewNativeComponent.js +32 -8
  82. package/Libraries/Components/View/ViewPropTypes.d.ts +1 -1
  83. package/Libraries/Components/View/ViewPropTypes.js +1 -1
  84. package/Libraries/Components/View/ViewPropTypes.win32.d.ts +1 -1
  85. package/Libraries/Components/View/ViewPropTypes.win32.js +1 -1
  86. package/Libraries/Components/View/ViewWin32.js +3 -3
  87. package/Libraries/Core/Devtools/openFileInEditor.js +1 -0
  88. package/Libraries/Core/Devtools/openURLInBrowser.js +1 -0
  89. package/Libraries/Core/Devtools/parseErrorStack.js +2 -2
  90. package/Libraries/Core/Devtools/parseHermesStack.js +54 -34
  91. package/Libraries/Core/ExceptionsManager.js +2 -2
  92. package/Libraries/Core/InitializeCore.js +2 -1
  93. package/Libraries/Core/ReactNativeVersion.js +3 -3
  94. package/Libraries/Core/ReactNativeVersionCheck.js +1 -9
  95. package/Libraries/Core/ReactNativeVersionCheck.win32.js +1 -9
  96. package/Libraries/Core/Timers/JSTimers.js +1 -1
  97. package/Libraries/Core/Timers/immediateShim.js +1 -0
  98. package/Libraries/Core/Timers/queueMicrotask.js +1 -1
  99. package/Libraries/Core/setUpAlert.js +1 -1
  100. package/Libraries/Core/setUpDOM.js +18 -0
  101. package/Libraries/Core/setUpDeveloperTools.js +1 -1
  102. package/Libraries/Core/setUpGlobals.js +5 -2
  103. package/Libraries/Core/setUpNavigator.js +6 -5
  104. package/Libraries/Core/setUpPerformance.js +23 -13
  105. package/Libraries/Core/setUpReactDevTools.js +2 -0
  106. package/Libraries/Core/setUpSegmentFetcher.js +0 -41
  107. package/Libraries/Core/setUpTimers.js +2 -2
  108. package/Libraries/DOM/Geometry/DOMRect.js +82 -0
  109. package/Libraries/DOM/Geometry/DOMRectReadOnly.js +188 -0
  110. package/Libraries/DOM/Nodes/ReactNativeElement.js +75 -0
  111. package/Libraries/DOM/Nodes/ReadOnlyElement.js +89 -0
  112. package/Libraries/DOM/Nodes/ReadOnlyNode.js +167 -0
  113. package/Libraries/DOM/OldStyleCollections/ArrayLikeUtils.js +46 -0
  114. package/Libraries/DOM/OldStyleCollections/DOMRectList.js +76 -0
  115. package/Libraries/DOM/OldStyleCollections/HTMLCollection.js +82 -0
  116. package/Libraries/DOM/OldStyleCollections/NodeList.js +104 -0
  117. package/Libraries/DevToolsSettings/DevToolsSettingsManager.android.js +35 -0
  118. package/Libraries/DevToolsSettings/DevToolsSettingsManager.d.ts +20 -0
  119. package/Libraries/DevToolsSettings/DevToolsSettingsManager.ios.js +49 -0
  120. package/Libraries/DevToolsSettings/DevToolsSettingsManager.win32.js +35 -0
  121. package/Libraries/{Utilities/NativeDevSplitBundleLoader.js → DevToolsSettings/NativeDevToolsSettingsManager.js} +7 -2
  122. package/Libraries/EventEmitter/NativeEventEmitter.d.ts +1 -2
  123. package/Libraries/EventEmitter/RCTDeviceEventEmitter.d.ts +1 -2
  124. package/Libraries/EventEmitter/RCTDeviceEventEmitter.js +9 -1
  125. package/Libraries/Events/EventPolyfill.js +1 -1
  126. package/Libraries/Image/AssetRegistry.js +1 -1
  127. package/Libraries/Image/AssetSourceResolver.js +3 -3
  128. package/Libraries/Image/Image.android.js +4 -1
  129. package/Libraries/Image/Image.d.ts +63 -2
  130. package/Libraries/Image/Image.ios.js +3 -0
  131. package/Libraries/Image/Image.win32.js +3 -0
  132. package/Libraries/Image/ImageBackground.js +1 -0
  133. package/Libraries/Image/ImageProps.js +1 -1
  134. package/Libraries/Image/ImageViewNativeComponent.js +4 -4
  135. package/Libraries/Image/RelativeImageStub.js +1 -1
  136. package/Libraries/Image/TextInlineImageNativeComponent.js +1 -1
  137. package/Libraries/Image/resolveAssetSource.js +1 -1
  138. package/Libraries/Inspector/DevtoolsOverlay.js +29 -19
  139. package/Libraries/Inspector/ElementBox.js +4 -1
  140. package/Libraries/Inspector/Inspector.js +5 -6
  141. package/Libraries/Inspector/Inspector.win32.js +7 -6
  142. package/Libraries/Inspector/InspectorOverlay.js +3 -3
  143. package/Libraries/Inspector/InspectorOverlay.win32.js +2 -1
  144. package/Libraries/Inspector/NetworkOverlay.js +1 -1
  145. package/Libraries/Interaction/JSEventLoopWatchdog.js +1 -1
  146. package/Libraries/Interaction/PanResponder.js +5 -6
  147. package/Libraries/LayoutAnimation/LayoutAnimation.js +2 -1
  148. package/Libraries/Linking/Linking.js +1 -4
  149. package/Libraries/Lists/FillRateHelper.js +4 -238
  150. package/Libraries/Lists/FlatList.d.ts +15 -22
  151. package/Libraries/Lists/FlatList.js +9 -6
  152. package/Libraries/Lists/SectionList.d.ts +10 -6
  153. package/Libraries/Lists/SectionList.js +5 -3
  154. package/Libraries/Lists/SectionListModern.js +3 -3
  155. package/Libraries/Lists/ViewabilityHelper.js +8 -344
  156. package/Libraries/Lists/VirtualizeUtils.js +4 -244
  157. package/Libraries/Lists/VirtualizedList.js +10 -1867
  158. package/Libraries/Lists/VirtualizedListContext.js +6 -104
  159. package/Libraries/Lists/VirtualizedSectionList.js +9 -602
  160. package/Libraries/Lists/__flowtests__/FlatList-flowtest.js +1 -0
  161. package/Libraries/Lists/__flowtests__/SectionList-flowtest.js +1 -1
  162. package/Libraries/LogBox/Data/LogBoxData.js +1 -1
  163. package/Libraries/LogBox/Data/parseLogBoxLog.js +1 -1
  164. package/Libraries/LogBox/LogBox.js +1 -1
  165. package/Libraries/LogBox/UI/LogBoxInspector.js +1 -3
  166. package/Libraries/LogBox/UI/LogBoxInspectorCodeFrame.win32.js +168 -0
  167. package/Libraries/LogBox/UI/LogBoxInspectorHeader.win32.js +3 -0
  168. package/Libraries/LogBox/UI/LogBoxInspectorReactFrames.win32.js +193 -0
  169. package/Libraries/LogBox/UI/LogBoxInspectorSourceMapStatus.js +1 -0
  170. package/Libraries/LogBox/UI/LogBoxInspectorStackFrame.js +2 -2
  171. package/Libraries/LogBox/UI/LogBoxInspectorStackFrame.win32.js +7 -3
  172. package/Libraries/LogBox/UI/LogBoxMessage.js +87 -5
  173. package/Libraries/LogBox/UI/LogBoxNotification.js +5 -7
  174. package/Libraries/Modal/Modal.js +2 -2
  175. package/Libraries/NativeComponent/BaseViewConfig.android.js +32 -12
  176. package/Libraries/NativeComponent/BaseViewConfig.ios.js +43 -19
  177. package/Libraries/NativeComponent/BaseViewConfig.win32.js +43 -19
  178. package/Libraries/NativeComponent/NativeComponentRegistryUnstable.js +4 -1
  179. package/Libraries/NativeComponent/ViewConfig.js +1 -0
  180. package/Libraries/NativeComponent/ViewConfigIgnore.js +1 -4
  181. package/Libraries/Network/RCTNetworking.android.js +2 -2
  182. package/Libraries/Network/RCTNetworking.ios.js +1 -1
  183. package/Libraries/Network/RCTNetworking.win32.js +1 -1
  184. package/Libraries/Network/XMLHttpRequest.js +1 -1
  185. package/Libraries/Pressability/Pressability.js +11 -5
  186. package/Libraries/Pressability/Pressability.win32.js +9 -3
  187. package/Libraries/ReactNative/AppContainer.js +7 -1
  188. package/Libraries/ReactNative/AppRegistry.d.ts +1 -1
  189. package/Libraries/ReactNative/AppRegistry.js +10 -13
  190. package/Libraries/ReactNative/FabricUIManager.js +24 -8
  191. package/Libraries/ReactNative/NativeUIManager.js +5 -5
  192. package/Libraries/ReactNative/ReactNativeFeatureFlags.js +10 -10
  193. package/Libraries/ReactNative/UIManager.js +142 -1
  194. package/Libraries/ReactNative/getCachedComponentWithDebugName.js +5 -5
  195. package/Libraries/ReactNative/getNativeComponentAttributes.js +1 -1
  196. package/Libraries/ReactNative/requireNativeComponent.d.ts +1 -1
  197. package/Libraries/ReactNative/requireNativeComponent.js +1 -1
  198. package/Libraries/ReactPrivate/ReactNativePrivateInterface.js +1 -0
  199. package/Libraries/Renderer/implementations/ReactFabric-dev.js +26 -3
  200. package/Libraries/Renderer/implementations/ReactFabric-prod.js +13 -1
  201. package/Libraries/Renderer/implementations/ReactFabric-profiling.js +13 -1
  202. package/Libraries/Renderer/public/ReactFabricPublicInstanceUtils.js +38 -0
  203. package/Libraries/Renderer/shims/ReactNativeTypes.js +38 -20
  204. package/Libraries/Renderer/shims/ReactNativeViewConfigRegistry.js +7 -7
  205. package/Libraries/Renderer/shims/createReactNativeComponentClass.js +2 -2
  206. package/Libraries/Share/Share.js +1 -1
  207. package/Libraries/StyleSheet/PlatformColorValueTypes.ios.js +1 -1
  208. package/Libraries/StyleSheet/StyleSheet.js +1 -1
  209. package/Libraries/StyleSheet/StyleSheet.win32.js +1 -1
  210. package/Libraries/StyleSheet/StyleSheetTypes.d.ts +115 -76
  211. package/Libraries/StyleSheet/StyleSheetTypes.js +188 -33
  212. package/Libraries/StyleSheet/flattenStyle.js +2 -0
  213. package/Libraries/StyleSheet/normalizeColor.js +1 -1
  214. package/Libraries/StyleSheet/processColor.js +1 -1
  215. package/Libraries/Text/Text.d.ts +12 -2
  216. package/Libraries/Text/Text.js +50 -41
  217. package/Libraries/Text/TextProps.js +3 -4
  218. package/Libraries/TurboModule/samples/NativeSampleTurboModule.js +6 -0
  219. package/Libraries/Types/CodegenTypes.js +1 -0
  220. package/Libraries/UTFSequence.js +3 -1
  221. package/Libraries/Utilities/Appearance.d.ts +10 -0
  222. package/Libraries/Utilities/Appearance.js +13 -0
  223. package/Libraries/Utilities/Dimensions.js +1 -1
  224. package/Libraries/Utilities/Dimensions.win32.js +1 -1
  225. package/Libraries/Utilities/GlobalPerformanceLogger.js +12 -1
  226. package/Libraries/Utilities/HMRClient.js +16 -10
  227. package/Libraries/Utilities/{createPerformanceLogger.d.ts → IPerformanceLogger.d.ts} +4 -4
  228. package/Libraries/Utilities/IPerformanceLogger.js +49 -0
  229. package/Libraries/Utilities/LoadingView.android.js +28 -11
  230. package/Libraries/Utilities/NativeAppearance.js +1 -0
  231. package/Libraries/Utilities/NativePlatformConstantsWin.js +1 -1
  232. package/Libraries/Utilities/PixelRatio.js +2 -2
  233. package/Libraries/Utilities/Platform.win32.js +1 -1
  234. package/Libraries/Utilities/ReactNativeTestTools.js +1 -1
  235. package/Libraries/Utilities/__mocks__/PixelRatio.js +1 -1
  236. package/Libraries/Utilities/codegenNativeCommands.js +2 -0
  237. package/Libraries/Utilities/createPerformanceLogger.js +55 -43
  238. package/Libraries/Utilities/stringifySafe.js +2 -7
  239. package/Libraries/Utilities/useColorScheme.js +1 -1
  240. package/Libraries/Utilities/useWindowDimensions.js +3 -3
  241. package/Libraries/WebPerformance/EventCounts.js +78 -0
  242. package/Libraries/WebPerformance/MemoryInfo.js +54 -0
  243. package/Libraries/WebPerformance/NativePerformance.js +38 -0
  244. package/Libraries/WebPerformance/NativePerformanceObserver.js +22 -7
  245. package/Libraries/WebPerformance/Performance.js +312 -0
  246. package/Libraries/WebPerformance/PerformanceEntry.js +45 -0
  247. package/Libraries/WebPerformance/PerformanceEventTiming.js +38 -0
  248. package/Libraries/WebPerformance/PerformanceObserver.js +196 -101
  249. package/Libraries/WebPerformance/RawPerformanceEntry.js +87 -0
  250. package/Libraries/WebPerformance/ReactNativeStartupTiming.js +65 -0
  251. package/Libraries/WebPerformance/__mocks__/NativePerformance.js +65 -0
  252. package/Libraries/WebPerformance/__mocks__/NativePerformanceObserver.js +101 -0
  253. package/Libraries/YellowBox/YellowBoxDeprecated.js +1 -1
  254. package/Libraries/vendor/core/ErrorUtils.js +1 -1
  255. package/Libraries/vendor/emitter/EventEmitter.d.ts +2 -2
  256. package/Libraries/vendor/emitter/EventEmitter.js +9 -1
  257. package/flow/global.js +29 -4
  258. package/flow/jest.js +258 -164
  259. package/index.js +56 -42
  260. package/index.win32.js +56 -42
  261. package/interface.js +1 -1
  262. package/jest/local-setup.js +33 -0
  263. package/jest/mockComponent.js +4 -2
  264. package/jest/mockNativeComponent.js +1 -1
  265. package/jest/mockScrollView.js +2 -1
  266. package/jest/react-native-env.js +1 -3
  267. package/jest/setup.js +11 -8
  268. package/overrides.json +115 -85
  269. package/package.json +38 -28
  270. package/rn-get-polyfills.js +1 -1
  271. package/src/Libraries/Components/TextInput/TextInput.Types.win32.ts +68 -0
  272. package/src/Libraries/Components/View/ViewAccessibility.win32.d.ts +5 -5
  273. package/src/Libraries/Components/View/ViewPropTypes.win32.d.ts +1 -1
  274. package/types/index.d.ts +2 -6
  275. package/types/modules/Codegen.d.ts +4 -4
  276. package/types/modules/globals.d.ts +27 -25
  277. package/types/public/DeprecatedPropertiesAlias.d.ts +0 -20
  278. package/types/public/ReactNativeRenderer.d.ts +2 -7
  279. package/Libraries/Animated/createAnimatedComponentInjection.js +0 -48
  280. package/Libraries/Animated/createAnimatedComponent_EXPERIMENTAL.js +0 -48
  281. package/Libraries/Components/AccessibilityInfo/AccessibilityInfo.flow.js +0 -208
  282. package/Libraries/Components/ActivityIndicator/ActivityIndicator.flow.js +0 -58
  283. package/Libraries/Components/DatePicker/DatePickerIOS.android.js +0 -47
  284. package/Libraries/Components/DatePicker/DatePickerIOS.d.ts +0 -92
  285. package/Libraries/Components/DatePicker/DatePickerIOS.flow.android.js +0 -14
  286. package/Libraries/Components/DatePicker/DatePickerIOS.flow.ios.js +0 -113
  287. package/Libraries/Components/DatePicker/DatePickerIOS.ios.js +0 -242
  288. package/Libraries/Components/DatePicker/DatePickerIOS.win32.js +0 -47
  289. package/Libraries/Components/DatePicker/RCTDatePickerNativeComponent.js +0 -60
  290. package/Libraries/Components/DatePickerAndroid/NativeDatePickerAndroid.js +0 -26
  291. package/Libraries/Components/ProgressViewIOS/ProgressViewIOS.android.js +0 -45
  292. package/Libraries/Components/ProgressViewIOS/ProgressViewIOS.d.ts +0 -62
  293. package/Libraries/Components/ProgressViewIOS/ProgressViewIOS.ios.js +0 -75
  294. package/Libraries/Components/ProgressViewIOS/ProgressViewIOS.win32.js +0 -45
  295. package/Libraries/Components/ProgressViewIOS/RCTProgressViewNativeComponent.js +0 -33
  296. package/Libraries/Components/SafeAreaView/SafeAreaView.flow.js +0 -19
  297. package/Libraries/Components/Slider/Slider.d.ts +0 -132
  298. package/Libraries/Components/Slider/Slider.js +0 -282
  299. package/Libraries/Components/Slider/SliderNativeComponent.js +0 -56
  300. package/Libraries/Components/TextInput/Win32TextInputNativeComponent.js +0 -23
  301. package/Libraries/Interaction/Batchinator.js +0 -76
  302. package/Libraries/Interaction/BridgeSpyStallHandler.js +0 -63
  303. package/Libraries/Interaction/InteractionStallDebugger.js +0 -23
  304. package/Libraries/Interaction/PanResponder.flow.js +0 -257
  305. package/Libraries/Lists/CellRenderMask.js +0 -155
  306. package/Libraries/Lists/ChildListCollection.js +0 -72
  307. package/Libraries/Lists/StateSafePureComponent.js +0 -85
  308. package/Libraries/Lists/VirtualizedList.d.ts +0 -347
  309. package/Libraries/Lists/VirtualizedListCellRenderer.js +0 -259
  310. package/Libraries/Lists/VirtualizedListProps.js +0 -279
  311. package/Libraries/Performance/PureComponentDebug.js +0 -74
  312. package/Libraries/Reliability/UserFlow.js +0 -158
  313. package/Libraries/Renderer/implementations/ReactNativeRenderer.d.ts +0 -149
  314. package/Libraries/Renderer/shims/ReactNativeTypes.d.ts +0 -141
  315. package/Libraries/Utilities/MatrixMath.js +0 -748
  316. package/Libraries/Utilities/buildStyleInterpolator.js +0 -209
  317. package/Libraries/Utilities/clamp.js +0 -23
  318. package/Libraries/Utilities/deprecatedPropType.js +0 -36
  319. package/Libraries/Utilities/groupByEveryN.js +0 -51
  320. package/Libraries/Utilities/mergeIntoFast.js +0 -26
  321. package/Libraries/Utilities/setAndForwardRef.js +0 -71
  322. package/Libraries/Utilities/truncate.js +0 -51
  323. package/flow/JSITimerInternalType.js +0 -30
  324. package/flow/use-sync-external-store.js +0 -19
@@ -1,38 +1,44 @@
1
1
  /**
2
- * Copyright (c) Meta Platforms, Inc. and affiliates.
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
- * This source code is licensed under the MIT license found in the
5
- * LICENSE file in the root directory of this source tree.
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
- ...WindowsProps, // [Windows]
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
- const emptyFunctionThatReturnsTrue = () => true;
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
- * A foundational component for inputting text into the app via a
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
- let viewCommands;
1161
- if (AndroidTextInputCommands) {
1162
- viewCommands = AndroidTextInputCommands;
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
- const text =
1177
- typeof props.value === 'string'
1178
- ? props.value
1179
- : typeof props.defaultValue === 'string'
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
- if (
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
- if (Object.keys(nativeUpdate).length === 0) {
1205
- return;
1206
- }
982
+ _lastNativeText: ?Stringish;
983
+ _eventCount: number = 0;
1207
984
 
1208
- if (inputRef.current != null) {
1209
- viewCommands.setTextAndSelection(
1210
- inputRef.current,
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
- setLastNativeText(currentText);
1326
- // This must happen last, after we call setLastNativeText.
1327
- // Different ordering can cause bugs when editing AndroidTextInputs
1328
- // with multiple Fragments.
1329
- // We must update this so that controlled input updates work.
1330
- setMostRecentEventCount(event.nativeEvent.eventCount);
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
- const _onChangeSync = (event: ChangeEvent) => {
1334
- const currentText = event.nativeEvent.text;
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 (inputRef.current == null) {
1340
- // calling `props.onChange` or `props.onChangeText`
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
- setLastNativeText(currentText);
1346
- // This must happen last, after we call setLastNativeText.
1347
- // Different ordering can cause bugs when editing AndroidTextInputs
1348
- // with multiple Fragments.
1349
- // We must update this so that controlled input updates work.
1350
- setMostRecentEventCount(event.nativeEvent.eventCount);
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
- setLastNativeSelection({
1363
- selection: event.nativeEvent.selection,
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
- const _onBlur = (event: BlurEvent) => {
1376
- TextInputState.blurInput(inputRef.current);
1377
- if (props.onBlur) {
1378
- props.onBlur(event);
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
- let textInput = null;
1027
+ // unregister
1028
+ // $FlowFixMe - // Win32
1029
+ TextInputState.unregisterInput(this);
1387
1030
 
1388
- const multiline = props.multiline ?? false;
1389
-
1390
- let submitBehavior: SubmitBehavior;
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
- } else {
1406
- // Single line
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
- const accessible = props.accessible !== false;
1415
- const focusable = props.focusable !== false;
1416
-
1417
- const config = React.useMemo(
1418
- () => ({
1419
- onPress: (event: PressEvent) => {
1420
- if (props.editable !== false) {
1421
- if (inputRef.current != null) {
1422
- inputRef.current.focus();
1423
- }
1424
- }
1425
- },
1426
- onPressIn: props.onPressIn,
1427
- onPressOut: props.onPressOut,
1428
- cancelable:
1429
- Platform.OS === 'ios' ? !props.rejectResponderTermination : null,
1430
- }),
1431
- [
1432
- props.editable,
1433
- props.onPressIn,
1434
- props.onPressOut,
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
- // TextInput handles onBlur and onFocus events
1447
- // so omitting onBlur and onFocus pressability handlers here.
1448
- const {onBlur, onFocus, ...eventHandlers} = usePressability(config) || {};
1449
- const eventPhase = Object.freeze({Capturing: 1, Bubbling: 3});
1450
- const _keyDown = (event: KeyEvent) => {
1451
- if (props.keyDownEvents && event.isPropagationStopped() !== true) {
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
- const _keyUp = (event: KeyEvent) => {
1466
- if (props.keyUpEvents && event.isPropagationStopped() !== true) {
1467
- // $FlowFixMe - keyDownEvents was already checked to not be undefined
1468
- for (const el of props.keyUpEvents) {
1469
- if (event.nativeEvent.code == el.code && el.handledEventPhase == 3) {
1470
- event.stopPropagation();
1471
- }
1472
- }
1473
- }
1474
- props.onKeyUp && props.onKeyUp(event);
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
- const _keyDownCapture = (event: KeyEvent) => {
1478
- if (props.keyDownEvents && event.isPropagationStopped() !== true) {
1479
- // $FlowFixMe - keyDownEvents was already checked to not be undefined
1480
- for (const el of props.keyDownEvents) {
1481
- if (event.nativeEvent.code == el.code && el.handledEventPhase == 1) {
1482
- event.stopPropagation();
1483
- }
1484
- }
1485
- }
1486
- props.onKeyDownCapture && props.onKeyDownCapture(event);
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
- const _keyUpCapture = (event: KeyEvent) => {
1490
- if (props.keyUpEvents && event.isPropagationStopped() !== true) {
1491
- // $FlowFixMe - keyDownEvents was already checked to not be undefined
1492
- for (const el of props.keyUpEvents) {
1493
- if (event.nativeEvent.code == el.code && el.handledEventPhase == 1) {
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
- let _accessibilityState;
1502
- if (
1503
- accessibilityState != null ||
1504
- ariaBusy != null ||
1505
- ariaChecked != null ||
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
- } // [Windows
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
- const ExportedForwardRef: React.AbstractComponent<
1736
- React.ElementConfig<typeof InternalTextInput>,
1737
- TextInputInstance,
1738
- > = React.forwardRef(function TextInput(
1739
- {
1740
- allowFontScaling = true,
1741
- rejectResponderTermination = true,
1742
- underlineColorAndroid = 'transparent',
1743
- autoComplete,
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
- return (
1766
- <InternalTextInput
1767
- allowFontScaling={allowFontScaling}
1768
- rejectResponderTermination={rejectResponderTermination}
1769
- underlineColorAndroid={underlineColorAndroid}
1770
- editable={readOnly !== undefined ? !readOnly : editable}
1771
- returnKeyType={
1772
- enterKeyHint ? enterKeyHintToReturnTypeMap[enterKeyHint] : returnKeyType
1773
- }
1774
- keyboardType={
1775
- inputMode ? inputModeToKeyboardTypeMap[inputMode] : keyboardType
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
- * Switch to `deprecated-react-native-prop-types` for compatibility with future
1806
- * releases. This is deprecated and will be removed in the future.
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
- // $FlowFixMe[prop-missing]
1812
- ExportedForwardRef.State = {
1813
- currentlyFocusedInput: TextInputState.currentlyFocusedInput,
1140
+ this.props.onChange && this.props.onChange(e);
1141
+ this.props.onChangeText && this.props.onChangeText(text);
1142
+ this._lastNativeText = text;
1814
1143
 
1815
- currentlyFocusedField: TextInputState.currentlyFocusedField,
1816
- focusTextInput: TextInputState.focusTextInput,
1817
- blurTextInput: TextInputState.blurTextInput,
1818
- };
1144
+ this.forceUpdate();
1145
+ return;
1146
+ };
1819
1147
 
1820
- export type TextInputComponentStatics = $ReadOnly<{|
1821
- State: $ReadOnly<{|
1822
- currentlyFocusedInput: typeof TextInputState.currentlyFocusedInput,
1823
- currentlyFocusedField: typeof TextInputState.currentlyFocusedField,
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
- const styles = StyleSheet.create({
1830
- multilineInput: {
1831
- // This default top inset makes RCTMultilineTextInputView seem as close as possible
1832
- // to single-line RCTSinglelineTextInputView defaults, using the system defaults
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
- // $FlowFixMe[unclear-type] Unclear type. Using `any` type is not safe.
1846
- module.exports = ((ExportedForwardRef: any): TextInputType);
1158
+ module.exports = TextInput;