react-native-monflowts 0.5.1 → 0.5.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +37 -3
- package/android/build.gradle +1 -0
- package/android/src/main/java/com/monflowts/MonflowtsLottieView.kt +12 -4
- package/android/src/main/java/com/monflowts/MonflowtsNavigationModule.kt +43 -0
- package/android/src/main/java/com/monflowts/MonflowtsPackage.kt +10 -1
- package/android/src/main/java/com/monflowts/MonflowtsStackView.kt +456 -0
- package/android/src/main/java/com/monflowts/MonflowtsStackViewManager.kt +70 -0
- package/android/src/main/java/com/monflowts/MonflowtsWebView.kt +35 -11
- package/android/src/main/java/com/monflowts/MonflowtsWebViewManager.kt +10 -0
- package/ios/MonflowtsNavigationBridge.m +10 -0
- package/ios/MonflowtsNavigationModule.swift +28 -0
- package/ios/MonflowtsStackBridge.m +17 -0
- package/ios/MonflowtsStackUIView.swift +409 -0
- package/ios/MonflowtsStackViewManager.swift +14 -0
- package/ios/MonflowtsWebBridge.m +1 -0
- package/ios/MonflowtsWebUIView.swift +21 -0
- package/lib/module/HubContent.js +259 -219
- package/lib/module/HubContent.js.map +1 -1
- package/lib/module/MonflowtsHub.js +42 -3
- package/lib/module/MonflowtsHub.js.map +1 -1
- package/lib/module/NativeWebView.js.map +1 -1
- package/lib/module/api/mutations.js +4 -0
- package/lib/module/api/mutations.js.map +1 -1
- package/lib/module/api/queries.js +9 -3
- package/lib/module/api/queries.js.map +1 -1
- package/lib/module/components/AbandonPolicyNotice.js +7 -6
- package/lib/module/components/AbandonPolicyNotice.js.map +1 -1
- package/lib/module/components/CoinFlyOverlay.js +27 -20
- package/lib/module/components/CoinFlyOverlay.js.map +1 -1
- package/lib/module/components/GameRulesModal.js +13 -11
- package/lib/module/components/GameRulesModal.js.map +1 -1
- package/lib/module/components/HypeCallout.js +5 -5
- package/lib/module/components/HypeCallout.js.map +1 -1
- package/lib/module/components/InsufficientFundsOverlay.js +4 -3
- package/lib/module/components/InsufficientFundsOverlay.js.map +1 -1
- package/lib/module/components/JackpotNearMiss.js +4 -3
- package/lib/module/components/JackpotNearMiss.js.map +1 -1
- package/lib/module/components/JackpotTeaser.js +10 -9
- package/lib/module/components/JackpotTeaser.js.map +1 -1
- package/lib/module/components/MonflowtsButton.js +7 -4
- package/lib/module/components/MonflowtsButton.js.map +1 -1
- package/lib/module/components/QuitConfirmModal.js +8 -7
- package/lib/module/components/QuitConfirmModal.js.map +1 -1
- package/lib/module/components/SessionTimer.js +3 -2
- package/lib/module/components/SessionTimer.js.map +1 -1
- package/lib/module/components/ShopArtView.js +105 -0
- package/lib/module/components/ShopArtView.js.map +1 -0
- package/lib/module/components/SideDemoTab.js +22 -4
- package/lib/module/components/SideDemoTab.js.map +1 -1
- package/lib/module/components/StakeInput.js +7 -6
- package/lib/module/components/StakeInput.js.map +1 -1
- package/lib/module/content.js.map +1 -1
- package/lib/module/hooks/useAvailableGames.js +7 -2
- package/lib/module/hooks/useAvailableGames.js.map +1 -1
- package/lib/module/hooks/useLeaderboard.js.map +1 -1
- package/lib/module/hooks/usePlayGame.js +11 -5
- package/lib/module/hooks/usePlayGame.js.map +1 -1
- package/lib/module/hooks/useRaffleDrawState.js +4 -1
- package/lib/module/hooks/useRaffleDrawState.js.map +1 -1
- package/lib/module/index.js +15 -0
- package/lib/module/index.js.map +1 -1
- package/lib/module/navigation/NativeStackView.js +5 -0
- package/lib/module/navigation/NativeStackView.js.map +1 -0
- package/lib/module/navigation/Navigator.js +250 -0
- package/lib/module/navigation/Navigator.js.map +1 -0
- package/lib/module/navigation/engine.js +466 -0
- package/lib/module/navigation/engine.js.map +1 -0
- package/lib/module/navigation/hooks.js +29 -0
- package/lib/module/navigation/hooks.js.map +1 -0
- package/lib/module/navigation/index.js +7 -0
- package/lib/module/navigation/index.js.map +1 -0
- package/lib/module/navigation/routes.js +111 -0
- package/lib/module/navigation/routes.js.map +1 -0
- package/lib/module/theme.js +13 -13
- package/lib/module/theme.js.map +1 -1
- package/lib/module/utils/scale.js +35 -0
- package/lib/module/utils/scale.js.map +1 -0
- package/lib/module/views/DepositSelect.js +8 -7
- package/lib/module/views/DepositSelect.js.map +1 -1
- package/lib/module/views/DiceBattle.js +589 -218
- package/lib/module/views/DiceBattle.js.map +1 -1
- package/lib/module/views/DiceLobby.js +113 -74
- package/lib/module/views/DiceLobby.js.map +1 -1
- package/lib/module/views/FortuneWheel.js +417 -271
- package/lib/module/views/FortuneWheel.js.map +1 -1
- package/lib/module/views/Freefall.js +149 -90
- package/lib/module/views/Freefall.js.map +1 -1
- package/lib/module/views/History.js +10 -9
- package/lib/module/views/History.js.map +1 -1
- package/lib/module/views/Home.js +1058 -401
- package/lib/module/views/Home.js.map +1 -1
- package/lib/module/views/Jetstream.js +47 -23
- package/lib/module/views/Jetstream.js.map +1 -1
- package/lib/module/views/Leaderboard.js +112 -103
- package/lib/module/views/Leaderboard.js.map +1 -1
- package/lib/module/views/MillionaireHunter.js +752 -578
- package/lib/module/views/MillionaireHunter.js.map +1 -1
- package/lib/module/views/Minefield.js +41 -19
- package/lib/module/views/Minefield.js.map +1 -1
- package/lib/module/views/PaymentWebView.js +7 -6
- package/lib/module/views/PaymentWebView.js.map +1 -1
- package/lib/module/views/PlayerCard.js +5 -4
- package/lib/module/views/PlayerCard.js.map +1 -1
- package/lib/module/views/Profile.js +11 -10
- package/lib/module/views/Profile.js.map +1 -1
- package/lib/module/views/RaffleDraw.js +37 -27
- package/lib/module/views/RaffleDraw.js.map +1 -1
- package/lib/module/views/RevealWin.js +161 -34
- package/lib/module/views/RevealWin.js.map +1 -1
- package/lib/module/views/Splash.js +3 -2
- package/lib/module/views/Splash.js.map +1 -1
- package/lib/module/views/Success.js +6 -3
- package/lib/module/views/Success.js.map +1 -1
- package/lib/module/views/TicketShop.js +1067 -236
- package/lib/module/views/TicketShop.js.map +1 -1
- package/lib/module/views/TriviaLobby.js +57 -31
- package/lib/module/views/TriviaLobby.js.map +1 -1
- package/lib/module/views/TriviaMaster.js +28 -23
- package/lib/module/views/TriviaMaster.js.map +1 -1
- package/lib/module/views/Wallet.js +18 -17
- package/lib/module/views/Wallet.js.map +1 -1
- package/lib/module/views/WithdrawFlow.js +6 -5
- package/lib/module/views/WithdrawFlow.js.map +1 -1
- package/lib/module/views/dice3d/DiceTable3D.js +131 -0
- package/lib/module/views/dice3d/DiceTable3D.js.map +1 -0
- package/lib/module/views/dice3d/diceScene.js +873 -0
- package/lib/module/views/dice3d/diceScene.js.map +1 -0
- package/lib/module/views/dice3d/diceSim.js +300 -0
- package/lib/module/views/dice3d/diceSim.js.map +1 -0
- package/lib/module/views/diceDuel.js +35 -0
- package/lib/module/views/diceDuel.js.map +1 -0
- package/lib/module/views/freefallDrop.js +66 -0
- package/lib/module/views/freefallDrop.js.map +1 -0
- package/lib/module/views/homeLayout.js +47 -0
- package/lib/module/views/homeLayout.js.map +1 -0
- package/lib/module/views/launchFeatured.js +43 -0
- package/lib/module/views/launchFeatured.js.map +1 -0
- package/lib/module/views/leaderboardPhase.js +52 -0
- package/lib/module/views/leaderboardPhase.js.map +1 -0
- package/lib/module/views/lobbyKit.js +224 -0
- package/lib/module/views/lobbyKit.js.map +1 -0
- package/lib/module/views/raffleContent.js +11 -0
- package/lib/module/views/raffleContent.js.map +1 -0
- package/lib/module/views/rafflePhase.js +15 -0
- package/lib/module/views/rafflePhase.js.map +1 -0
- package/lib/module/views/revealWinHelpers.js +19 -0
- package/lib/module/views/revealWinHelpers.js.map +1 -1
- package/lib/module/views/shopArtMotion.js +25 -0
- package/lib/module/views/shopArtMotion.js.map +1 -0
- package/lib/module/views/ticketBundlePresets.js +15 -12
- package/lib/module/views/ticketBundlePresets.js.map +1 -1
- package/lib/module/views/ticketShopArt.js +391 -0
- package/lib/module/views/ticketShopArt.js.map +1 -0
- package/lib/module/views/treasureHunt.js +81 -0
- package/lib/module/views/treasureHunt.js.map +1 -0
- package/lib/module/views/wheelLayout.js +47 -0
- package/lib/module/views/wheelLayout.js.map +1 -0
- package/lib/typescript/src/HubContent.d.ts.map +1 -1
- package/lib/typescript/src/MonflowtsHub.d.ts.map +1 -1
- package/lib/typescript/src/NativeWebView.d.ts +1 -0
- package/lib/typescript/src/NativeWebView.d.ts.map +1 -1
- package/lib/typescript/src/api/gameTypes.d.ts +18 -2
- package/lib/typescript/src/api/gameTypes.d.ts.map +1 -1
- package/lib/typescript/src/api/mutations.d.ts.map +1 -1
- package/lib/typescript/src/api/queries.d.ts.map +1 -1
- package/lib/typescript/src/api/sdkTypes.d.ts +3 -0
- package/lib/typescript/src/api/sdkTypes.d.ts.map +1 -1
- package/lib/typescript/src/components/AbandonPolicyNotice.d.ts.map +1 -1
- package/lib/typescript/src/components/CoinFlyOverlay.d.ts.map +1 -1
- package/lib/typescript/src/components/GameRulesModal.d.ts +1 -0
- package/lib/typescript/src/components/GameRulesModal.d.ts.map +1 -1
- package/lib/typescript/src/components/HypeCallout.d.ts.map +1 -1
- package/lib/typescript/src/components/InsufficientFundsOverlay.d.ts.map +1 -1
- package/lib/typescript/src/components/JackpotNearMiss.d.ts.map +1 -1
- package/lib/typescript/src/components/JackpotTeaser.d.ts.map +1 -1
- package/lib/typescript/src/components/MonflowtsButton.d.ts.map +1 -1
- package/lib/typescript/src/components/QuitConfirmModal.d.ts.map +1 -1
- package/lib/typescript/src/components/SessionTimer.d.ts.map +1 -1
- package/lib/typescript/src/components/ShopArtView.d.ts +11 -0
- package/lib/typescript/src/components/ShopArtView.d.ts.map +1 -0
- package/lib/typescript/src/components/SideDemoTab.d.ts +1 -0
- package/lib/typescript/src/components/SideDemoTab.d.ts.map +1 -1
- package/lib/typescript/src/components/StakeInput.d.ts.map +1 -1
- package/lib/typescript/src/content.d.ts +1 -0
- package/lib/typescript/src/content.d.ts.map +1 -1
- package/lib/typescript/src/hooks/useAvailableGames.d.ts +3 -0
- package/lib/typescript/src/hooks/useAvailableGames.d.ts.map +1 -1
- package/lib/typescript/src/hooks/useLeaderboard.d.ts +4 -0
- package/lib/typescript/src/hooks/useLeaderboard.d.ts.map +1 -1
- package/lib/typescript/src/hooks/usePlayGame.d.ts +1 -1
- package/lib/typescript/src/hooks/usePlayGame.d.ts.map +1 -1
- package/lib/typescript/src/hooks/useRaffleDrawState.d.ts.map +1 -1
- package/lib/typescript/src/index.d.ts +16 -0
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/navigation/NativeStackView.d.ts +41 -0
- package/lib/typescript/src/navigation/NativeStackView.d.ts.map +1 -0
- package/lib/typescript/src/navigation/Navigator.d.ts +13 -0
- package/lib/typescript/src/navigation/Navigator.d.ts.map +1 -0
- package/lib/typescript/src/navigation/engine.d.ts +69 -0
- package/lib/typescript/src/navigation/engine.d.ts.map +1 -0
- package/lib/typescript/src/navigation/hooks.d.ts +6 -0
- package/lib/typescript/src/navigation/hooks.d.ts.map +1 -0
- package/lib/typescript/src/navigation/index.d.ts +7 -0
- package/lib/typescript/src/navigation/index.d.ts.map +1 -0
- package/lib/typescript/src/navigation/routes.d.ts +80 -0
- package/lib/typescript/src/navigation/routes.d.ts.map +1 -0
- package/lib/typescript/src/theme.d.ts +3 -3
- package/lib/typescript/src/types.d.ts +0 -9
- package/lib/typescript/src/types.d.ts.map +1 -1
- package/lib/typescript/src/utils/scale.d.ts +12 -0
- package/lib/typescript/src/utils/scale.d.ts.map +1 -0
- package/lib/typescript/src/views/DiceBattle.d.ts.map +1 -1
- package/lib/typescript/src/views/DiceLobby.d.ts.map +1 -1
- package/lib/typescript/src/views/FortuneWheel.d.ts.map +1 -1
- package/lib/typescript/src/views/Freefall.d.ts.map +1 -1
- package/lib/typescript/src/views/History.d.ts.map +1 -1
- package/lib/typescript/src/views/Home.d.ts +2 -2
- package/lib/typescript/src/views/Home.d.ts.map +1 -1
- package/lib/typescript/src/views/Jetstream.d.ts.map +1 -1
- package/lib/typescript/src/views/Leaderboard.d.ts.map +1 -1
- package/lib/typescript/src/views/MillionaireHunter.d.ts.map +1 -1
- package/lib/typescript/src/views/Minefield.d.ts.map +1 -1
- package/lib/typescript/src/views/PlayerCard.d.ts.map +1 -1
- package/lib/typescript/src/views/Profile.d.ts.map +1 -1
- package/lib/typescript/src/views/RaffleDraw.d.ts +2 -1
- package/lib/typescript/src/views/RaffleDraw.d.ts.map +1 -1
- package/lib/typescript/src/views/RevealWin.d.ts.map +1 -1
- package/lib/typescript/src/views/Splash.d.ts.map +1 -1
- package/lib/typescript/src/views/Success.d.ts.map +1 -1
- package/lib/typescript/src/views/TicketShop.d.ts +1 -0
- package/lib/typescript/src/views/TicketShop.d.ts.map +1 -1
- package/lib/typescript/src/views/TriviaLobby.d.ts.map +1 -1
- package/lib/typescript/src/views/TriviaMaster.d.ts.map +1 -1
- package/lib/typescript/src/views/Wallet.d.ts.map +1 -1
- package/lib/typescript/src/views/dice3d/DiceTable3D.d.ts +41 -0
- package/lib/typescript/src/views/dice3d/DiceTable3D.d.ts.map +1 -0
- package/lib/typescript/src/views/dice3d/diceScene.d.ts +2 -0
- package/lib/typescript/src/views/dice3d/diceScene.d.ts.map +1 -0
- package/lib/typescript/src/views/dice3d/diceSim.d.ts +2 -0
- package/lib/typescript/src/views/dice3d/diceSim.d.ts.map +1 -0
- package/lib/typescript/src/views/diceDuel.d.ts +15 -0
- package/lib/typescript/src/views/diceDuel.d.ts.map +1 -0
- package/lib/typescript/src/views/freefallDrop.d.ts +19 -0
- package/lib/typescript/src/views/freefallDrop.d.ts.map +1 -0
- package/lib/typescript/src/views/homeLayout.d.ts +15 -0
- package/lib/typescript/src/views/homeLayout.d.ts.map +1 -0
- package/lib/typescript/src/views/launchFeatured.d.ts +2 -0
- package/lib/typescript/src/views/launchFeatured.d.ts.map +1 -0
- package/lib/typescript/src/views/leaderboardPhase.d.ts +6 -0
- package/lib/typescript/src/views/leaderboardPhase.d.ts.map +1 -0
- package/lib/typescript/src/views/lobbyKit.d.ts +45 -0
- package/lib/typescript/src/views/lobbyKit.d.ts.map +1 -0
- package/lib/typescript/src/views/raffleContent.d.ts +3 -0
- package/lib/typescript/src/views/raffleContent.d.ts.map +1 -0
- package/lib/typescript/src/views/rafflePhase.d.ts +9 -0
- package/lib/typescript/src/views/rafflePhase.d.ts.map +1 -0
- package/lib/typescript/src/views/revealWinHelpers.d.ts +9 -0
- package/lib/typescript/src/views/revealWinHelpers.d.ts.map +1 -1
- package/lib/typescript/src/views/shopArtMotion.d.ts +13 -0
- package/lib/typescript/src/views/shopArtMotion.d.ts.map +1 -0
- package/lib/typescript/src/views/ticketBundlePresets.d.ts +3 -17
- package/lib/typescript/src/views/ticketBundlePresets.d.ts.map +1 -1
- package/lib/typescript/src/views/ticketShopArt.d.ts +27 -0
- package/lib/typescript/src/views/ticketShopArt.d.ts.map +1 -0
- package/lib/typescript/src/views/treasureHunt.d.ts +29 -0
- package/lib/typescript/src/views/treasureHunt.d.ts.map +1 -0
- package/lib/typescript/src/views/wheelLayout.d.ts +30 -0
- package/lib/typescript/src/views/wheelLayout.d.ts.map +1 -0
- 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-
|
|
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://
|
|
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/`:
|
package/android/build.gradle
CHANGED
|
@@ -8,7 +8,9 @@ import android.util.Log
|
|
|
8
8
|
import android.widget.FrameLayout
|
|
9
9
|
import com.facebook.react.bridge.Arguments
|
|
10
10
|
import com.facebook.react.bridge.ReactContext
|
|
11
|
-
import com.facebook.react.
|
|
11
|
+
import com.facebook.react.bridge.WritableMap
|
|
12
|
+
import com.facebook.react.uimanager.UIManagerHelper
|
|
13
|
+
import com.facebook.react.uimanager.events.Event
|
|
12
14
|
import java.io.ByteArrayInputStream
|
|
13
15
|
|
|
14
16
|
class MonflowtsLottieView @JvmOverloads constructor(
|
|
@@ -46,10 +48,16 @@ class MonflowtsLottieView @JvmOverloads constructor(
|
|
|
46
48
|
}
|
|
47
49
|
}
|
|
48
50
|
|
|
51
|
+
private class AnimationFinishEvent(surfaceId: Int, viewTag: Int) : Event<AnimationFinishEvent>(surfaceId, viewTag) {
|
|
52
|
+
override fun getEventName(): String = "topMonflowtsAnimationFinish"
|
|
53
|
+
override fun canCoalesce(): Boolean = false
|
|
54
|
+
override fun getEventData(): WritableMap = Arguments.createMap()
|
|
55
|
+
}
|
|
56
|
+
|
|
49
57
|
private fun sendAnimationFinish() {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
58
|
+
val reactContext = context as? ReactContext ?: return
|
|
59
|
+
val dispatcher = UIManagerHelper.getEventDispatcherForReactTag(reactContext, id) ?: return
|
|
60
|
+
dispatcher.dispatchEvent(AnimationFinishEvent(UIManagerHelper.getSurfaceId(reactContext), id))
|
|
53
61
|
}
|
|
54
62
|
|
|
55
63
|
fun setSourceJson(json: String?) {
|
|
@@ -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,456 @@
|
|
|
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.UIManagerHelper
|
|
25
|
+
import com.facebook.react.uimanager.events.Event
|
|
26
|
+
import com.facebook.react.views.view.ReactViewGroup
|
|
27
|
+
import kotlin.math.max
|
|
28
|
+
import kotlin.math.roundToInt
|
|
29
|
+
|
|
30
|
+
class MonflowtsStackView(
|
|
31
|
+
private val themedContext: ThemedReactContext,
|
|
32
|
+
private val setHostPointerEvents: (ReactViewGroup, String?) -> Unit,
|
|
33
|
+
) : ReactViewGroup(themedContext) {
|
|
34
|
+
|
|
35
|
+
private data class Scene(val key: String, val state: String, val presentation: String, val gesture: Boolean)
|
|
36
|
+
|
|
37
|
+
private class Motion(val top: View, val below: View?, val presentation: String)
|
|
38
|
+
|
|
39
|
+
private class SavedBars(val lightNavigationBar: Boolean, val navigationBarColor: Int)
|
|
40
|
+
|
|
41
|
+
var transitionKind = "none"
|
|
42
|
+
var gestureBlocked = false
|
|
43
|
+
var rtl = false
|
|
44
|
+
var reduceMotion = false
|
|
45
|
+
|
|
46
|
+
private var backTarget = false
|
|
47
|
+
private var reportInsets = false
|
|
48
|
+
private var barColor: Int? = null
|
|
49
|
+
private var scenes: List<Scene> = emptyList()
|
|
50
|
+
private var topKey: String? = null
|
|
51
|
+
private var settledPopKey: String? = null
|
|
52
|
+
private var motion: Motion? = null
|
|
53
|
+
private var isPredicting = false
|
|
54
|
+
private var predictiveDirection = 1f
|
|
55
|
+
private var predictiveProgress = 0f
|
|
56
|
+
private var animator: ValueAnimator? = null
|
|
57
|
+
private var motionCompletion: (() -> Unit)? = null
|
|
58
|
+
private var reconcileScheduled = false
|
|
59
|
+
private val reportedExits = mutableSetOf<String>()
|
|
60
|
+
private var lastInsets: List<Float>? = null
|
|
61
|
+
private var savedBars: SavedBars? = null
|
|
62
|
+
private val dim = ColorDrawable(Color.BLACK)
|
|
63
|
+
private val density = resources.displayMetrics.density
|
|
64
|
+
private val emphasized = PathInterpolator(0.2f, 0f, 0f, 1f)
|
|
65
|
+
|
|
66
|
+
private val backCallback = object : OnBackPressedCallback(true) {
|
|
67
|
+
override fun handleOnBackStarted(backEvent: BackEventCompat) {
|
|
68
|
+
beginPredictive(backEvent)
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
override fun handleOnBackProgressed(backEvent: BackEventCompat) {
|
|
72
|
+
val current = motion
|
|
73
|
+
if (isPredicting && current != null) applyPredictive(current, backEvent.progress)
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
override fun handleOnBackCancelled() {
|
|
77
|
+
cancelPredictive()
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
override fun handleOnBackPressed() {
|
|
81
|
+
if (isPredicting) commitPredictive() else emit("topBackRequest", Arguments.createMap())
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
init {
|
|
86
|
+
clipChildren = true
|
|
87
|
+
addOnLayoutChangeListener { _, _, _, _, _, _, _, _, _ -> publishInsets() }
|
|
88
|
+
ViewCompat.setOnApplyWindowInsetsListener(this) { _, insets ->
|
|
89
|
+
publishInsets()
|
|
90
|
+
insets
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
fun setScenes(raw: ReadableArray?) {
|
|
95
|
+
val parsed = mutableListOf<Scene>()
|
|
96
|
+
if (raw != null) {
|
|
97
|
+
for (index in 0 until raw.size()) {
|
|
98
|
+
val scene = raw.getMap(index) ?: continue
|
|
99
|
+
parsed.add(
|
|
100
|
+
Scene(
|
|
101
|
+
key = scene.getString("key") ?: continue,
|
|
102
|
+
state = scene.getString("state") ?: continue,
|
|
103
|
+
presentation = scene.getString("presentation") ?: continue,
|
|
104
|
+
gesture = scene.hasKey("gesture") && scene.getBoolean("gesture"),
|
|
105
|
+
),
|
|
106
|
+
)
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
scenes = parsed
|
|
110
|
+
scheduleReconcile()
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
fun setBackTarget(enabled: Boolean) {
|
|
114
|
+
if (backTarget == enabled) return
|
|
115
|
+
backTarget = enabled
|
|
116
|
+
syncBackRegistration()
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
fun setReportInsets(report: Boolean) {
|
|
120
|
+
reportInsets = report
|
|
121
|
+
publishInsets()
|
|
122
|
+
syncSystemBars()
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
fun setBarColor(color: String?) {
|
|
126
|
+
barColor = color?.let { runCatching { Color.parseColor(it) }.getOrNull() }
|
|
127
|
+
syncSystemBars()
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
override fun onAttachedToWindow() {
|
|
131
|
+
super.onAttachedToWindow()
|
|
132
|
+
syncBackRegistration()
|
|
133
|
+
syncSystemBars()
|
|
134
|
+
ViewCompat.requestApplyInsets(this)
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
override fun onDetachedFromWindow() {
|
|
138
|
+
interruptPrediction()
|
|
139
|
+
completeRunningMotion()
|
|
140
|
+
backCallback.remove()
|
|
141
|
+
restoreSystemBars()
|
|
142
|
+
super.onDetachedFromWindow()
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
override fun onViewAdded(child: View) {
|
|
146
|
+
super.onViewAdded(child)
|
|
147
|
+
scheduleReconcile()
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
override fun onViewRemoved(child: View) {
|
|
151
|
+
restore(child)
|
|
152
|
+
super.onViewRemoved(child)
|
|
153
|
+
scheduleReconcile()
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
private val activeScenes: List<Scene>
|
|
157
|
+
get() = scenes.filter { it.state == "active" }
|
|
158
|
+
|
|
159
|
+
private fun sceneView(key: String): View? {
|
|
160
|
+
val index = scenes.indexOfFirst { it.key == key }
|
|
161
|
+
return if (index in 0 until childCount) getChildAt(index) else null
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
private fun scheduleReconcile() {
|
|
165
|
+
if (reconcileScheduled) return
|
|
166
|
+
reconcileScheduled = true
|
|
167
|
+
post {
|
|
168
|
+
reconcileScheduled = false
|
|
169
|
+
reconcile()
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
private fun reconcile() {
|
|
174
|
+
if (childCount != scenes.size) return
|
|
175
|
+
val newTop = activeScenes.lastOrNull()?.key
|
|
176
|
+
if (newTop != topKey) {
|
|
177
|
+
interruptPrediction()
|
|
178
|
+
completeRunningMotion()
|
|
179
|
+
val oldTop = topKey
|
|
180
|
+
topKey = newTop
|
|
181
|
+
settledPopKey = null
|
|
182
|
+
startTransition(oldTop, newTop)
|
|
183
|
+
} else if (motion == null) {
|
|
184
|
+
applyVisibility()
|
|
185
|
+
}
|
|
186
|
+
reportExits()
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
private fun applyVisibility() {
|
|
190
|
+
if (childCount != scenes.size) return
|
|
191
|
+
val visible = mutableSetOf<String>()
|
|
192
|
+
for (scene in activeScenes.asReversed()) {
|
|
193
|
+
if (scene.key == settledPopKey) continue
|
|
194
|
+
visible.add(scene.key)
|
|
195
|
+
if (scene.presentation != "overlay") break
|
|
196
|
+
}
|
|
197
|
+
scenes.forEachIndexed { index, scene ->
|
|
198
|
+
getChildAt(index).visibility = if (scene.key in visible) View.VISIBLE else View.INVISIBLE
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
private fun reportExits() {
|
|
203
|
+
if (motion != null) return
|
|
204
|
+
val exits = scenes.filter { it.state == "exit" }.map { it.key }
|
|
205
|
+
reportedExits.retainAll(exits.toSet())
|
|
206
|
+
for (key in exits) {
|
|
207
|
+
if (reportedExits.add(key)) emit("topSceneExited", Arguments.createMap().apply { putString("key", key) })
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
private fun startTransition(oldKey: String?, newKey: String?) {
|
|
212
|
+
val oldScene = scenes.firstOrNull { it.key == oldKey }
|
|
213
|
+
val newScene = scenes.firstOrNull { it.key == newKey }
|
|
214
|
+
val oldView = oldKey?.let { sceneView(it) }
|
|
215
|
+
val newView = newKey?.let { sceneView(it) }
|
|
216
|
+
if (transitionKind == "none" || !isAttachedToWindow || oldScene == null || newScene == null || oldView == null || newView == null) {
|
|
217
|
+
applyVisibility()
|
|
218
|
+
return
|
|
219
|
+
}
|
|
220
|
+
val popping = transitionKind == "pop"
|
|
221
|
+
val presentation = (if (popping) oldScene else newScene).presentation
|
|
222
|
+
if (presentation == "tab") {
|
|
223
|
+
applyVisibility()
|
|
224
|
+
return
|
|
225
|
+
}
|
|
226
|
+
val next = Motion(
|
|
227
|
+
top = if (popping) oldView else newView,
|
|
228
|
+
below = if (popping) newView else oldView,
|
|
229
|
+
presentation = if (reduceMotion) "overlay" else presentation,
|
|
230
|
+
)
|
|
231
|
+
prepare(next)
|
|
232
|
+
setHostPointerEvents(this, "box-only")
|
|
233
|
+
apply(next, if (popping) 0f else 1f)
|
|
234
|
+
run(if (popping) 0f else 1f, if (popping) 1f else 0f, durationFor(next), { apply(next, it) }) { finishMotion() }
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
private fun durationFor(current: Motion): Long = if (current.presentation == "overlay") 200L else 300L
|
|
238
|
+
|
|
239
|
+
private fun prepare(next: Motion) {
|
|
240
|
+
motion = next
|
|
241
|
+
next.top.visibility = View.VISIBLE
|
|
242
|
+
next.top.setLayerType(View.LAYER_TYPE_HARDWARE, null)
|
|
243
|
+
next.below?.visibility = View.VISIBLE
|
|
244
|
+
dim.alpha = 0
|
|
245
|
+
next.below?.foreground = dim
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
private fun apply(current: Motion, progress: Float) {
|
|
249
|
+
val direction = if (rtl) -1f else 1f
|
|
250
|
+
when (current.presentation) {
|
|
251
|
+
"card" -> {
|
|
252
|
+
current.top.translationX = direction * progress * width * 0.25f
|
|
253
|
+
current.top.alpha = 1f - progress
|
|
254
|
+
current.below?.translationX = -direction * width * 0.1f * (1f - progress)
|
|
255
|
+
dim.alpha = (255 * 0.2f * (1f - progress)).roundToInt()
|
|
256
|
+
}
|
|
257
|
+
"modal" -> {
|
|
258
|
+
current.top.translationY = progress * height
|
|
259
|
+
dim.alpha = (255 * 0.4f * (1f - progress)).roundToInt()
|
|
260
|
+
}
|
|
261
|
+
else -> current.top.alpha = 1f - progress
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
private fun run(from: Float, to: Float, duration: Long, onFrame: (Float) -> Unit, completion: () -> Unit) {
|
|
266
|
+
val runner = ValueAnimator.ofFloat(from, to)
|
|
267
|
+
runner.duration = duration
|
|
268
|
+
runner.interpolator = emphasized
|
|
269
|
+
runner.addUpdateListener { onFrame(it.animatedValue as Float) }
|
|
270
|
+
runner.addListener(object : AnimatorListenerAdapter() {
|
|
271
|
+
override fun onAnimationEnd(animation: Animator) {
|
|
272
|
+
if (animator !== runner) return
|
|
273
|
+
animator = null
|
|
274
|
+
val finished = motionCompletion
|
|
275
|
+
motionCompletion = null
|
|
276
|
+
finished?.invoke()
|
|
277
|
+
}
|
|
278
|
+
})
|
|
279
|
+
animator = runner
|
|
280
|
+
motionCompletion = completion
|
|
281
|
+
runner.start()
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
private fun completeRunningMotion() {
|
|
285
|
+
val running = animator ?: return
|
|
286
|
+
animator = null
|
|
287
|
+
running.cancel()
|
|
288
|
+
val finished = motionCompletion
|
|
289
|
+
motionCompletion = null
|
|
290
|
+
finished?.invoke()
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
private fun finishMotion() {
|
|
294
|
+
val finished = motion ?: return
|
|
295
|
+
motion = null
|
|
296
|
+
restore(finished.top)
|
|
297
|
+
finished.below?.let { restore(it) }
|
|
298
|
+
setHostPointerEvents(this, null)
|
|
299
|
+
applyVisibility()
|
|
300
|
+
reportExits()
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
private fun restore(view: View) {
|
|
304
|
+
view.translationX = 0f
|
|
305
|
+
view.translationY = 0f
|
|
306
|
+
view.scaleX = 1f
|
|
307
|
+
view.scaleY = 1f
|
|
308
|
+
view.alpha = 1f
|
|
309
|
+
view.foreground = null
|
|
310
|
+
if (view.clipToOutline) {
|
|
311
|
+
view.clipToOutline = false
|
|
312
|
+
view.outlineProvider = ViewOutlineProvider.BACKGROUND
|
|
313
|
+
}
|
|
314
|
+
view.setLayerType(View.LAYER_TYPE_NONE, null)
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
private fun beginPredictive(event: BackEventCompat) {
|
|
318
|
+
val active = activeScenes
|
|
319
|
+
val topScene = active.lastOrNull()
|
|
320
|
+
if (active.size < 2 || topScene == null || !topScene.gesture || gestureBlocked || settledPopKey != null) return
|
|
321
|
+
completeRunningMotion()
|
|
322
|
+
val topView = sceneView(topScene.key) ?: return
|
|
323
|
+
val belowView = sceneView(active[active.size - 2].key) ?: return
|
|
324
|
+
prepare(Motion(topView, belowView, topScene.presentation))
|
|
325
|
+
isPredicting = true
|
|
326
|
+
predictiveDirection = if (event.swipeEdge == BackEventCompat.EDGE_LEFT) 1f else -1f
|
|
327
|
+
topView.outlineProvider = object : ViewOutlineProvider() {
|
|
328
|
+
override fun getOutline(view: View, outline: Outline) {
|
|
329
|
+
outline.setRoundRect(0, 0, view.width, view.height, predictiveProgress * 28f * density)
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
topView.clipToOutline = true
|
|
333
|
+
applyPredictive(motion ?: return, event.progress)
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
private fun applyPredictive(current: Motion, progress: Float) {
|
|
337
|
+
predictiveProgress = progress
|
|
338
|
+
val scale = 1f - 0.1f * progress
|
|
339
|
+
current.top.scaleX = scale
|
|
340
|
+
current.top.scaleY = scale
|
|
341
|
+
current.top.translationX = predictiveDirection * progress * 16f * density
|
|
342
|
+
current.top.invalidateOutline()
|
|
343
|
+
current.below?.translationX = -predictiveDirection * width * 0.06f * (1f - progress)
|
|
344
|
+
dim.alpha = (255 * 0.35f * (1f - progress)).roundToInt()
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
private fun cancelPredictive() {
|
|
348
|
+
val current = motion
|
|
349
|
+
if (!isPredicting || current == null) return
|
|
350
|
+
isPredicting = false
|
|
351
|
+
run(predictiveProgress, 0f, 150L, { applyPredictive(current, it) }) { finishMotion() }
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
private fun commitPredictive() {
|
|
355
|
+
val current = motion
|
|
356
|
+
if (!isPredicting || current == null) return
|
|
357
|
+
isPredicting = false
|
|
358
|
+
val key = topKey
|
|
359
|
+
val startX = current.top.translationX
|
|
360
|
+
val startBelowX = current.below?.translationX ?: 0f
|
|
361
|
+
val startDim = dim.alpha
|
|
362
|
+
val direction = predictiveDirection
|
|
363
|
+
run(0f, 1f, 180L, { progress ->
|
|
364
|
+
current.top.alpha = 1f - progress
|
|
365
|
+
current.top.translationX = startX + direction * progress * width * 0.2f
|
|
366
|
+
current.below?.translationX = startBelowX * (1f - progress)
|
|
367
|
+
dim.alpha = (startDim * (1f - progress)).roundToInt()
|
|
368
|
+
}) {
|
|
369
|
+
settledPopKey = key
|
|
370
|
+
finishMotion()
|
|
371
|
+
if (key != null) emit("topSwipePop", Arguments.createMap().apply { putString("key", key) })
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
private fun interruptPrediction() {
|
|
376
|
+
if (!isPredicting) return
|
|
377
|
+
isPredicting = false
|
|
378
|
+
finishMotion()
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
private fun syncBackRegistration() {
|
|
382
|
+
backCallback.remove()
|
|
383
|
+
if (!backTarget || !isAttachedToWindow) return
|
|
384
|
+
val activity = themedContext.currentActivity as? ComponentActivity ?: return
|
|
385
|
+
activity.onBackPressedDispatcher.addCallback(activity, backCallback)
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
private fun syncSystemBars() {
|
|
389
|
+
if (!reportInsets || !isAttachedToWindow) return
|
|
390
|
+
val window = themedContext.currentActivity?.window ?: return
|
|
391
|
+
val controller = WindowCompat.getInsetsController(window, window.decorView)
|
|
392
|
+
if (savedBars == null) {
|
|
393
|
+
@Suppress("DEPRECATION")
|
|
394
|
+
savedBars = SavedBars(controller.isAppearanceLightNavigationBars, window.navigationBarColor)
|
|
395
|
+
}
|
|
396
|
+
controller.isAppearanceLightNavigationBars = false
|
|
397
|
+
val color = barColor
|
|
398
|
+
if (color != null && Build.VERSION.SDK_INT < Build.VERSION_CODES.VANILLA_ICE_CREAM) {
|
|
399
|
+
@Suppress("DEPRECATION")
|
|
400
|
+
window.navigationBarColor = color
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
private fun restoreSystemBars() {
|
|
405
|
+
val saved = savedBars ?: return
|
|
406
|
+
savedBars = null
|
|
407
|
+
val window = themedContext.currentActivity?.window ?: return
|
|
408
|
+
WindowCompat.getInsetsController(window, window.decorView).isAppearanceLightNavigationBars = saved.lightNavigationBar
|
|
409
|
+
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.VANILLA_ICE_CREAM) {
|
|
410
|
+
@Suppress("DEPRECATION")
|
|
411
|
+
window.navigationBarColor = saved.navigationBarColor
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
private fun publishInsets() {
|
|
416
|
+
if (!reportInsets || !isAttachedToWindow) return
|
|
417
|
+
val rootInsets = ViewCompat.getRootWindowInsets(this) ?: return
|
|
418
|
+
val bars = rootInsets.getInsets(WindowInsetsCompat.Type.systemBars() or WindowInsetsCompat.Type.displayCutout())
|
|
419
|
+
val location = IntArray(2)
|
|
420
|
+
getLocationInWindow(location)
|
|
421
|
+
val root = rootView
|
|
422
|
+
val values = listOf(
|
|
423
|
+
max(0, bars.top - location[1]),
|
|
424
|
+
max(0, bars.left - location[0]),
|
|
425
|
+
max(0, bars.bottom - (root.height - location[1] - height)),
|
|
426
|
+
max(0, bars.right - (root.width - location[0] - width)),
|
|
427
|
+
).map { PixelUtil.toDIPFromPixel(it.toFloat()) }
|
|
428
|
+
if (values == lastInsets) return
|
|
429
|
+
lastInsets = values
|
|
430
|
+
emit(
|
|
431
|
+
"topInsets",
|
|
432
|
+
Arguments.createMap().apply {
|
|
433
|
+
putDouble("top", values[0].toDouble())
|
|
434
|
+
putDouble("left", values[1].toDouble())
|
|
435
|
+
putDouble("bottom", values[2].toDouble())
|
|
436
|
+
putDouble("right", values[3].toDouble())
|
|
437
|
+
},
|
|
438
|
+
)
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
private class StackEvent(
|
|
442
|
+
surfaceId: Int,
|
|
443
|
+
viewTag: Int,
|
|
444
|
+
private val name: String,
|
|
445
|
+
private val payload: WritableMap,
|
|
446
|
+
) : Event<StackEvent>(surfaceId, viewTag) {
|
|
447
|
+
override fun getEventName(): String = name
|
|
448
|
+
override fun canCoalesce(): Boolean = false
|
|
449
|
+
override fun getEventData(): WritableMap = payload
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
private fun emit(eventName: String, payload: WritableMap) {
|
|
453
|
+
val dispatcher = UIManagerHelper.getEventDispatcherForReactTag(themedContext, id) ?: return
|
|
454
|
+
dispatcher.dispatchEvent(StackEvent(UIManagerHelper.getSurfaceId(themedContext), id, eventName, payload))
|
|
455
|
+
}
|
|
456
|
+
}
|