react-native-monflowts 0.5.1 → 0.5.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (245) hide show
  1. package/README.md +37 -3
  2. package/android/build.gradle +1 -0
  3. package/android/src/main/java/com/monflowts/MonflowtsNavigationModule.kt +43 -0
  4. package/android/src/main/java/com/monflowts/MonflowtsPackage.kt +10 -1
  5. package/android/src/main/java/com/monflowts/MonflowtsStackView.kt +443 -0
  6. package/android/src/main/java/com/monflowts/MonflowtsStackViewManager.kt +70 -0
  7. package/ios/MonflowtsNavigationBridge.m +10 -0
  8. package/ios/MonflowtsNavigationModule.swift +28 -0
  9. package/ios/MonflowtsStackBridge.m +17 -0
  10. package/ios/MonflowtsStackUIView.swift +409 -0
  11. package/ios/MonflowtsStackViewManager.swift +14 -0
  12. package/lib/module/HubContent.js +259 -219
  13. package/lib/module/HubContent.js.map +1 -1
  14. package/lib/module/MonflowtsHub.js +42 -3
  15. package/lib/module/MonflowtsHub.js.map +1 -1
  16. package/lib/module/api/mutations.js +4 -0
  17. package/lib/module/api/mutations.js.map +1 -1
  18. package/lib/module/api/queries.js +9 -3
  19. package/lib/module/api/queries.js.map +1 -1
  20. package/lib/module/components/AbandonPolicyNotice.js +3 -2
  21. package/lib/module/components/AbandonPolicyNotice.js.map +1 -1
  22. package/lib/module/components/CoinFlyOverlay.js +27 -20
  23. package/lib/module/components/CoinFlyOverlay.js.map +1 -1
  24. package/lib/module/components/GameRulesModal.js +8 -6
  25. package/lib/module/components/GameRulesModal.js.map +1 -1
  26. package/lib/module/components/HypeCallout.js +5 -5
  27. package/lib/module/components/HypeCallout.js.map +1 -1
  28. package/lib/module/components/InsufficientFundsOverlay.js +2 -1
  29. package/lib/module/components/InsufficientFundsOverlay.js.map +1 -1
  30. package/lib/module/components/JackpotNearMiss.js +3 -2
  31. package/lib/module/components/JackpotNearMiss.js.map +1 -1
  32. package/lib/module/components/JackpotTeaser.js +2 -1
  33. package/lib/module/components/JackpotTeaser.js.map +1 -1
  34. package/lib/module/components/QuitConfirmModal.js +3 -2
  35. package/lib/module/components/QuitConfirmModal.js.map +1 -1
  36. package/lib/module/components/SessionTimer.js +3 -2
  37. package/lib/module/components/SessionTimer.js.map +1 -1
  38. package/lib/module/components/ShopArtView.js +105 -0
  39. package/lib/module/components/ShopArtView.js.map +1 -0
  40. package/lib/module/components/SideDemoTab.js +20 -2
  41. package/lib/module/components/SideDemoTab.js.map +1 -1
  42. package/lib/module/components/StakeInput.js +3 -2
  43. package/lib/module/components/StakeInput.js.map +1 -1
  44. package/lib/module/content.js.map +1 -1
  45. package/lib/module/hooks/useAvailableGames.js +7 -2
  46. package/lib/module/hooks/useAvailableGames.js.map +1 -1
  47. package/lib/module/hooks/useLeaderboard.js.map +1 -1
  48. package/lib/module/hooks/usePlayGame.js +11 -5
  49. package/lib/module/hooks/usePlayGame.js.map +1 -1
  50. package/lib/module/hooks/useRaffleDrawState.js +4 -1
  51. package/lib/module/hooks/useRaffleDrawState.js.map +1 -1
  52. package/lib/module/index.js +15 -0
  53. package/lib/module/index.js.map +1 -1
  54. package/lib/module/navigation/NativeStackView.js +5 -0
  55. package/lib/module/navigation/NativeStackView.js.map +1 -0
  56. package/lib/module/navigation/Navigator.js +250 -0
  57. package/lib/module/navigation/Navigator.js.map +1 -0
  58. package/lib/module/navigation/engine.js +466 -0
  59. package/lib/module/navigation/engine.js.map +1 -0
  60. package/lib/module/navigation/hooks.js +29 -0
  61. package/lib/module/navigation/hooks.js.map +1 -0
  62. package/lib/module/navigation/index.js +7 -0
  63. package/lib/module/navigation/index.js.map +1 -0
  64. package/lib/module/navigation/routes.js +111 -0
  65. package/lib/module/navigation/routes.js.map +1 -0
  66. package/lib/module/theme.js +2 -2
  67. package/lib/module/theme.js.map +1 -1
  68. package/lib/module/utils/scale.js +35 -0
  69. package/lib/module/utils/scale.js.map +1 -0
  70. package/lib/module/views/DepositSelect.js +3 -2
  71. package/lib/module/views/DepositSelect.js.map +1 -1
  72. package/lib/module/views/DiceBattle.js +207 -125
  73. package/lib/module/views/DiceBattle.js.map +1 -1
  74. package/lib/module/views/DiceLobby.js +97 -30
  75. package/lib/module/views/DiceLobby.js.map +1 -1
  76. package/lib/module/views/FortuneWheel.js +417 -271
  77. package/lib/module/views/FortuneWheel.js.map +1 -1
  78. package/lib/module/views/Freefall.js +147 -88
  79. package/lib/module/views/Freefall.js.map +1 -1
  80. package/lib/module/views/History.js +3 -2
  81. package/lib/module/views/History.js.map +1 -1
  82. package/lib/module/views/Home.js +1026 -401
  83. package/lib/module/views/Home.js.map +1 -1
  84. package/lib/module/views/Jetstream.js +43 -19
  85. package/lib/module/views/Jetstream.js.map +1 -1
  86. package/lib/module/views/Leaderboard.js +98 -89
  87. package/lib/module/views/Leaderboard.js.map +1 -1
  88. package/lib/module/views/MillionaireHunter.js +743 -569
  89. package/lib/module/views/MillionaireHunter.js.map +1 -1
  90. package/lib/module/views/Minefield.js +40 -18
  91. package/lib/module/views/Minefield.js.map +1 -1
  92. package/lib/module/views/PaymentWebView.js +4 -3
  93. package/lib/module/views/PaymentWebView.js.map +1 -1
  94. package/lib/module/views/PlayerCard.js +3 -2
  95. package/lib/module/views/PlayerCard.js.map +1 -1
  96. package/lib/module/views/Profile.js +3 -2
  97. package/lib/module/views/Profile.js.map +1 -1
  98. package/lib/module/views/RaffleDraw.js +16 -6
  99. package/lib/module/views/RaffleDraw.js.map +1 -1
  100. package/lib/module/views/RevealWin.js +152 -25
  101. package/lib/module/views/RevealWin.js.map +1 -1
  102. package/lib/module/views/Splash.js +3 -2
  103. package/lib/module/views/Splash.js.map +1 -1
  104. package/lib/module/views/Success.js +5 -2
  105. package/lib/module/views/Success.js.map +1 -1
  106. package/lib/module/views/TicketShop.js +1067 -236
  107. package/lib/module/views/TicketShop.js.map +1 -1
  108. package/lib/module/views/TriviaLobby.js +43 -6
  109. package/lib/module/views/TriviaLobby.js.map +1 -1
  110. package/lib/module/views/TriviaMaster.js +23 -18
  111. package/lib/module/views/TriviaMaster.js.map +1 -1
  112. package/lib/module/views/Wallet.js +2 -1
  113. package/lib/module/views/Wallet.js.map +1 -1
  114. package/lib/module/views/WithdrawFlow.js +3 -2
  115. package/lib/module/views/WithdrawFlow.js.map +1 -1
  116. package/lib/module/views/diceDuel.js +44 -0
  117. package/lib/module/views/diceDuel.js.map +1 -0
  118. package/lib/module/views/freefallDrop.js +66 -0
  119. package/lib/module/views/freefallDrop.js.map +1 -0
  120. package/lib/module/views/homeLayout.js +47 -0
  121. package/lib/module/views/homeLayout.js.map +1 -0
  122. package/lib/module/views/launchFeatured.js +43 -0
  123. package/lib/module/views/launchFeatured.js.map +1 -0
  124. package/lib/module/views/leaderboardPhase.js +52 -0
  125. package/lib/module/views/leaderboardPhase.js.map +1 -0
  126. package/lib/module/views/lobbyKit.js +224 -0
  127. package/lib/module/views/lobbyKit.js.map +1 -0
  128. package/lib/module/views/raffleContent.js +11 -0
  129. package/lib/module/views/raffleContent.js.map +1 -0
  130. package/lib/module/views/rafflePhase.js +15 -0
  131. package/lib/module/views/rafflePhase.js.map +1 -0
  132. package/lib/module/views/revealWinHelpers.js +19 -0
  133. package/lib/module/views/revealWinHelpers.js.map +1 -1
  134. package/lib/module/views/shopArtMotion.js +25 -0
  135. package/lib/module/views/shopArtMotion.js.map +1 -0
  136. package/lib/module/views/ticketBundlePresets.js +15 -12
  137. package/lib/module/views/ticketBundlePresets.js.map +1 -1
  138. package/lib/module/views/ticketShopArt.js +391 -0
  139. package/lib/module/views/ticketShopArt.js.map +1 -0
  140. package/lib/module/views/treasureHunt.js +81 -0
  141. package/lib/module/views/treasureHunt.js.map +1 -0
  142. package/lib/module/views/wheelLayout.js +47 -0
  143. package/lib/module/views/wheelLayout.js.map +1 -0
  144. package/lib/typescript/src/HubContent.d.ts.map +1 -1
  145. package/lib/typescript/src/MonflowtsHub.d.ts.map +1 -1
  146. package/lib/typescript/src/api/gameTypes.d.ts +18 -2
  147. package/lib/typescript/src/api/gameTypes.d.ts.map +1 -1
  148. package/lib/typescript/src/api/mutations.d.ts.map +1 -1
  149. package/lib/typescript/src/api/queries.d.ts.map +1 -1
  150. package/lib/typescript/src/api/sdkTypes.d.ts +3 -0
  151. package/lib/typescript/src/api/sdkTypes.d.ts.map +1 -1
  152. package/lib/typescript/src/components/AbandonPolicyNotice.d.ts.map +1 -1
  153. package/lib/typescript/src/components/CoinFlyOverlay.d.ts.map +1 -1
  154. package/lib/typescript/src/components/GameRulesModal.d.ts +1 -0
  155. package/lib/typescript/src/components/GameRulesModal.d.ts.map +1 -1
  156. package/lib/typescript/src/components/HypeCallout.d.ts.map +1 -1
  157. package/lib/typescript/src/components/InsufficientFundsOverlay.d.ts.map +1 -1
  158. package/lib/typescript/src/components/JackpotNearMiss.d.ts.map +1 -1
  159. package/lib/typescript/src/components/JackpotTeaser.d.ts.map +1 -1
  160. package/lib/typescript/src/components/QuitConfirmModal.d.ts.map +1 -1
  161. package/lib/typescript/src/components/SessionTimer.d.ts.map +1 -1
  162. package/lib/typescript/src/components/ShopArtView.d.ts +11 -0
  163. package/lib/typescript/src/components/ShopArtView.d.ts.map +1 -0
  164. package/lib/typescript/src/components/SideDemoTab.d.ts +1 -0
  165. package/lib/typescript/src/components/SideDemoTab.d.ts.map +1 -1
  166. package/lib/typescript/src/components/StakeInput.d.ts.map +1 -1
  167. package/lib/typescript/src/content.d.ts +1 -0
  168. package/lib/typescript/src/content.d.ts.map +1 -1
  169. package/lib/typescript/src/hooks/useAvailableGames.d.ts +3 -0
  170. package/lib/typescript/src/hooks/useAvailableGames.d.ts.map +1 -1
  171. package/lib/typescript/src/hooks/useLeaderboard.d.ts +4 -0
  172. package/lib/typescript/src/hooks/useLeaderboard.d.ts.map +1 -1
  173. package/lib/typescript/src/hooks/usePlayGame.d.ts +1 -1
  174. package/lib/typescript/src/hooks/usePlayGame.d.ts.map +1 -1
  175. package/lib/typescript/src/hooks/useRaffleDrawState.d.ts.map +1 -1
  176. package/lib/typescript/src/index.d.ts +16 -0
  177. package/lib/typescript/src/index.d.ts.map +1 -1
  178. package/lib/typescript/src/navigation/NativeStackView.d.ts +41 -0
  179. package/lib/typescript/src/navigation/NativeStackView.d.ts.map +1 -0
  180. package/lib/typescript/src/navigation/Navigator.d.ts +13 -0
  181. package/lib/typescript/src/navigation/Navigator.d.ts.map +1 -0
  182. package/lib/typescript/src/navigation/engine.d.ts +69 -0
  183. package/lib/typescript/src/navigation/engine.d.ts.map +1 -0
  184. package/lib/typescript/src/navigation/hooks.d.ts +6 -0
  185. package/lib/typescript/src/navigation/hooks.d.ts.map +1 -0
  186. package/lib/typescript/src/navigation/index.d.ts +7 -0
  187. package/lib/typescript/src/navigation/index.d.ts.map +1 -0
  188. package/lib/typescript/src/navigation/routes.d.ts +80 -0
  189. package/lib/typescript/src/navigation/routes.d.ts.map +1 -0
  190. package/lib/typescript/src/types.d.ts +0 -9
  191. package/lib/typescript/src/types.d.ts.map +1 -1
  192. package/lib/typescript/src/utils/scale.d.ts +12 -0
  193. package/lib/typescript/src/utils/scale.d.ts.map +1 -0
  194. package/lib/typescript/src/views/DiceBattle.d.ts.map +1 -1
  195. package/lib/typescript/src/views/DiceLobby.d.ts.map +1 -1
  196. package/lib/typescript/src/views/FortuneWheel.d.ts.map +1 -1
  197. package/lib/typescript/src/views/Freefall.d.ts.map +1 -1
  198. package/lib/typescript/src/views/History.d.ts.map +1 -1
  199. package/lib/typescript/src/views/Home.d.ts +2 -2
  200. package/lib/typescript/src/views/Home.d.ts.map +1 -1
  201. package/lib/typescript/src/views/Jetstream.d.ts.map +1 -1
  202. package/lib/typescript/src/views/Leaderboard.d.ts.map +1 -1
  203. package/lib/typescript/src/views/MillionaireHunter.d.ts.map +1 -1
  204. package/lib/typescript/src/views/Minefield.d.ts.map +1 -1
  205. package/lib/typescript/src/views/PlayerCard.d.ts.map +1 -1
  206. package/lib/typescript/src/views/Profile.d.ts.map +1 -1
  207. package/lib/typescript/src/views/RaffleDraw.d.ts +2 -1
  208. package/lib/typescript/src/views/RaffleDraw.d.ts.map +1 -1
  209. package/lib/typescript/src/views/RevealWin.d.ts.map +1 -1
  210. package/lib/typescript/src/views/Splash.d.ts.map +1 -1
  211. package/lib/typescript/src/views/Success.d.ts.map +1 -1
  212. package/lib/typescript/src/views/TicketShop.d.ts +1 -0
  213. package/lib/typescript/src/views/TicketShop.d.ts.map +1 -1
  214. package/lib/typescript/src/views/TriviaLobby.d.ts.map +1 -1
  215. package/lib/typescript/src/views/TriviaMaster.d.ts.map +1 -1
  216. package/lib/typescript/src/views/Wallet.d.ts.map +1 -1
  217. package/lib/typescript/src/views/diceDuel.d.ts +22 -0
  218. package/lib/typescript/src/views/diceDuel.d.ts.map +1 -0
  219. package/lib/typescript/src/views/freefallDrop.d.ts +19 -0
  220. package/lib/typescript/src/views/freefallDrop.d.ts.map +1 -0
  221. package/lib/typescript/src/views/homeLayout.d.ts +15 -0
  222. package/lib/typescript/src/views/homeLayout.d.ts.map +1 -0
  223. package/lib/typescript/src/views/launchFeatured.d.ts +2 -0
  224. package/lib/typescript/src/views/launchFeatured.d.ts.map +1 -0
  225. package/lib/typescript/src/views/leaderboardPhase.d.ts +6 -0
  226. package/lib/typescript/src/views/leaderboardPhase.d.ts.map +1 -0
  227. package/lib/typescript/src/views/lobbyKit.d.ts +45 -0
  228. package/lib/typescript/src/views/lobbyKit.d.ts.map +1 -0
  229. package/lib/typescript/src/views/raffleContent.d.ts +3 -0
  230. package/lib/typescript/src/views/raffleContent.d.ts.map +1 -0
  231. package/lib/typescript/src/views/rafflePhase.d.ts +9 -0
  232. package/lib/typescript/src/views/rafflePhase.d.ts.map +1 -0
  233. package/lib/typescript/src/views/revealWinHelpers.d.ts +9 -0
  234. package/lib/typescript/src/views/revealWinHelpers.d.ts.map +1 -1
  235. package/lib/typescript/src/views/shopArtMotion.d.ts +13 -0
  236. package/lib/typescript/src/views/shopArtMotion.d.ts.map +1 -0
  237. package/lib/typescript/src/views/ticketBundlePresets.d.ts +3 -17
  238. package/lib/typescript/src/views/ticketBundlePresets.d.ts.map +1 -1
  239. package/lib/typescript/src/views/ticketShopArt.d.ts +27 -0
  240. package/lib/typescript/src/views/ticketShopArt.d.ts.map +1 -0
  241. package/lib/typescript/src/views/treasureHunt.d.ts +29 -0
  242. package/lib/typescript/src/views/treasureHunt.d.ts.map +1 -0
  243. package/lib/typescript/src/views/wheelLayout.d.ts +30 -0
  244. package/lib/typescript/src/views/wheelLayout.d.ts.map +1 -0
  245. package/package.json +1 -1
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # react-native-monflowts
2
2
 
3
- SDK for Monflowts Hub — a collection of interactive mini-games (Millionaire Hunter, Fortune Wheel, Dice, Trivia, Raffle Draw, and more) for React Native apps.
3
+ SDK for Monflowts Hub — a collection of interactive mini-services (Millionaire Hunter, Fortune Wheel, Dice, Trivia, Raffle Draw, and more) for React Native apps.
4
4
 
5
5
  ## Installation
6
6
 
@@ -49,7 +49,7 @@ export default function App() {
49
49
  externalToken={userAuthToken}
50
50
  projectId="monflowts"
51
51
  language="en"
52
- realtimeUrl="https://games-api.example.com"
52
+ realtimeUrl="https://services-api.example.com"
53
53
  />
54
54
  );
55
55
  }
@@ -93,7 +93,8 @@ export default function App() {
93
93
  | `language` | `string` | Yes | — | ISO 639 code of a language enabled in the admin dashboard (`en`, `ar`, `de`, `es`, `fr`, `ha`, `he`, `ig`, `it`, `pcm`, `yo`, `zh`, or any language added later). All text comes from the server; `ar` and `he` render right-to-left. An unavailable language calls `onError` with `code: 'LANGUAGE_UNAVAILABLE'` instead of falling back. |
94
94
  | `mToken` | `string` | No | — | MoniFlow token passed to the NetApps Pay checkout when the player tops up their wallet. |
95
95
  | `realtimeUrl` | `string` | No | — | REST API base URL for one-time-ticket-authenticated realtime wallet and game events. |
96
- | `onExit` | `() => void` | No | — | Called when the user taps "Logout" on the Profile screen. Use this to navigate away from the hub. |
96
+ | `onExit` | `() => void` | No | — | Called when the user taps "Logout" on the Profile screen, or goes back from the first screen. Use this to navigate away from the hub. |
97
+ | `linking` | `{ prefixes: string[] }` | No | — | URL prefixes the SDK may open deep links from. Omit to ignore all links. See [Navigation](#navigation). |
97
98
  | `onError` | `(error: Error \| string) => void` | No | — | Called when session initialization fails. Receives the error. |
98
99
  | `onDepositRequested` | `() => void` | No | — | Called when the user initiates a deposit. |
99
100
  | `onWithdrawRequested` | `() => void` | No | — | Called when the user initiates a withdrawal. |
@@ -103,6 +104,39 @@ export default function App() {
103
104
 
104
105
  > **Note:** Device analytics (OS, version, screen resolution, timezone, etc.) are collected automatically by the SDK — no configuration needed.
105
106
 
107
+ ## Navigation
108
+
109
+ The SDK ships its own navigator, with no navigation library involved. Swipe-back and transitions run natively on the UI thread, so a busy JS thread cannot stall them.
110
+
111
+ | | iOS | Android |
112
+ |---|---|---|
113
+ | Back gesture | Edge swipe that follows the finger (right edge in RTL) | System back gesture with predictive progress on API 34+ |
114
+ | Back button | | Hardware and system back |
115
+ | Modals | Slide up, pull down from the top to dismiss | Slide up, back to dismiss |
116
+
117
+ ```ts
118
+ import { navigation } from 'react-native-monflowts';
119
+
120
+ navigation.navigate('WALLET');
121
+ navigation.push('LEADERBOARD');
122
+ navigation.replace('TICKET_SHOP');
123
+ navigation.goBack();
124
+ navigation.reset('HOME');
125
+ navigation.canGoBack();
126
+ navigation.getCurrentRoute();
127
+ navigation.getNavigationState();
128
+ ```
129
+
130
+ Route names and params are typed. Add a route in `src/navigation/routes.ts`, including its presentation, owning tab, gesture and deep link path.
131
+ `
132
+ **Deep links.** Pass `linking={{ prefixes: ['myapp://play'] }}` and the SDK opens paths such as `myapp://play/wallet` or `myapp://play/services/dice`. The host registers the URL scheme itself, and on iOS forwards `application(_:open:options:)` to `RCTLinkingManager`. Hosts with their own router can call `navigation.openUrl(url)`. Only routes with a `path` are reachable. Routes that carry a stake or payment cannot be given one, and a link is ignored during a live round or payment.
133
+
134
+ **Inside a host navigator.** A swipe on an inner SDK screen stays in the SDK. On the SDK's first screen, the host's own swipe-back takes over.
135
+
136
+ **State.** Each game stays mounted while it is covered, and returning to an idle game resumes the same instance. The last two idle services are kept. Leaving a live round ends that instance. The stack is restored for 30 minutes after the process dies, for the same player, except stake and payment screens. Exiting through `onExit` clears it.
137
+
138
+ **Android predictive back.** On by default for apps targeting API 36. Below that, set `android:enableOnBackInvokedCallback="true"` on the host's `<application>`, otherwise back still works without the progress animation.
139
+
106
140
  ## Server-driven content
107
141
 
108
142
  The SDK ships no game content. The only things compiled in are the bootstrap screen shown before content arrives (a blank screen, then the server-defined loading screen, plus a retry/exit fallback that uses three icons and no text). Everything else comes from the server and lives in one folder, `remote-assets/`:
@@ -55,4 +55,5 @@ dependencies {
55
55
  implementation "com.facebook.react:react-android"
56
56
  implementation "com.airbnb.android:lottie:${getExtOrDefault('lottieVersion')}"
57
57
  implementation "com.squareup.okhttp3:okhttp:4.9.2"
58
+ implementation "androidx.activity:activity:1.9.3"
58
59
  }
@@ -0,0 +1,43 @@
1
+ package com.monflowts
2
+
3
+ import android.content.Context
4
+ import com.facebook.react.bridge.Promise
5
+ import com.facebook.react.bridge.ReactApplicationContext
6
+ import com.facebook.react.bridge.ReactContextBaseJavaModule
7
+ import com.facebook.react.bridge.ReactMethod
8
+
9
+ class MonflowtsNavigationModule(reactContext: ReactApplicationContext) :
10
+ ReactContextBaseJavaModule(reactContext) {
11
+
12
+ private val preferences
13
+ get() = reactApplicationContext.getSharedPreferences("monflowts_navigation", Context.MODE_PRIVATE)
14
+
15
+ override fun getName(): String = "MonflowtsNavigation"
16
+
17
+ @ReactMethod
18
+ fun saveState(json: String, promise: Promise) {
19
+ preferences.edit().putString(STATE_KEY, json).apply()
20
+ promise.resolve(null)
21
+ }
22
+
23
+ @ReactMethod
24
+ fun loadState(promise: Promise) {
25
+ promise.resolve(preferences.getString(STATE_KEY, null))
26
+ }
27
+
28
+ @ReactMethod
29
+ fun saveValue(key: String, value: String, promise: Promise) {
30
+ preferences.edit().putString("$VALUE_PREFIX$key", value).apply()
31
+ promise.resolve(null)
32
+ }
33
+
34
+ @ReactMethod
35
+ fun loadValue(key: String, promise: Promise) {
36
+ promise.resolve(preferences.getString("$VALUE_PREFIX$key", null))
37
+ }
38
+
39
+ companion object {
40
+ private const val STATE_KEY = "state"
41
+ private const val VALUE_PREFIX = "value."
42
+ }
43
+ }
@@ -9,7 +9,7 @@ import com.facebook.react.uimanager.ViewManager
9
9
 
10
10
  class MonflowtsViewPackage : BaseReactPackage() {
11
11
  override fun createViewManagers(reactContext: ReactApplicationContext): List<ViewManager<*, *>> {
12
- return listOf(MonflowtsWheelViewManager(), MonflowtsSvgViewManager(), MonflowtsLottieViewManager(), MonflowtsWebViewManager())
12
+ return listOf(MonflowtsWheelViewManager(), MonflowtsSvgViewManager(), MonflowtsLottieViewManager(), MonflowtsWebViewManager(), MonflowtsStackViewManager())
13
13
  }
14
14
 
15
15
  override fun getModule(name: String, reactContext: ReactApplicationContext): NativeModule? {
@@ -19,6 +19,7 @@ class MonflowtsViewPackage : BaseReactPackage() {
19
19
  "MonflowtsCrashFeed" -> MonflowtsCrashFeedModule(reactContext)
20
20
  "MonflowtsSpeech" -> MonflowtsSpeechModule(reactContext)
21
21
  "MonflowtsAssets" -> MonflowtsAssetsModule(reactContext)
22
+ "MonflowtsNavigation" -> MonflowtsNavigationModule(reactContext)
22
23
  else -> null
23
24
  }
24
25
  }
@@ -64,6 +65,14 @@ class MonflowtsViewPackage : BaseReactPackage() {
64
65
  false,
65
66
  false,
66
67
  false
68
+ ),
69
+ "MonflowtsNavigation" to ReactModuleInfo(
70
+ "MonflowtsNavigation",
71
+ MonflowtsNavigationModule::class.java.name,
72
+ false,
73
+ false,
74
+ false,
75
+ false
67
76
  )
68
77
  )
69
78
  }
@@ -0,0 +1,443 @@
1
+ package com.monflowts
2
+
3
+ import android.animation.Animator
4
+ import android.animation.AnimatorListenerAdapter
5
+ import android.animation.ValueAnimator
6
+ import android.graphics.Color
7
+ import android.graphics.Outline
8
+ import android.graphics.drawable.ColorDrawable
9
+ import android.os.Build
10
+ import android.view.View
11
+ import android.view.ViewOutlineProvider
12
+ import android.view.animation.PathInterpolator
13
+ import androidx.activity.BackEventCompat
14
+ import androidx.activity.ComponentActivity
15
+ import androidx.activity.OnBackPressedCallback
16
+ import androidx.core.view.ViewCompat
17
+ import androidx.core.view.WindowCompat
18
+ import androidx.core.view.WindowInsetsCompat
19
+ import com.facebook.react.bridge.Arguments
20
+ import com.facebook.react.bridge.ReadableArray
21
+ import com.facebook.react.bridge.WritableMap
22
+ import com.facebook.react.uimanager.PixelUtil
23
+ import com.facebook.react.uimanager.ThemedReactContext
24
+ import com.facebook.react.uimanager.events.RCTEventEmitter
25
+ import com.facebook.react.views.view.ReactViewGroup
26
+ import kotlin.math.max
27
+ import kotlin.math.roundToInt
28
+
29
+ class MonflowtsStackView(
30
+ private val themedContext: ThemedReactContext,
31
+ private val setHostPointerEvents: (ReactViewGroup, String?) -> Unit,
32
+ ) : ReactViewGroup(themedContext) {
33
+
34
+ private data class Scene(val key: String, val state: String, val presentation: String, val gesture: Boolean)
35
+
36
+ private class Motion(val top: View, val below: View?, val presentation: String)
37
+
38
+ private class SavedBars(val lightNavigationBar: Boolean, val navigationBarColor: Int)
39
+
40
+ var transitionKind = "none"
41
+ var gestureBlocked = false
42
+ var rtl = false
43
+ var reduceMotion = false
44
+
45
+ private var backTarget = false
46
+ private var reportInsets = false
47
+ private var barColor: Int? = null
48
+ private var scenes: List<Scene> = emptyList()
49
+ private var topKey: String? = null
50
+ private var settledPopKey: String? = null
51
+ private var motion: Motion? = null
52
+ private var isPredicting = false
53
+ private var predictiveDirection = 1f
54
+ private var predictiveProgress = 0f
55
+ private var animator: ValueAnimator? = null
56
+ private var motionCompletion: (() -> Unit)? = null
57
+ private var reconcileScheduled = false
58
+ private val reportedExits = mutableSetOf<String>()
59
+ private var lastInsets: List<Float>? = null
60
+ private var savedBars: SavedBars? = null
61
+ private val dim = ColorDrawable(Color.BLACK)
62
+ private val density = resources.displayMetrics.density
63
+ private val emphasized = PathInterpolator(0.2f, 0f, 0f, 1f)
64
+
65
+ private val backCallback = object : OnBackPressedCallback(true) {
66
+ override fun handleOnBackStarted(backEvent: BackEventCompat) {
67
+ beginPredictive(backEvent)
68
+ }
69
+
70
+ override fun handleOnBackProgressed(backEvent: BackEventCompat) {
71
+ val current = motion
72
+ if (isPredicting && current != null) applyPredictive(current, backEvent.progress)
73
+ }
74
+
75
+ override fun handleOnBackCancelled() {
76
+ cancelPredictive()
77
+ }
78
+
79
+ override fun handleOnBackPressed() {
80
+ if (isPredicting) commitPredictive() else emit("topBackRequest", Arguments.createMap())
81
+ }
82
+ }
83
+
84
+ init {
85
+ clipChildren = true
86
+ addOnLayoutChangeListener { _, _, _, _, _, _, _, _, _ -> publishInsets() }
87
+ ViewCompat.setOnApplyWindowInsetsListener(this) { _, insets ->
88
+ publishInsets()
89
+ insets
90
+ }
91
+ }
92
+
93
+ fun setScenes(raw: ReadableArray?) {
94
+ val parsed = mutableListOf<Scene>()
95
+ if (raw != null) {
96
+ for (index in 0 until raw.size()) {
97
+ val scene = raw.getMap(index) ?: continue
98
+ parsed.add(
99
+ Scene(
100
+ key = scene.getString("key") ?: continue,
101
+ state = scene.getString("state") ?: continue,
102
+ presentation = scene.getString("presentation") ?: continue,
103
+ gesture = scene.hasKey("gesture") && scene.getBoolean("gesture"),
104
+ ),
105
+ )
106
+ }
107
+ }
108
+ scenes = parsed
109
+ scheduleReconcile()
110
+ }
111
+
112
+ fun setBackTarget(enabled: Boolean) {
113
+ if (backTarget == enabled) return
114
+ backTarget = enabled
115
+ syncBackRegistration()
116
+ }
117
+
118
+ fun setReportInsets(report: Boolean) {
119
+ reportInsets = report
120
+ publishInsets()
121
+ syncSystemBars()
122
+ }
123
+
124
+ fun setBarColor(color: String?) {
125
+ barColor = color?.let { runCatching { Color.parseColor(it) }.getOrNull() }
126
+ syncSystemBars()
127
+ }
128
+
129
+ override fun onAttachedToWindow() {
130
+ super.onAttachedToWindow()
131
+ syncBackRegistration()
132
+ syncSystemBars()
133
+ ViewCompat.requestApplyInsets(this)
134
+ }
135
+
136
+ override fun onDetachedFromWindow() {
137
+ interruptPrediction()
138
+ completeRunningMotion()
139
+ backCallback.remove()
140
+ restoreSystemBars()
141
+ super.onDetachedFromWindow()
142
+ }
143
+
144
+ override fun onViewAdded(child: View) {
145
+ super.onViewAdded(child)
146
+ scheduleReconcile()
147
+ }
148
+
149
+ override fun onViewRemoved(child: View) {
150
+ restore(child)
151
+ super.onViewRemoved(child)
152
+ scheduleReconcile()
153
+ }
154
+
155
+ private val activeScenes: List<Scene>
156
+ get() = scenes.filter { it.state == "active" }
157
+
158
+ private fun sceneView(key: String): View? {
159
+ val index = scenes.indexOfFirst { it.key == key }
160
+ return if (index in 0 until childCount) getChildAt(index) else null
161
+ }
162
+
163
+ private fun scheduleReconcile() {
164
+ if (reconcileScheduled) return
165
+ reconcileScheduled = true
166
+ post {
167
+ reconcileScheduled = false
168
+ reconcile()
169
+ }
170
+ }
171
+
172
+ private fun reconcile() {
173
+ if (childCount != scenes.size) return
174
+ val newTop = activeScenes.lastOrNull()?.key
175
+ if (newTop != topKey) {
176
+ interruptPrediction()
177
+ completeRunningMotion()
178
+ val oldTop = topKey
179
+ topKey = newTop
180
+ settledPopKey = null
181
+ startTransition(oldTop, newTop)
182
+ } else if (motion == null) {
183
+ applyVisibility()
184
+ }
185
+ reportExits()
186
+ }
187
+
188
+ private fun applyVisibility() {
189
+ if (childCount != scenes.size) return
190
+ val visible = mutableSetOf<String>()
191
+ for (scene in activeScenes.asReversed()) {
192
+ if (scene.key == settledPopKey) continue
193
+ visible.add(scene.key)
194
+ if (scene.presentation != "overlay") break
195
+ }
196
+ scenes.forEachIndexed { index, scene ->
197
+ getChildAt(index).visibility = if (scene.key in visible) View.VISIBLE else View.INVISIBLE
198
+ }
199
+ }
200
+
201
+ private fun reportExits() {
202
+ if (motion != null) return
203
+ val exits = scenes.filter { it.state == "exit" }.map { it.key }
204
+ reportedExits.retainAll(exits.toSet())
205
+ for (key in exits) {
206
+ if (reportedExits.add(key)) emit("topSceneExited", Arguments.createMap().apply { putString("key", key) })
207
+ }
208
+ }
209
+
210
+ private fun startTransition(oldKey: String?, newKey: String?) {
211
+ val oldScene = scenes.firstOrNull { it.key == oldKey }
212
+ val newScene = scenes.firstOrNull { it.key == newKey }
213
+ val oldView = oldKey?.let { sceneView(it) }
214
+ val newView = newKey?.let { sceneView(it) }
215
+ if (transitionKind == "none" || !isAttachedToWindow || oldScene == null || newScene == null || oldView == null || newView == null) {
216
+ applyVisibility()
217
+ return
218
+ }
219
+ val popping = transitionKind == "pop"
220
+ val presentation = (if (popping) oldScene else newScene).presentation
221
+ if (presentation == "tab") {
222
+ applyVisibility()
223
+ return
224
+ }
225
+ val next = Motion(
226
+ top = if (popping) oldView else newView,
227
+ below = if (popping) newView else oldView,
228
+ presentation = if (reduceMotion) "overlay" else presentation,
229
+ )
230
+ prepare(next)
231
+ setHostPointerEvents(this, "box-only")
232
+ apply(next, if (popping) 0f else 1f)
233
+ run(if (popping) 0f else 1f, if (popping) 1f else 0f, durationFor(next), { apply(next, it) }) { finishMotion() }
234
+ }
235
+
236
+ private fun durationFor(current: Motion): Long = if (current.presentation == "overlay") 200L else 300L
237
+
238
+ private fun prepare(next: Motion) {
239
+ motion = next
240
+ next.top.visibility = View.VISIBLE
241
+ next.top.setLayerType(View.LAYER_TYPE_HARDWARE, null)
242
+ next.below?.visibility = View.VISIBLE
243
+ dim.alpha = 0
244
+ next.below?.foreground = dim
245
+ }
246
+
247
+ private fun apply(current: Motion, progress: Float) {
248
+ val direction = if (rtl) -1f else 1f
249
+ when (current.presentation) {
250
+ "card" -> {
251
+ current.top.translationX = direction * progress * width * 0.25f
252
+ current.top.alpha = 1f - progress
253
+ current.below?.translationX = -direction * width * 0.1f * (1f - progress)
254
+ dim.alpha = (255 * 0.2f * (1f - progress)).roundToInt()
255
+ }
256
+ "modal" -> {
257
+ current.top.translationY = progress * height
258
+ dim.alpha = (255 * 0.4f * (1f - progress)).roundToInt()
259
+ }
260
+ else -> current.top.alpha = 1f - progress
261
+ }
262
+ }
263
+
264
+ private fun run(from: Float, to: Float, duration: Long, onFrame: (Float) -> Unit, completion: () -> Unit) {
265
+ val runner = ValueAnimator.ofFloat(from, to)
266
+ runner.duration = duration
267
+ runner.interpolator = emphasized
268
+ runner.addUpdateListener { onFrame(it.animatedValue as Float) }
269
+ runner.addListener(object : AnimatorListenerAdapter() {
270
+ override fun onAnimationEnd(animation: Animator) {
271
+ if (animator !== runner) return
272
+ animator = null
273
+ val finished = motionCompletion
274
+ motionCompletion = null
275
+ finished?.invoke()
276
+ }
277
+ })
278
+ animator = runner
279
+ motionCompletion = completion
280
+ runner.start()
281
+ }
282
+
283
+ private fun completeRunningMotion() {
284
+ val running = animator ?: return
285
+ animator = null
286
+ running.cancel()
287
+ val finished = motionCompletion
288
+ motionCompletion = null
289
+ finished?.invoke()
290
+ }
291
+
292
+ private fun finishMotion() {
293
+ val finished = motion ?: return
294
+ motion = null
295
+ restore(finished.top)
296
+ finished.below?.let { restore(it) }
297
+ setHostPointerEvents(this, null)
298
+ applyVisibility()
299
+ reportExits()
300
+ }
301
+
302
+ private fun restore(view: View) {
303
+ view.translationX = 0f
304
+ view.translationY = 0f
305
+ view.scaleX = 1f
306
+ view.scaleY = 1f
307
+ view.alpha = 1f
308
+ view.foreground = null
309
+ if (view.clipToOutline) {
310
+ view.clipToOutline = false
311
+ view.outlineProvider = ViewOutlineProvider.BACKGROUND
312
+ }
313
+ view.setLayerType(View.LAYER_TYPE_NONE, null)
314
+ }
315
+
316
+ private fun beginPredictive(event: BackEventCompat) {
317
+ val active = activeScenes
318
+ val topScene = active.lastOrNull()
319
+ if (active.size < 2 || topScene == null || !topScene.gesture || gestureBlocked || settledPopKey != null) return
320
+ completeRunningMotion()
321
+ val topView = sceneView(topScene.key) ?: return
322
+ val belowView = sceneView(active[active.size - 2].key) ?: return
323
+ prepare(Motion(topView, belowView, topScene.presentation))
324
+ isPredicting = true
325
+ predictiveDirection = if (event.swipeEdge == BackEventCompat.EDGE_LEFT) 1f else -1f
326
+ topView.outlineProvider = object : ViewOutlineProvider() {
327
+ override fun getOutline(view: View, outline: Outline) {
328
+ outline.setRoundRect(0, 0, view.width, view.height, predictiveProgress * 28f * density)
329
+ }
330
+ }
331
+ topView.clipToOutline = true
332
+ applyPredictive(motion ?: return, event.progress)
333
+ }
334
+
335
+ private fun applyPredictive(current: Motion, progress: Float) {
336
+ predictiveProgress = progress
337
+ val scale = 1f - 0.1f * progress
338
+ current.top.scaleX = scale
339
+ current.top.scaleY = scale
340
+ current.top.translationX = predictiveDirection * progress * 16f * density
341
+ current.top.invalidateOutline()
342
+ current.below?.translationX = -predictiveDirection * width * 0.06f * (1f - progress)
343
+ dim.alpha = (255 * 0.35f * (1f - progress)).roundToInt()
344
+ }
345
+
346
+ private fun cancelPredictive() {
347
+ val current = motion
348
+ if (!isPredicting || current == null) return
349
+ isPredicting = false
350
+ run(predictiveProgress, 0f, 150L, { applyPredictive(current, it) }) { finishMotion() }
351
+ }
352
+
353
+ private fun commitPredictive() {
354
+ val current = motion
355
+ if (!isPredicting || current == null) return
356
+ isPredicting = false
357
+ val key = topKey
358
+ val startX = current.top.translationX
359
+ val startBelowX = current.below?.translationX ?: 0f
360
+ val startDim = dim.alpha
361
+ val direction = predictiveDirection
362
+ run(0f, 1f, 180L, { progress ->
363
+ current.top.alpha = 1f - progress
364
+ current.top.translationX = startX + direction * progress * width * 0.2f
365
+ current.below?.translationX = startBelowX * (1f - progress)
366
+ dim.alpha = (startDim * (1f - progress)).roundToInt()
367
+ }) {
368
+ settledPopKey = key
369
+ finishMotion()
370
+ if (key != null) emit("topSwipePop", Arguments.createMap().apply { putString("key", key) })
371
+ }
372
+ }
373
+
374
+ private fun interruptPrediction() {
375
+ if (!isPredicting) return
376
+ isPredicting = false
377
+ finishMotion()
378
+ }
379
+
380
+ private fun syncBackRegistration() {
381
+ backCallback.remove()
382
+ if (!backTarget || !isAttachedToWindow) return
383
+ val activity = themedContext.currentActivity as? ComponentActivity ?: return
384
+ activity.onBackPressedDispatcher.addCallback(activity, backCallback)
385
+ }
386
+
387
+ private fun syncSystemBars() {
388
+ if (!reportInsets || !isAttachedToWindow) return
389
+ val window = themedContext.currentActivity?.window ?: return
390
+ val controller = WindowCompat.getInsetsController(window, window.decorView)
391
+ if (savedBars == null) {
392
+ @Suppress("DEPRECATION")
393
+ savedBars = SavedBars(controller.isAppearanceLightNavigationBars, window.navigationBarColor)
394
+ }
395
+ controller.isAppearanceLightNavigationBars = false
396
+ val color = barColor
397
+ if (color != null && Build.VERSION.SDK_INT < Build.VERSION_CODES.VANILLA_ICE_CREAM) {
398
+ @Suppress("DEPRECATION")
399
+ window.navigationBarColor = color
400
+ }
401
+ }
402
+
403
+ private fun restoreSystemBars() {
404
+ val saved = savedBars ?: return
405
+ savedBars = null
406
+ val window = themedContext.currentActivity?.window ?: return
407
+ WindowCompat.getInsetsController(window, window.decorView).isAppearanceLightNavigationBars = saved.lightNavigationBar
408
+ if (Build.VERSION.SDK_INT < Build.VERSION_CODES.VANILLA_ICE_CREAM) {
409
+ @Suppress("DEPRECATION")
410
+ window.navigationBarColor = saved.navigationBarColor
411
+ }
412
+ }
413
+
414
+ private fun publishInsets() {
415
+ if (!reportInsets || !isAttachedToWindow) return
416
+ val rootInsets = ViewCompat.getRootWindowInsets(this) ?: return
417
+ val bars = rootInsets.getInsets(WindowInsetsCompat.Type.systemBars() or WindowInsetsCompat.Type.displayCutout())
418
+ val location = IntArray(2)
419
+ getLocationInWindow(location)
420
+ val root = rootView
421
+ val values = listOf(
422
+ max(0, bars.top - location[1]),
423
+ max(0, bars.left - location[0]),
424
+ max(0, bars.bottom - (root.height - location[1] - height)),
425
+ max(0, bars.right - (root.width - location[0] - width)),
426
+ ).map { PixelUtil.toDIPFromPixel(it.toFloat()) }
427
+ if (values == lastInsets) return
428
+ lastInsets = values
429
+ emit(
430
+ "topInsets",
431
+ Arguments.createMap().apply {
432
+ putDouble("top", values[0].toDouble())
433
+ putDouble("left", values[1].toDouble())
434
+ putDouble("bottom", values[2].toDouble())
435
+ putDouble("right", values[3].toDouble())
436
+ },
437
+ )
438
+ }
439
+
440
+ private fun emit(eventName: String, payload: WritableMap) {
441
+ themedContext.getJSModule(RCTEventEmitter::class.java).receiveEvent(id, eventName, payload)
442
+ }
443
+ }
@@ -0,0 +1,70 @@
1
+ package com.monflowts
2
+
3
+ import com.facebook.react.bridge.ReadableArray
4
+ import com.facebook.react.module.annotations.ReactModule
5
+ import com.facebook.react.uimanager.ThemedReactContext
6
+ import com.facebook.react.uimanager.annotations.ReactProp
7
+ import com.facebook.react.views.view.ReactViewGroup
8
+ import com.facebook.react.views.view.ReactViewManager
9
+
10
+ @ReactModule(name = MonflowtsStackViewManager.NAME)
11
+ class MonflowtsStackViewManager : ReactViewManager() {
12
+
13
+ companion object {
14
+ const val NAME = "MonflowtsStackView"
15
+ }
16
+
17
+ override fun getName(): String = NAME
18
+
19
+ override fun createViewInstance(context: ThemedReactContext): ReactViewGroup =
20
+ MonflowtsStackView(context) { view, value -> setPointerEvents(view, value) }
21
+
22
+ @ReactProp(name = "scenes")
23
+ fun setScenes(view: MonflowtsStackView, scenes: ReadableArray?) {
24
+ view.setScenes(scenes)
25
+ }
26
+
27
+ @ReactProp(name = "transitionKind")
28
+ fun setTransitionKind(view: MonflowtsStackView, kind: String?) {
29
+ view.transitionKind = kind ?: "none"
30
+ }
31
+
32
+ @ReactProp(name = "backTarget")
33
+ fun setBackTarget(view: MonflowtsStackView, enabled: Boolean) {
34
+ view.setBackTarget(enabled)
35
+ }
36
+
37
+ @ReactProp(name = "gestureBlocked")
38
+ fun setGestureBlocked(view: MonflowtsStackView, blocked: Boolean) {
39
+ view.gestureBlocked = blocked
40
+ }
41
+
42
+ @ReactProp(name = "rtl")
43
+ fun setRtl(view: MonflowtsStackView, rtl: Boolean) {
44
+ view.rtl = rtl
45
+ }
46
+
47
+ @ReactProp(name = "reduceMotion")
48
+ fun setReduceMotion(view: MonflowtsStackView, reduce: Boolean) {
49
+ view.reduceMotion = reduce
50
+ }
51
+
52
+ @ReactProp(name = "reportInsets")
53
+ fun setReportInsets(view: MonflowtsStackView, report: Boolean) {
54
+ view.setReportInsets(report)
55
+ }
56
+
57
+ @ReactProp(name = "barColor")
58
+ fun setBarColor(view: MonflowtsStackView, color: String?) {
59
+ view.setBarColor(color)
60
+ }
61
+
62
+ override fun getExportedCustomDirectEventTypeConstants(): MutableMap<String, Any>? {
63
+ val constants = super.getExportedCustomDirectEventTypeConstants()?.toMutableMap() ?: mutableMapOf()
64
+ constants["topSceneExited"] = mapOf("registrationName" to "onSceneExited")
65
+ constants["topSwipePop"] = mapOf("registrationName" to "onSwipePop")
66
+ constants["topBackRequest"] = mapOf("registrationName" to "onBackRequest")
67
+ constants["topInsets"] = mapOf("registrationName" to "onInsets")
68
+ return constants
69
+ }
70
+ }
@@ -0,0 +1,10 @@
1
+ #import <React/RCTBridgeModule.h>
2
+
3
+ @interface RCT_EXTERN_MODULE(MonflowtsNavigation, NSObject)
4
+
5
+ RCT_EXTERN_METHOD(saveState:(NSString *)json resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject)
6
+ RCT_EXTERN_METHOD(loadState:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject)
7
+ RCT_EXTERN_METHOD(saveValue:(NSString *)key value:(NSString *)value resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject)
8
+ RCT_EXTERN_METHOD(loadValue:(NSString *)key resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject)
9
+
10
+ @end