react-native-screens 3.20.0 → 3.21.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 (210) hide show
  1. package/README.md +4 -1
  2. package/RNScreens.podspec +1 -1
  3. package/android/build.gradle +24 -6
  4. package/android/src/main/java/com/swmansion/rnscreens/CustomSearchView.kt +4 -0
  5. package/android/src/main/java/com/swmansion/rnscreens/LifecycleHelper.kt +60 -0
  6. package/android/src/main/java/com/swmansion/rnscreens/ScreenStackHeaderConfig.kt +7 -9
  7. package/android/src/main/java/com/swmansion/rnscreens/ScreenStackHeaderConfigViewManager.kt +12 -4
  8. package/android/src/main/java/com/swmansion/rnscreens/ScreenViewManager.kt +10 -0
  9. package/android/src/main/java/com/swmansion/rnscreens/SearchBarManager.kt +32 -8
  10. package/android/src/main/java/com/swmansion/rnscreens/SearchBarView.kt +36 -15
  11. package/android/src/main/java/com/swmansion/rnscreens/events/HeaderAttachedEvent.kt +24 -0
  12. package/android/src/main/java/com/swmansion/rnscreens/events/HeaderDetachedEvent.kt +24 -0
  13. package/android/src/main/java/com/swmansion/rnscreens/events/SearchBarBlurEvent.kt +24 -0
  14. package/android/src/main/java/com/swmansion/rnscreens/events/SearchBarChangeTextEvent.kt +29 -0
  15. package/android/src/main/java/com/swmansion/rnscreens/events/SearchBarCloseEvent.kt +24 -0
  16. package/android/src/main/java/com/swmansion/rnscreens/events/SearchBarFocusEvent.kt +24 -0
  17. package/android/src/main/java/com/swmansion/rnscreens/events/SearchBarOpenEvent.kt +24 -0
  18. package/android/src/main/java/com/swmansion/rnscreens/events/SearchBarSearchButtonPressEvent.kt +26 -0
  19. package/android/src/main/res/base/anim/rns_standard_accelerate_interpolator.xml +6 -0
  20. package/android/src/main/res/v33/anim-v33/rns_default_enter_in.xml +38 -0
  21. package/android/src/main/res/v33/anim-v33/rns_default_enter_out.xml +38 -0
  22. package/android/src/main/res/v33/anim-v33/rns_default_exit_in.xml +38 -0
  23. package/android/src/main/res/v33/anim-v33/rns_default_exit_out.xml +38 -0
  24. package/android/src/paper/java/com/facebook/react/viewmanagers/RNSScreenManagerDelegate.java +15 -0
  25. package/android/src/paper/java/com/facebook/react/viewmanagers/RNSScreenManagerInterface.java +5 -0
  26. package/android/src/paper/java/com/facebook/react/viewmanagers/RNSScreenStackHeaderConfigManagerDelegate.java +3 -0
  27. package/android/src/paper/java/com/facebook/react/viewmanagers/RNSScreenStackHeaderConfigManagerInterface.java +1 -0
  28. package/common/cpp/react/renderer/components/rnscreens/RNSScreenState.h +1 -2
  29. package/ios/RCTImageComponentView+RNSScreenStackHeaderConfig.h +11 -0
  30. package/ios/RCTImageComponentView+RNSScreenStackHeaderConfig.mm +14 -0
  31. package/ios/RNSConvert.h +8 -2
  32. package/ios/RNSConvert.mm +28 -2
  33. package/ios/RNSEnums.h +6 -0
  34. package/ios/RNSFullWindowOverlay.h +5 -5
  35. package/ios/RNSFullWindowOverlay.mm +13 -13
  36. package/ios/RNSScreen.h +14 -6
  37. package/ios/RNSScreen.mm +129 -28
  38. package/ios/RNSScreenContainer.h +2 -2
  39. package/ios/RNSScreenContainer.mm +5 -5
  40. package/ios/RNSScreenNavigationContainer.mm +3 -3
  41. package/ios/RNSScreenStack.h +4 -4
  42. package/ios/RNSScreenStack.mm +62 -23
  43. package/ios/RNSScreenStackHeaderConfig.h +10 -3
  44. package/ios/RNSScreenStackHeaderConfig.mm +138 -81
  45. package/ios/RNSScreenStackHeaderSubview.h +5 -6
  46. package/ios/RNSScreenStackHeaderSubview.mm +20 -11
  47. package/ios/RNSScreenWindowTraits.mm +21 -2
  48. package/ios/RNSSearchBar.h +5 -4
  49. package/ios/RNSSearchBar.mm +87 -12
  50. package/lib/commonjs/TransitionProgressContext.js.map +1 -1
  51. package/lib/commonjs/fabric/FullWindowOverlayNativeComponent.js +0 -5
  52. package/lib/commonjs/fabric/FullWindowOverlayNativeComponent.js.map +1 -1
  53. package/lib/commonjs/fabric/ScreenContainerNativeComponent.js +0 -5
  54. package/lib/commonjs/fabric/ScreenContainerNativeComponent.js.map +1 -1
  55. package/lib/commonjs/fabric/ScreenNativeComponent.js +0 -5
  56. package/lib/commonjs/fabric/ScreenNativeComponent.js.map +1 -1
  57. package/lib/commonjs/fabric/ScreenNavigationContainerNativeComponent.js +0 -5
  58. package/lib/commonjs/fabric/ScreenNavigationContainerNativeComponent.js.map +1 -1
  59. package/lib/commonjs/fabric/ScreenStackHeaderConfigNativeComponent.js +0 -8
  60. package/lib/commonjs/fabric/ScreenStackHeaderConfigNativeComponent.js.map +1 -1
  61. package/lib/commonjs/fabric/ScreenStackHeaderSubviewNativeComponent.js +0 -8
  62. package/lib/commonjs/fabric/ScreenStackHeaderSubviewNativeComponent.js.map +1 -1
  63. package/lib/commonjs/fabric/ScreenStackNativeComponent.js +0 -5
  64. package/lib/commonjs/fabric/ScreenStackNativeComponent.js.map +1 -1
  65. package/lib/commonjs/fabric/SearchBarNativeComponent.js +7 -7
  66. package/lib/commonjs/fabric/SearchBarNativeComponent.js.map +1 -1
  67. package/lib/commonjs/index.js +8 -1
  68. package/lib/commonjs/index.js.map +1 -1
  69. package/lib/commonjs/index.native.js +51 -10
  70. package/lib/commonjs/index.native.js.map +1 -1
  71. package/lib/commonjs/native-stack/index.js.map +1 -1
  72. package/lib/commonjs/native-stack/navigators/createNativeStackNavigator.js +18 -16
  73. package/lib/commonjs/native-stack/navigators/createNativeStackNavigator.js.map +1 -1
  74. package/lib/commonjs/native-stack/types.js.map +1 -1
  75. package/lib/commonjs/native-stack/utils/HeaderHeightContext.js.map +1 -1
  76. package/lib/commonjs/native-stack/utils/SafeAreaProviderCompat.js.map +1 -1
  77. package/lib/commonjs/native-stack/utils/getDefaultHeaderHeight.js.map +1 -1
  78. package/lib/commonjs/native-stack/utils/useBackPressSubscription.js.map +1 -1
  79. package/lib/commonjs/native-stack/utils/useHeaderHeight.js.map +1 -1
  80. package/lib/commonjs/native-stack/views/FontProcessor.js +1 -0
  81. package/lib/commonjs/native-stack/views/FontProcessor.js.map +1 -1
  82. package/lib/commonjs/native-stack/views/HeaderConfig.js +3 -1
  83. package/lib/commonjs/native-stack/views/HeaderConfig.js.map +1 -1
  84. package/lib/commonjs/native-stack/views/NativeStackView.js +14 -1
  85. package/lib/commonjs/native-stack/views/NativeStackView.js.map +1 -1
  86. package/lib/commonjs/reanimated/ReanimatedNativeStackScreen.js.map +1 -1
  87. package/lib/commonjs/reanimated/ReanimatedScreen.js.map +1 -1
  88. package/lib/commonjs/reanimated/ReanimatedScreenProvider.js.map +1 -1
  89. package/lib/commonjs/reanimated/ReanimatedTransitionProgressContext.js.map +1 -1
  90. package/lib/commonjs/reanimated/index.js.map +1 -1
  91. package/lib/commonjs/reanimated/useReanimatedTransitionProgress.js.map +1 -1
  92. package/lib/commonjs/types.js.map +1 -1
  93. package/lib/commonjs/useTransitionProgress.js.map +1 -1
  94. package/lib/commonjs/utils.js +8 -1
  95. package/lib/commonjs/utils.js.map +1 -1
  96. package/lib/module/fabric/FullWindowOverlayNativeComponent.js +0 -5
  97. package/lib/module/fabric/FullWindowOverlayNativeComponent.js.map +1 -1
  98. package/lib/module/fabric/ScreenContainerNativeComponent.js +0 -5
  99. package/lib/module/fabric/ScreenContainerNativeComponent.js.map +1 -1
  100. package/lib/module/fabric/ScreenNativeComponent.js +0 -5
  101. package/lib/module/fabric/ScreenNativeComponent.js.map +1 -1
  102. package/lib/module/fabric/ScreenNavigationContainerNativeComponent.js +0 -5
  103. package/lib/module/fabric/ScreenNavigationContainerNativeComponent.js.map +1 -1
  104. package/lib/module/fabric/ScreenStackHeaderConfigNativeComponent.js +0 -6
  105. package/lib/module/fabric/ScreenStackHeaderConfigNativeComponent.js.map +1 -1
  106. package/lib/module/fabric/ScreenStackHeaderSubviewNativeComponent.js +0 -6
  107. package/lib/module/fabric/ScreenStackHeaderSubviewNativeComponent.js.map +1 -1
  108. package/lib/module/fabric/ScreenStackNativeComponent.js +0 -5
  109. package/lib/module/fabric/ScreenStackNativeComponent.js.map +1 -1
  110. package/lib/module/fabric/SearchBarNativeComponent.js +4 -6
  111. package/lib/module/fabric/SearchBarNativeComponent.js.map +1 -1
  112. package/lib/module/index.js +2 -2
  113. package/lib/module/index.js.map +1 -1
  114. package/lib/module/index.native.js +53 -11
  115. package/lib/module/index.native.js.map +1 -1
  116. package/lib/module/native-stack/navigators/createNativeStackNavigator.js +18 -16
  117. package/lib/module/native-stack/navigators/createNativeStackNavigator.js.map +1 -1
  118. package/lib/module/native-stack/types.js.map +1 -1
  119. package/lib/module/native-stack/utils/SafeAreaProviderCompat.js.map +1 -1
  120. package/lib/module/native-stack/utils/getDefaultHeaderHeight.js.map +1 -1
  121. package/lib/module/native-stack/utils/useBackPressSubscription.js.map +1 -1
  122. package/lib/module/native-stack/utils/useHeaderHeight.js.map +1 -1
  123. package/lib/module/native-stack/views/FontProcessor.js +1 -0
  124. package/lib/module/native-stack/views/FontProcessor.js.map +1 -1
  125. package/lib/module/native-stack/views/HeaderConfig.js +3 -1
  126. package/lib/module/native-stack/views/HeaderConfig.js.map +1 -1
  127. package/lib/module/native-stack/views/NativeStackView.js +15 -1
  128. package/lib/module/native-stack/views/NativeStackView.js.map +1 -1
  129. package/lib/module/reanimated/ReanimatedNativeStackScreen.js.map +1 -1
  130. package/lib/module/reanimated/ReanimatedScreen.js.map +1 -1
  131. package/lib/module/reanimated/ReanimatedScreenProvider.js.map +1 -1
  132. package/lib/module/reanimated/useReanimatedTransitionProgress.js.map +1 -1
  133. package/lib/module/types.js.map +1 -1
  134. package/lib/module/useTransitionProgress.js.map +1 -1
  135. package/lib/module/utils.js +6 -0
  136. package/lib/module/utils.js.map +1 -1
  137. package/lib/typescript/TransitionProgressContext.d.ts +1 -1
  138. package/lib/typescript/fabric/FullWindowOverlayNativeComponent.d.ts +6 -0
  139. package/lib/typescript/fabric/ScreenContainerNativeComponent.d.ts +6 -0
  140. package/lib/typescript/fabric/ScreenNativeComponent.d.ts +62 -0
  141. package/lib/typescript/fabric/ScreenNavigationContainerNativeComponent.d.ts +6 -0
  142. package/lib/typescript/fabric/ScreenStackHeaderConfigNativeComponent.d.ts +34 -0
  143. package/lib/typescript/fabric/ScreenStackHeaderSubviewNativeComponent.d.ts +9 -0
  144. package/lib/typescript/fabric/ScreenStackNativeComponent.d.ts +9 -0
  145. package/lib/typescript/fabric/SearchBarNativeComponent.d.ts +46 -0
  146. package/lib/typescript/index.d.ts +3 -3
  147. package/lib/typescript/native-stack/types.d.ts +64 -10
  148. package/lib/typescript/native-stack/utils/SafeAreaProviderCompat.d.ts +1 -1
  149. package/lib/typescript/native-stack/utils/getDefaultHeaderHeight.d.ts +1 -1
  150. package/lib/typescript/native-stack/views/HeaderConfig.d.ts +1 -1
  151. package/lib/typescript/native-stack/views/NativeStackView.d.ts +1 -1
  152. package/lib/typescript/reanimated/ReanimatedNativeStackScreen.d.ts +1 -1
  153. package/lib/typescript/reanimated/ReanimatedScreen.d.ts +1 -1
  154. package/lib/typescript/reanimated/ReanimatedTransitionProgressContext.d.ts +1 -1
  155. package/lib/typescript/types.d.ts +90 -11
  156. package/lib/typescript/useTransitionProgress.d.ts +3 -3
  157. package/lib/typescript/utils.d.ts +1 -0
  158. package/native-stack/README.md +59 -1
  159. package/package.json +11 -14
  160. package/src/fabric/FullWindowOverlayNativeComponent.ts +6 -0
  161. package/src/fabric/ScreenContainerNativeComponent.ts +6 -0
  162. package/src/fabric/ScreenNativeComponent.ts +97 -0
  163. package/src/fabric/ScreenNavigationContainerNativeComponent.ts +9 -0
  164. package/src/fabric/ScreenStackHeaderConfigNativeComponent.ts +43 -0
  165. package/src/fabric/ScreenStackHeaderSubviewNativeComponent.ts +20 -0
  166. package/src/fabric/ScreenStackNativeComponent.ts +12 -0
  167. package/src/fabric/SearchBarNativeComponent.ts +73 -0
  168. package/src/index.native.tsx +109 -14
  169. package/src/index.tsx +5 -3
  170. package/src/native-stack/navigators/createNativeStackNavigator.tsx +23 -19
  171. package/src/native-stack/types.tsx +55 -0
  172. package/src/native-stack/views/FontProcessor.tsx +1 -0
  173. package/src/native-stack/views/HeaderConfig.tsx +3 -1
  174. package/src/native-stack/views/NativeStackView.tsx +14 -2
  175. package/src/types.tsx +84 -2
  176. package/src/utils.ts +6 -0
  177. package/createNativeStackNavigator/README.md +0 -522
  178. package/createNativeStackNavigator/package.json +0 -6
  179. package/lib/commonjs/createNativeStackNavigator.js +0 -374
  180. package/lib/commonjs/createNativeStackNavigator.js.map +0 -1
  181. package/lib/module/createNativeStackNavigator.js +0 -366
  182. package/lib/module/createNativeStackNavigator.js.map +0 -1
  183. package/lib/typescript/createNativeStackNavigator.d.ts +0 -51
  184. package/src/createNativeStackNavigator.tsx +0 -594
  185. package/src/fabric/FullWindowOverlayNativeComponent.js +0 -19
  186. package/src/fabric/ScreenContainerNativeComponent.js +0 -19
  187. package/src/fabric/ScreenNativeComponent.js +0 -97
  188. package/src/fabric/ScreenNavigationContainerNativeComponent.js +0 -19
  189. package/src/fabric/ScreenStackHeaderConfigNativeComponent.js +0 -54
  190. package/src/fabric/ScreenStackHeaderSubviewNativeComponent.js +0 -31
  191. package/src/fabric/ScreenStackNativeComponent.js +0 -23
  192. package/src/fabric/SearchBarNativeComponent.js +0 -62
  193. /package/android/src/main/res/{anim → base/anim}/rns_default_enter_in.xml +0 -0
  194. /package/android/src/main/res/{anim → base/anim}/rns_default_enter_out.xml +0 -0
  195. /package/android/src/main/res/{anim → base/anim}/rns_default_exit_in.xml +0 -0
  196. /package/android/src/main/res/{anim → base/anim}/rns_default_exit_out.xml +0 -0
  197. /package/android/src/main/res/{anim → base/anim}/rns_fade_from_bottom.xml +0 -0
  198. /package/android/src/main/res/{anim → base/anim}/rns_fade_in.xml +0 -0
  199. /package/android/src/main/res/{anim → base/anim}/rns_fade_out.xml +0 -0
  200. /package/android/src/main/res/{anim → base/anim}/rns_fade_to_bottom.xml +0 -0
  201. /package/android/src/main/res/{anim → base/anim}/rns_no_animation_20.xml +0 -0
  202. /package/android/src/main/res/{anim → base/anim}/rns_no_animation_250.xml +0 -0
  203. /package/android/src/main/res/{anim → base/anim}/rns_no_animation_350.xml +0 -0
  204. /package/android/src/main/res/{anim → base/anim}/rns_no_animation_medium.xml +0 -0
  205. /package/android/src/main/res/{anim → base/anim}/rns_slide_in_from_bottom.xml +0 -0
  206. /package/android/src/main/res/{anim → base/anim}/rns_slide_in_from_left.xml +0 -0
  207. /package/android/src/main/res/{anim → base/anim}/rns_slide_in_from_right.xml +0 -0
  208. /package/android/src/main/res/{anim → base/anim}/rns_slide_out_to_bottom.xml +0 -0
  209. /package/android/src/main/res/{anim → base/anim}/rns_slide_out_to_left.xml +0 -0
  210. /package/android/src/main/res/{anim → base/anim}/rns_slide_out_to_right.xml +0 -0
package/README.md CHANGED
@@ -91,11 +91,15 @@ Screens are already integrated with the React Native's most popular navigation l
91
91
 
92
92
  [Fabric](https://reactnative.dev/architecture/fabric-renderer) is React Native's new rendering system.
93
93
 
94
+ - As of [version `3.21.0`](https://github.com/software-mansion/react-native-screens/releases/tag/3.21.0) of this project, Fabric is supported only for react-native 0.72+. Support for lower versions has been dropped.
95
+ - As of [version `3.19.0`](https://github.com/software-mansion/react-native-screens/releases/tag/3.19.0) of this project, Fabric is supported only for react-native 0.71+. Support for lower versions has been dropped.
94
96
  - As of [version `3.18.0`](https://github.com/software-mansion/react-native-screens/releases/tag/3.18.0) of this project, Fabric is supported only for react-native 0.70+. Support for lower versions has been dropped.
95
97
  - As of [version `3.14.0`](https://github.com/software-mansion/react-native-screens/releases/tag/3.14.0) of this project, Fabric is supported only for react-native 0.69+. Support for lower versions has been dropped.
96
98
 
97
99
  | version | react-native version |
98
100
  | ------- | -------------------- |
101
+ | 3.21.0+ | 0.72.0+ |
102
+ | 3.19.0+ | 0.71.0+ |
99
103
  | 3.18.0+ | 0.70.0+ |
100
104
  | 3.14.0+ | 0.69.0+ |
101
105
 
@@ -153,7 +157,6 @@ To take advantage of the native stack navigator primitive for React Navigation t
153
157
 
154
158
  - for React Navigation >= v6 to the [Native Stack Navigator part of React Navigation documentation](https://reactnavigation.org/docs/native-stack-navigator)
155
159
  - for React Navigation v5 to the [README in react-native-screens/native-stack](https://github.com/software-mansion/react-native-screens/tree/main/native-stack)
156
- - for older versions to the [README in react-native-screens/createNativeStackNavigator](https://github.com/software-mansion/react-native-screens/tree/main/createNativeStackNavigator)
157
160
 
158
161
  ## `FullWindowOverlay`
159
162
 
package/RNScreens.podspec CHANGED
@@ -26,7 +26,7 @@ Pod::Spec.new do |s|
26
26
  "CLANG_CXX_LANGUAGE_STANDARD" => "c++17",
27
27
  }
28
28
  s.platforms = { ios: '11.0', tvos: '11.0' }
29
- s.compiler_flags = folly_compiler_flags + ' ' + '-DRN_FABRIC_ENABLED'
29
+ s.compiler_flags = folly_compiler_flags + ' ' + '-DRCT_NEW_ARCH_ENABLED'
30
30
  s.source_files = 'ios/**/*.{h,m,mm,cpp}'
31
31
  s.requires_arc = true
32
32
 
@@ -1,4 +1,10 @@
1
1
  buildscript {
2
+ ext {
3
+ rnsDefaultTargetSdkVersion = 31
4
+ rnsDefaultCompileSdkVersion = 31
5
+ rnsDefaultMinSdkVersion = 21
6
+ rnsDefaultKotlinVersion = '1.6.21'
7
+ }
2
8
  ext.safeExtGet = {prop, fallback ->
3
9
  rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
4
10
  }
@@ -8,7 +14,7 @@ buildscript {
8
14
  }
9
15
  dependencies {
10
16
  classpath('com.android.tools.build:gradle:4.2.2')
11
- classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:${safeExtGet('kotlinVersion', '1.6.21')}"
17
+ classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:${safeExtGet('kotlinVersion', rnsDefaultKotlinVersion)}"
12
18
  classpath "com.diffplug.spotless:spotless-plugin-gradle:5.15.0"
13
19
  }
14
20
  }
@@ -38,7 +44,11 @@ def reactNativeArchitectures() {
38
44
  }
39
45
 
40
46
  android {
41
- compileSdkVersion safeExtGet('compileSdkVersion', 28)
47
+ compileSdkVersion safeExtGet('compileSdkVersion', rnsDefaultCompileSdkVersion)
48
+ def agpVersion = com.android.Version.ANDROID_GRADLE_PLUGIN_VERSION
49
+ if (agpVersion.tokenize('.')[0].toInteger() >= 7) {
50
+ namespace "com.swmansion.rnscreens"
51
+ }
42
52
 
43
53
  // Used to override the NDK path/version on internal CI or by allowing
44
54
  // users to customize the NDK path/version from their root project (e.g. for M1 support)
@@ -50,8 +60,8 @@ android {
50
60
  }
51
61
 
52
62
  defaultConfig {
53
- minSdkVersion safeExtGet('minSdkVersion', 21)
54
- targetSdkVersion safeExtGet('targetSdkVersion', 22)
63
+ minSdkVersion safeExtGet('minSdkVersion', rnsDefaultMinSdkVersion)
64
+ targetSdkVersion safeExtGet('targetSdkVersion', rnsDefaultTargetSdkVersion)
55
65
  versionCode 1
56
66
  versionName "1.0"
57
67
  buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString()
@@ -68,12 +78,13 @@ android {
68
78
  }
69
79
  packagingOptions {
70
80
  // For some reason gradle only complains about the duplicated version of libreact_render libraries
71
- // while there are more libraries copied in intermediates folder of the lib build directory, we exlude
81
+ // while there are more libraries copied in intermediates folder of the lib build directory, we exclude
72
82
  // only the ones that make the build fail (ideally we should only include librnscreens_modules but we
73
- // are only allowed to specify exlude patterns)
83
+ // are only allowed to specify exclude patterns)
74
84
  exclude "**/libreact_render*.so"
75
85
  }
76
86
  sourceSets.main {
87
+ ext.androidResDir = "src/main/res"
77
88
  java {
78
89
  if (isNewArchitectureEnabled()) {
79
90
  srcDirs += [
@@ -87,6 +98,13 @@ android {
87
98
  }
88
99
 
89
100
  }
101
+ res {
102
+ if (safeExtGet('compileSdkVersion', rnsDefaultCompileSdkVersion) >= 33) {
103
+ srcDirs = ["${androidResDir}/base", "${androidResDir}/v33"]
104
+ } else {
105
+ srcDirs = ["${androidResDir}/base"]
106
+ }
107
+ }
90
108
  }
91
109
  }
92
110
 
@@ -36,6 +36,10 @@ class CustomSearchView(context: Context, fragment: Fragment) : SearchView(contex
36
36
  requestFocusFromTouch()
37
37
  }
38
38
 
39
+ fun clearText() = setQuery("", false)
40
+
41
+ fun setText(text: String) = setQuery(text, false)
42
+
39
43
  override fun setOnCloseListener(listener: OnCloseListener?) {
40
44
  mCustomOnCloseListener = listener
41
45
  }
@@ -0,0 +1,60 @@
1
+ package com.swmansion.rnscreens
2
+
3
+ import android.view.View
4
+ import androidx.fragment.app.Fragment
5
+ import androidx.lifecycle.Lifecycle
6
+ import androidx.lifecycle.LifecycleObserver
7
+
8
+ class LifecycleHelper {
9
+ private val mViewToLifecycleMap: MutableMap<View, Lifecycle> = HashMap()
10
+ private val mRegisterOnLayoutChange: View.OnLayoutChangeListener = object : View.OnLayoutChangeListener {
11
+ override fun onLayoutChange(
12
+ view: View,
13
+ i: Int,
14
+ i1: Int,
15
+ i2: Int,
16
+ i3: Int,
17
+ i4: Int,
18
+ i5: Int,
19
+ i6: Int,
20
+ i7: Int
21
+ ) {
22
+ registerViewWithLifecycleOwner(view)
23
+ view.removeOnLayoutChangeListener(this)
24
+ }
25
+ }
26
+
27
+ private fun registerViewWithLifecycleOwner(view: View) {
28
+ val parent = findNearestScreenFragmentAncestor(view)
29
+ if (parent != null && view is LifecycleObserver) {
30
+ val lifecycle = parent.lifecycle
31
+ lifecycle.addObserver((view as LifecycleObserver))
32
+ mViewToLifecycleMap[view] = lifecycle
33
+ }
34
+ }
35
+
36
+ fun <T> register(view: T) where T : View, T : LifecycleObserver? {
37
+ // we need to wait until view is mounted in the hierarchy as this method is called only at the
38
+ // moment of the view creation. In order to register lifecycle observer we need to find ancestor
39
+ // of type Screen and this can only happen when the view is properly attached. We rely on
40
+ // Android's onLayout callback being triggered when the view gets added to the hierarchy and
41
+ // only then we attempt to locate lifecycle owner ancestor.
42
+ view.addOnLayoutChangeListener(mRegisterOnLayoutChange)
43
+ }
44
+
45
+ fun <T> unregister(view: T) where T : View, T : LifecycleObserver? {
46
+ mViewToLifecycleMap[view]?.removeObserver(view)
47
+ }
48
+
49
+ companion object {
50
+ fun findNearestScreenFragmentAncestor(view: View): Fragment? {
51
+ var parent = view.parent
52
+ while (parent != null && parent !is Screen) {
53
+ parent = parent.parent
54
+ }
55
+ return if (parent != null) {
56
+ (parent as Screen).fragment
57
+ } else null
58
+ }
59
+ }
60
+ }
@@ -16,9 +16,10 @@ import androidx.fragment.app.Fragment
16
16
  import com.facebook.react.ReactApplication
17
17
  import com.facebook.react.bridge.JSApplicationIllegalArgumentException
18
18
  import com.facebook.react.bridge.ReactContext
19
- import com.facebook.react.bridge.WritableMap
20
- import com.facebook.react.uimanager.events.RCTEventEmitter
19
+ import com.facebook.react.uimanager.UIManagerHelper
21
20
  import com.facebook.react.views.text.ReactTypefaceUtils
21
+ import com.swmansion.rnscreens.events.HeaderAttachedEvent
22
+ import com.swmansion.rnscreens.events.HeaderDetachedEvent
22
23
 
23
24
  class ScreenStackHeaderConfig(context: Context) : ViewGroup(context) {
24
25
  private val mConfigSubviews = ArrayList<ScreenStackHeaderSubview>(3)
@@ -64,11 +65,6 @@ class ScreenStackHeaderConfig(context: Context) : ViewGroup(context) {
64
65
  }
65
66
  }
66
67
 
67
- private fun sendEvent(eventName: String, eventContent: WritableMap?) {
68
- (context as ReactContext).getJSModule(RCTEventEmitter::class.java)
69
- ?.receiveEvent(id, eventName, eventContent)
70
- }
71
-
72
68
  override fun onLayout(changed: Boolean, l: Int, t: Int, r: Int, b: Int) {
73
69
  // no-op
74
70
  }
@@ -80,7 +76,8 @@ class ScreenStackHeaderConfig(context: Context) : ViewGroup(context) {
80
76
  override fun onAttachedToWindow() {
81
77
  super.onAttachedToWindow()
82
78
  mIsAttachedToWindow = true
83
- sendEvent("onAttached", null)
79
+ UIManagerHelper.getEventDispatcherForReactTag(context as ReactContext, id)
80
+ ?.dispatchEvent(HeaderAttachedEvent(id))
84
81
  // we want to save the top inset before the status bar can be hidden, which would resolve in
85
82
  // inset being 0
86
83
  if (headerTopInset == null) {
@@ -96,7 +93,8 @@ class ScreenStackHeaderConfig(context: Context) : ViewGroup(context) {
96
93
  override fun onDetachedFromWindow() {
97
94
  super.onDetachedFromWindow()
98
95
  mIsAttachedToWindow = false
99
- sendEvent("onDetached", null)
96
+ UIManagerHelper.getEventDispatcherForReactTag(context as ReactContext, id)
97
+ ?.dispatchEvent(HeaderDetachedEvent(id))
100
98
  }
101
99
 
102
100
  private val screen: Screen?
@@ -11,6 +11,8 @@ import com.facebook.react.uimanager.ViewManagerDelegate
11
11
  import com.facebook.react.uimanager.annotations.ReactProp
12
12
  import com.facebook.react.viewmanagers.RNSScreenStackHeaderConfigManagerDelegate
13
13
  import com.facebook.react.viewmanagers.RNSScreenStackHeaderConfigManagerInterface
14
+ import com.swmansion.rnscreens.events.HeaderAttachedEvent
15
+ import com.swmansion.rnscreens.events.HeaderDetachedEvent
14
16
  import javax.annotation.Nonnull
15
17
 
16
18
  @ReactModule(name = ScreenStackHeaderConfigViewManager.REACT_CLASS)
@@ -133,10 +135,12 @@ class ScreenStackHeaderConfigViewManager : ViewGroupManager<ScreenStackHeaderCon
133
135
  }
134
136
 
135
137
  override fun getExportedCustomDirectEventTypeConstants(): Map<String, Any>? {
136
- return MapBuilder.builder<String, Any>()
137
- .put("onAttached", MapBuilder.of("registrationName", "onAttached"))
138
- .put("onDetached", MapBuilder.of("registrationName", "onDetached"))
139
- .build()
138
+ return MapBuilder.of(
139
+ HeaderAttachedEvent.EVENT_NAME,
140
+ MapBuilder.of("registrationName", "onAttached"),
141
+ HeaderDetachedEvent.EVENT_NAME,
142
+ MapBuilder.of("registrationName", "onDetached"),
143
+ )
140
144
  }
141
145
 
142
146
  protected override fun getDelegate(): ViewManagerDelegate<ScreenStackHeaderConfig> = mDelegate
@@ -162,6 +166,10 @@ class ScreenStackHeaderConfigViewManager : ViewGroupManager<ScreenStackHeaderCon
162
166
  logNotAvailable("backTitleFontSize")
163
167
  }
164
168
 
169
+ override fun setBackTitleVisible(view: ScreenStackHeaderConfig?, value: Boolean) {
170
+ logNotAvailable("backTitleVisible")
171
+ }
172
+
165
173
  override fun setLargeTitle(view: ScreenStackHeaderConfig?, value: Boolean) {
166
174
  logNotAvailable("largeTitle")
167
175
  }
@@ -156,6 +156,16 @@ class ScreenViewManager : ViewGroupManager<Screen>(), RNSScreenManagerInterface<
156
156
 
157
157
  override fun setSwipeDirection(view: Screen?, value: String?) = Unit
158
158
 
159
+ override fun setSheetAllowedDetents(view: Screen, value: String?) = Unit
160
+
161
+ override fun setSheetLargestUndimmedDetent(view: Screen, value: String?) = Unit
162
+
163
+ override fun setSheetGrabberVisible(view: Screen?, value: Boolean) = Unit
164
+
165
+ override fun setSheetCornerRadius(view: Screen?, value: Float) = Unit
166
+
167
+ override fun setSheetExpandsWhenScrolledToEdge(view: Screen?, value: Boolean) = Unit
168
+
159
169
  override fun getExportedCustomDirectEventTypeConstants(): MutableMap<String, Any> {
160
170
  return MapBuilder.of(
161
171
  ScreenDismissedEvent.EVENT_NAME,
@@ -1,11 +1,18 @@
1
1
  package com.swmansion.rnscreens
2
2
 
3
3
  import com.facebook.react.bridge.JSApplicationIllegalArgumentException
4
+ import com.facebook.react.bridge.ReadableArray
4
5
  import com.facebook.react.common.MapBuilder
5
6
  import com.facebook.react.module.annotations.ReactModule
6
7
  import com.facebook.react.uimanager.ThemedReactContext
7
8
  import com.facebook.react.uimanager.ViewGroupManager
8
9
  import com.facebook.react.uimanager.annotations.ReactProp
10
+ import com.swmansion.rnscreens.events.SearchBarBlurEvent
11
+ import com.swmansion.rnscreens.events.SearchBarChangeTextEvent
12
+ import com.swmansion.rnscreens.events.SearchBarCloseEvent
13
+ import com.swmansion.rnscreens.events.SearchBarFocusEvent
14
+ import com.swmansion.rnscreens.events.SearchBarOpenEvent
15
+ import com.swmansion.rnscreens.events.SearchBarSearchButtonPressEvent
9
16
 
10
17
  @ReactModule(name = SearchBarManager.REACT_CLASS)
11
18
  class SearchBarManager : ViewGroupManager<SearchBarView>() {
@@ -90,15 +97,32 @@ class SearchBarManager : ViewGroupManager<SearchBarView>() {
90
97
  view.shouldShowHintSearchIcon = shouldShowHintSearchIcon ?: true
91
98
  }
92
99
 
100
+ override fun receiveCommand(root: SearchBarView, commandId: String?, args: ReadableArray?) {
101
+ when (commandId) {
102
+ "focus" -> root.handleFocusJsRequest()
103
+ "blur" -> root.handleBlurJsRequest()
104
+ "clearText" -> root.handleClearTextJsRequest()
105
+ "toggleCancelButton" -> root.handleToggleCancelButtonJsRequest(false) // just a dummy argument
106
+ "setText" -> root.handleSetTextJsRequest(args?.getString(0))
107
+ else -> throw JSApplicationIllegalArgumentException("Unsupported native command received: $commandId")
108
+ }
109
+ }
110
+
93
111
  override fun getExportedCustomDirectEventTypeConstants(): Map<String, Any>? {
94
- return MapBuilder.builder<String, Any>()
95
- .put("onChangeText", MapBuilder.of("registrationName", "onChangeText"))
96
- .put("onSearchButtonPress", MapBuilder.of("registrationName", "onSearchButtonPress"))
97
- .put("onFocus", MapBuilder.of("registrationName", "onFocus"))
98
- .put("onBlur", MapBuilder.of("registrationName", "onBlur"))
99
- .put("onClose", MapBuilder.of("registrationName", "onClose"))
100
- .put("onOpen", MapBuilder.of("registrationName", "onOpen"))
101
- .build()
112
+ return MapBuilder.of(
113
+ SearchBarBlurEvent.EVENT_NAME,
114
+ MapBuilder.of("registrationName", "onBlur"),
115
+ SearchBarChangeTextEvent.EVENT_NAME,
116
+ MapBuilder.of("registrationName", "onChangeText"),
117
+ SearchBarCloseEvent.EVENT_NAME,
118
+ MapBuilder.of("registrationName", "onClose"),
119
+ SearchBarFocusEvent.EVENT_NAME,
120
+ MapBuilder.of("registrationName", "onFocus"),
121
+ SearchBarOpenEvent.EVENT_NAME,
122
+ MapBuilder.of("registrationName", "onOpen"),
123
+ SearchBarSearchButtonPressEvent.EVENT_NAME,
124
+ MapBuilder.of("registrationName", "onSearchButtonPress"),
125
+ )
102
126
  }
103
127
 
104
128
  companion object {
@@ -3,11 +3,17 @@ package com.swmansion.rnscreens
3
3
  import android.annotation.SuppressLint
4
4
  import android.text.InputType
5
5
  import androidx.appcompat.widget.SearchView
6
- import com.facebook.react.bridge.Arguments
7
6
  import com.facebook.react.bridge.ReactContext
8
- import com.facebook.react.bridge.WritableMap
9
- import com.facebook.react.uimanager.events.RCTEventEmitter
7
+ import com.facebook.react.uimanager.UIManagerHelper
8
+ import com.facebook.react.uimanager.events.Event
9
+ import com.facebook.react.uimanager.events.EventDispatcher
10
10
  import com.facebook.react.views.view.ReactViewGroup
11
+ import com.swmansion.rnscreens.events.SearchBarBlurEvent
12
+ import com.swmansion.rnscreens.events.SearchBarChangeTextEvent
13
+ import com.swmansion.rnscreens.events.SearchBarCloseEvent
14
+ import com.swmansion.rnscreens.events.SearchBarFocusEvent
15
+ import com.swmansion.rnscreens.events.SearchBarOpenEvent
16
+ import com.swmansion.rnscreens.events.SearchBarSearchButtonPressEvent
11
17
 
12
18
  @SuppressLint("ViewConstructor")
13
19
  class SearchBarView(reactContext: ReactContext?) : ReactViewGroup(reactContext) {
@@ -95,32 +101,47 @@ class SearchBarView(reactContext: ReactContext?) : ReactViewGroup(reactContext)
95
101
  }
96
102
 
97
103
  private fun handleTextChange(newText: String?) {
98
- val event = Arguments.createMap()
99
- event.putString("text", newText)
100
- sendEvent("onChangeText", event)
104
+ sendEvent(SearchBarChangeTextEvent(id, newText))
101
105
  }
102
106
 
103
107
  private fun handleFocusChange(hasFocus: Boolean) {
104
- sendEvent(if (hasFocus) "onFocus" else "onBlur", null)
108
+ sendEvent(if (hasFocus) SearchBarFocusEvent(id) else SearchBarBlurEvent(id))
105
109
  }
106
110
 
107
111
  private fun handleClose() {
108
- sendEvent("onClose", null)
112
+ sendEvent(SearchBarCloseEvent(id))
109
113
  }
110
114
 
111
115
  private fun handleOpen() {
112
- sendEvent("onOpen", null)
116
+ sendEvent(SearchBarOpenEvent(id))
113
117
  }
114
118
 
115
119
  private fun handleTextSubmit(newText: String?) {
116
- val event = Arguments.createMap()
117
- event.putString("text", newText)
118
- sendEvent("onSearchButtonPress", event)
120
+ sendEvent(SearchBarSearchButtonPressEvent(id, newText))
119
121
  }
120
122
 
121
- private fun sendEvent(eventName: String, eventContent: WritableMap?) {
122
- (context as ReactContext).getJSModule(RCTEventEmitter::class.java)
123
- ?.receiveEvent(id, eventName, eventContent)
123
+ private fun sendEvent(event: Event<*>) {
124
+ val eventDispatcher: EventDispatcher? =
125
+ UIManagerHelper.getEventDispatcherForReactTag(context as ReactContext, id)
126
+ eventDispatcher?.dispatchEvent(event)
127
+ }
128
+
129
+ fun handleClearTextJsRequest() {
130
+ screenStackFragment?.searchView?.clearText()
131
+ }
132
+
133
+ fun handleFocusJsRequest() {
134
+ screenStackFragment?.searchView?.focus()
135
+ }
136
+
137
+ fun handleBlurJsRequest() {
138
+ screenStackFragment?.searchView?.clearFocus()
139
+ }
140
+
141
+ fun handleToggleCancelButtonJsRequest(flag: Boolean) = Unit
142
+
143
+ fun handleSetTextJsRequest(text: String?) {
144
+ text?.let { screenStackFragment?.searchView?.setText(it) }
124
145
  }
125
146
 
126
147
  enum class SearchBarAutoCapitalize {
@@ -0,0 +1,24 @@
1
+ package com.swmansion.rnscreens.events
2
+
3
+ import com.facebook.react.bridge.Arguments
4
+ import com.facebook.react.uimanager.events.Event
5
+ import com.facebook.react.uimanager.events.RCTEventEmitter
6
+
7
+ class HeaderAttachedEvent(viewId: Int) : Event<ScreenAppearEvent>(viewId) {
8
+ override fun getEventName(): String {
9
+ return EVENT_NAME
10
+ }
11
+
12
+ override fun getCoalescingKey(): Short {
13
+ // All events for a given view can be coalesced.
14
+ return 0
15
+ }
16
+
17
+ override fun dispatch(rctEventEmitter: RCTEventEmitter) {
18
+ rctEventEmitter.receiveEvent(viewTag, eventName, Arguments.createMap())
19
+ }
20
+
21
+ companion object {
22
+ const val EVENT_NAME = "topAttached"
23
+ }
24
+ }
@@ -0,0 +1,24 @@
1
+ package com.swmansion.rnscreens.events
2
+
3
+ import com.facebook.react.bridge.Arguments
4
+ import com.facebook.react.uimanager.events.Event
5
+ import com.facebook.react.uimanager.events.RCTEventEmitter
6
+
7
+ class HeaderDetachedEvent(viewId: Int) : Event<ScreenAppearEvent>(viewId) {
8
+ override fun getEventName(): String {
9
+ return EVENT_NAME
10
+ }
11
+
12
+ override fun getCoalescingKey(): Short {
13
+ // All events for a given view can be coalesced.
14
+ return 0
15
+ }
16
+
17
+ override fun dispatch(rctEventEmitter: RCTEventEmitter) {
18
+ rctEventEmitter.receiveEvent(viewTag, eventName, Arguments.createMap())
19
+ }
20
+
21
+ companion object {
22
+ const val EVENT_NAME = "topDetached"
23
+ }
24
+ }
@@ -0,0 +1,24 @@
1
+ package com.swmansion.rnscreens.events
2
+
3
+ import com.facebook.react.bridge.Arguments
4
+ import com.facebook.react.uimanager.events.Event
5
+ import com.facebook.react.uimanager.events.RCTEventEmitter
6
+
7
+ class SearchBarBlurEvent(viewId: Int) : Event<ScreenAppearEvent>(viewId) {
8
+ override fun getEventName(): String {
9
+ return EVENT_NAME
10
+ }
11
+
12
+ override fun getCoalescingKey(): Short {
13
+ // All events for a given view can be coalesced.
14
+ return 0
15
+ }
16
+
17
+ override fun dispatch(rctEventEmitter: RCTEventEmitter) {
18
+ rctEventEmitter.receiveEvent(viewTag, eventName, Arguments.createMap())
19
+ }
20
+
21
+ companion object {
22
+ const val EVENT_NAME = "topBlur"
23
+ }
24
+ }
@@ -0,0 +1,29 @@
1
+ package com.swmansion.rnscreens.events
2
+
3
+ import com.facebook.react.bridge.Arguments
4
+ import com.facebook.react.uimanager.events.Event
5
+ import com.facebook.react.uimanager.events.RCTEventEmitter
6
+
7
+ class SearchBarChangeTextEvent(
8
+ viewId: Int,
9
+ private val text: String?,
10
+ ) : Event<ScreenAppearEvent>(viewId) {
11
+ override fun getEventName(): String {
12
+ return EVENT_NAME
13
+ }
14
+
15
+ override fun getCoalescingKey(): Short {
16
+ // All events for a given view can be coalesced.
17
+ return 0
18
+ }
19
+
20
+ override fun dispatch(rctEventEmitter: RCTEventEmitter) {
21
+ val map = Arguments.createMap()
22
+ map.putString("text", text)
23
+ rctEventEmitter.receiveEvent(viewTag, eventName, map)
24
+ }
25
+
26
+ companion object {
27
+ const val EVENT_NAME = "topChangeText"
28
+ }
29
+ }
@@ -0,0 +1,24 @@
1
+ package com.swmansion.rnscreens.events
2
+
3
+ import com.facebook.react.bridge.Arguments
4
+ import com.facebook.react.uimanager.events.Event
5
+ import com.facebook.react.uimanager.events.RCTEventEmitter
6
+
7
+ class SearchBarCloseEvent(viewId: Int) : Event<ScreenAppearEvent>(viewId) {
8
+ override fun getEventName(): String {
9
+ return EVENT_NAME
10
+ }
11
+
12
+ override fun getCoalescingKey(): Short {
13
+ // All events for a given view can be coalesced.
14
+ return 0
15
+ }
16
+
17
+ override fun dispatch(rctEventEmitter: RCTEventEmitter) {
18
+ rctEventEmitter.receiveEvent(viewTag, eventName, Arguments.createMap())
19
+ }
20
+
21
+ companion object {
22
+ const val EVENT_NAME = "topClose"
23
+ }
24
+ }
@@ -0,0 +1,24 @@
1
+ package com.swmansion.rnscreens.events
2
+
3
+ import com.facebook.react.bridge.Arguments
4
+ import com.facebook.react.uimanager.events.Event
5
+ import com.facebook.react.uimanager.events.RCTEventEmitter
6
+
7
+ class SearchBarFocusEvent(viewId: Int) : Event<ScreenAppearEvent>(viewId) {
8
+ override fun getEventName(): String {
9
+ return EVENT_NAME
10
+ }
11
+
12
+ override fun getCoalescingKey(): Short {
13
+ // All events for a given view can be coalesced.
14
+ return 0
15
+ }
16
+
17
+ override fun dispatch(rctEventEmitter: RCTEventEmitter) {
18
+ rctEventEmitter.receiveEvent(viewTag, eventName, Arguments.createMap())
19
+ }
20
+
21
+ companion object {
22
+ const val EVENT_NAME = "topFocus"
23
+ }
24
+ }
@@ -0,0 +1,24 @@
1
+ package com.swmansion.rnscreens.events
2
+
3
+ import com.facebook.react.bridge.Arguments
4
+ import com.facebook.react.uimanager.events.Event
5
+ import com.facebook.react.uimanager.events.RCTEventEmitter
6
+
7
+ class SearchBarOpenEvent(viewId: Int) : Event<ScreenAppearEvent>(viewId) {
8
+ override fun getEventName(): String {
9
+ return EVENT_NAME
10
+ }
11
+
12
+ override fun getCoalescingKey(): Short {
13
+ // All events for a given view can be coalesced.
14
+ return 0
15
+ }
16
+
17
+ override fun dispatch(rctEventEmitter: RCTEventEmitter) {
18
+ rctEventEmitter.receiveEvent(viewTag, eventName, Arguments.createMap())
19
+ }
20
+
21
+ companion object {
22
+ const val EVENT_NAME = "topOpen"
23
+ }
24
+ }
@@ -0,0 +1,26 @@
1
+ package com.swmansion.rnscreens.events
2
+
3
+ import com.facebook.react.bridge.Arguments
4
+ import com.facebook.react.uimanager.events.Event
5
+ import com.facebook.react.uimanager.events.RCTEventEmitter
6
+
7
+ class SearchBarSearchButtonPressEvent(viewId: Int, private val text: String?) : Event<ScreenAppearEvent>(viewId) {
8
+ override fun getEventName(): String {
9
+ return EVENT_NAME
10
+ }
11
+
12
+ override fun getCoalescingKey(): Short {
13
+ // All events for a given view can be coalesced.
14
+ return 0
15
+ }
16
+
17
+ override fun dispatch(rctEventEmitter: RCTEventEmitter) {
18
+ val map = Arguments.createMap()
19
+ map.putString("text", text)
20
+ rctEventEmitter.receiveEvent(viewTag, eventName, map)
21
+ }
22
+
23
+ companion object {
24
+ const val EVENT_NAME = "topSearchButtonPress"
25
+ }
26
+ }
@@ -0,0 +1,6 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <pathInterpolator xmlns:android="http://schemas.android.com/apk/res/android"
3
+ android:controlX1="0.3"
4
+ android:controlY1="0"
5
+ android:controlX2="1"
6
+ android:controlY2="1"/>