@joryio/react-native-sdk 1.4.0-beta.1 → 1.4.0-beta.4
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/CHANGELOG.md +16 -2
- package/README.md +13 -0
- package/android/src/main/java/io/joryio/reactnative/JoryioCardFeedViewManager.kt +104 -0
- package/android/src/main/java/io/joryio/reactnative/JoryioModule.kt +331 -0
- package/android/src/main/java/io/joryio/reactnative/JoryioPackage.kt +2 -1
- package/android/src/main/java/io/joryio/reactnative/JoryioPlacementViewManager.kt +105 -0
- package/ios/JoryioCardFeedViewManager.m +14 -0
- package/ios/JoryioCardFeedViewManager.swift +77 -0
- package/ios/JoryioModule.m +76 -0
- package/ios/JoryioModule.swift +296 -4
- package/ios/JoryioPlacementViewManager.m +14 -0
- package/ios/JoryioPlacementViewManager.swift +75 -0
- package/lib/index.d.ts +326 -2
- package/lib/index.js +570 -3
- package/lib/index.js.map +1 -1
- package/package.json +2 -1
- package/src/index.ts +724 -2
package/CHANGELOG.md
CHANGED
|
@@ -2,13 +2,27 @@
|
|
|
2
2
|
|
|
3
3
|
## 1.4.0 - 2026-11-18
|
|
4
4
|
|
|
5
|
-
Added:
|
|
5
|
+
Added: `<JoryioPlacement>` draws an item's recommended products through the native view (Joryio BACKLOG D444) - props `showProducts` (default true), `productButtonText`, `productCardWidth`, forwarded by both view managers. A tap reports `clicked` with elementId `product:<id>`. New exports `PLACEMENT_PRODUCT_ELEMENT_PREFIX`, `PLACEMENT_PRODUCT_CARD_WIDTH`, `placementProductElementId`.
|
|
6
|
+
|
|
7
|
+
Added: the `time_on_screen` in-app trigger (Joryio BACKLOG D444 follow-up) works through the native iOS and Android SDKs: `Joryio.trackScreen(name)` starts the screen's clock there, and a campaign with the trigger shows after that many foreground seconds on the screen (or any screen). No JavaScript API change; needs the native SDK versions that add it.
|
|
8
|
+
|
|
9
|
+
Added: `Joryio.setLinkHandler((link) => boolean | Promise<boolean>)` / `clearLinkHandler()` (work before `initialize()`): every link the native SDK is about to open - an in-app message button or link, a `<JoryioPlacement />` button, a `<JoryioCardFeed />` tap, an iOS push tap - reaches JS first as a `JoryioLink` (`url`, `source`: `in_app` / `placement` / `card` / `push`, `campaignId`, `placementKey`, `itemId`, `cardId`, `isAppDeepLink`). Return true to take it over, false for the native behaviour without a handler; a Promise decides later. Both bridges take the link at once (event `JoryioLink`, at most 32 waiting) and JS answers with `completeLink`. Refused schemes never reach JS. `onDeepLink` props keep receiving app deep links, after the handler declines. New config option `forwardUniversalLinks` (iOS only, default false; ignored on Android, which routes verified App Links itself) - see the iOS SDK. The same names and source values on all five SDKs.
|
|
10
|
+
|
|
11
|
+
Added: content cards and the inbox (Joryio BACKLOG D444 Phase 3, docs/PLACEMENTS_PLAN.md section 11) - a persistent feed per person, filled from card campaigns and the journey step "Add card". `<JoryioCardFeed />` is the native iOS `CardFeedViewController` / Android `CardFeedView` (new view managers `JoryioCardFeedView` on both bridges): a plain scrolling list with image, title, body, optional button, a "Pinned" marker, an unread dot and a dismiss control, "No messages yet" when empty (`emptyText`, `pinnedLabel`, `dismissLabel`, `unreadLabel`), in the system theme; it reports `viewed` then `read` after half a card was on screen for a second, `clicked` on a tap and `dismissed` on the x, opens http(s) links natively, hands app deep links to `onDeepLink(url, cardId)` and never opens any other scheme. Data first: `Joryio.getCards({ cursor? })` resolving `CardFeed { cards, unreadCount, nextCursor, stateScope }` (each `Card`: `id, campaignId, variantId, title, body, imageUrl, buttonText, url, pinned, createdAt, expiresAt, read, clicked`), `getUnreadCardCount()` (a Promise over the native cache - every React Native read crosses the bridge - never a network call), `markCardViewed` / `markCardRead` / `markCardClicked` / `dismissCard` (a card or its id), `refreshCards()`, `onCardsUpdated(cb)` (returns an unsubscribe); exported `CARD_MIN_REFRESH_SECONDS` (30) and `CARD_FEED_TTL_SECONDS` (300). The native SDKs fetch, cache, rate-limit, keep an anonymous visitor's state and report; every report goes back to the native card object the bridge handed out, which drops it after an identify / reset. Apps with their own push messaging handler call `refreshCards()` on a `jry_sync: "cards"` data message. The same names and wire values on all five SDKs.
|
|
12
|
+
|
|
13
|
+
Added: placements (Joryio BACKLOG D444, docs/PLACEMENTS_PLAN.md). `<JoryioPlacement placementKey="home_hero" />` is the native iOS / Android `PlacementView` (new view managers `JoryioPlacementView` on both bridges): it sizes itself to what it draws (0 when collapsed), and `deep_link` buttons with an app link (`myapp://cart`, the shared `isAppDeepLink` rule, exported) go to `onDeepLink`; an http(s) link is opened by the SDK, any other scheme (javascript:, data:, intent:, ...) is refused. Data first: `Joryio.getPlacements(keys)`, `refreshPlacements(keys?)`, `onPlacementsUpdated(cb)` (returns an unsubscribe), `item.markDisplayed()` / `markClicked(elementId?)` / `markDismissed()`, `placement.markDisplayed()`; exported `PLACEMENT_VIEWABLE_FRACTION` (0.5) and `PLACEMENT_MIN_REFRESH_SECONDS` (30). The native SDKs fetch, cache, rate-limit, measure viewability and report; every mark call goes back to the native object, which drops it after an identify / reset. Apps with their own push messaging handler call `refreshPlacements()` on a `jry_sync: "placements"` data message. The same names and wire values on all five SDKs.
|
|
14
|
+
|
|
15
|
+
Added: feature flags and remote config (Joryio BACKLOG D446), routed to the native iOS and Android SDKs, which hold the answer and log exposures. `getFlag(key, defaultValue)`, `getBoolFlag`, `getStringFlag`, `getNumberFlag`, `getJsonFlag` resolve with the value Joryio decided for this person, or your default before the first answer, for a flag Joryio did not send, for a value of another type, or without tracking consent (a getter called before `initialize()` resolves once it has run). `getAllFlags()` (logs no exposure), `refreshFlags()` and `onFlagsUpdated(callback)` (returns an unsubscribe; one native subscription, event `JoryioFlagsUpdated`). Both bridges pass every argument - the key and the default - to the native getter. The same names and wire values on all five SDKs.
|
|
16
|
+
|
|
17
|
+
Added: the app's React Native package version reaches the dashboard (BACKLOG D427). `initialize()` hands `SDK_VERSION` (now exported) to the native SDK, which sends `X-Joryio-SDK-Wrapper: react-native` and `X-Joryio-SDK-Wrapper-Version: <version>` on every request next to its own `X-Joryio-SDK` (`android` / `ios`) and `X-Joryio-SDK-Version`. Settings > Apps shows the oldest version each app ran in the last 7 days and when a newer SDK is out. Not an app option: the bridge sets it on every `initialize()`. The same wire names on all five SDKs.
|
|
18
|
+
|
|
19
|
+
Added: `resetTo(anonymousId)`, bound on both bridges to the native `resetTo` (the native SDK checks the id) - everything `reset()` does, then the anonymous id you pass instead of a random one, for an app that keeps its own visitor id (BACKLOG D366). The id must be 8 to 255 letters, digits, `.`, `_`, `:` or `-`, must not have the shape of a Joryio profile id (24 lowercase hex) and must not be the user id the SDK holds; a refused id is logged and the call is a plain `reset()` (a random id), so a logout is never skipped. The same name and rule on all five SDKs. No wire changes: the server sees an ordinary anonymous id. Like `reset()`, `resetTo` drops a click-link token the SDK has not sent yet (one held while consent is pending), so the link is never attributed to the next person on the device.
|
|
6
20
|
|
|
7
21
|
Changed (BACKLOG D366, before any release of resetTo): it also refuses the anonymous id the SDK holds while a user is signed in - that id is tied to the signed-in person's profile, and adopting it would hand their in-app messages, events, form attribution and push subscription to the next person on a shared device (a random id is used instead). `resetTo` returns `Promise<boolean>`: `true` adopted, `false` refused; both bridges resolve the native answer. The same on all five SDKs.
|
|
8
22
|
|
|
9
23
|
Changed (BACKLOG D366): `resetTo` also refuses the last 20 anonymous ids this device held for a signed-in user when a reset signed them out (stored locally, newest kept; `wipeData()` forgets them) - a random id is used and it answers `false`, the same message and cap on all five SDKs. A `resetTo` held before `initialize()` and discarded before it runs (pushed out of a full hold) now resolves `false` instead of never settling; the native SDKs answer the same way.
|
|
10
24
|
|
|
11
|
-
Added: `identifyFromLink(url)`, bound on both bridges to the native `identifyFromLink` (the url is passed through unchanged; native reads the token and applies the rules) - click-link identity. Pass the URL from `Linking.getInitialURL()` and `Linking.addEventListener('url', ...)`; when it carries the `jr_t` token a tracked Joryio message link adds, the
|
|
25
|
+
Added: `identifyFromLink(url)`, bound on both bridges to the native `identifyFromLink` (the url is passed through unchanged; native reads the token and applies the rules) - click-link identity. Pass the URL from `Linking.getInitialURL()` and `Linking.addEventListener('url', ...)`; when it carries the `jr_t` token a tracked Joryio message link adds, the native SDK sends it to `POST /v1/identify-link`. The server uses it only to attribute this app's session and later events (Session Start, screen views, conversions) to the contact the message was sent to - it never identifies the person: the app's profile does not become the contact and is never merged into it, and nothing set in the app is written to the contact. Only `identify` joins the two. Held before `initialize()` like other data calls. Nothing happens when a user is identified, the person opted out or consent is denied; while consent is pending the token is held in memory and sent on `'granted'`. The same name, parameter, path and body on all five SDKs.
|
|
12
26
|
|
|
13
27
|
## 1.3.3 - 2026-11-03
|
|
14
28
|
|
package/README.md
CHANGED
|
@@ -60,6 +60,18 @@ Upgrading from a version that used the `Joryio/UI` pod: if you added a `pod 'Jor
|
|
|
60
60
|
|
|
61
61
|
Nothing to add. The bridge depends on `io.joryio:joryio-android-ui` from Maven Central, at the same version as this package; React Native projects already list `mavenCentral()` in their repositories.
|
|
62
62
|
|
|
63
|
+
A **beta** (`npm install @joryio/react-native-sdk@beta`) asks for the Android SDK beta, which is not on Maven Central: download `joryio-android-<version>-maven-repo.zip` from the matching [joryio-android-sdk pre-release](https://github.com/joryio/joryio-android-sdk/releases), unzip it into a folder of its own (the zip has no top-level folder: `unzip joryio-android-<version>-maven-repo.zip -d joryio-android-<version>-maven-repo`), and add that folder by absolute path to the project-level `android/build.gradle`:
|
|
64
|
+
|
|
65
|
+
```groovy
|
|
66
|
+
allprojects {
|
|
67
|
+
repositories {
|
|
68
|
+
maven { url = uri("/absolute/path/to/joryio-android-<version>-maven-repo") }
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
Remove the line when you move to the final release. Full steps, including Expo: [Installing a beta](https://docs.joryio.com/developers/sdk/react-native-sdk#beta).
|
|
74
|
+
|
|
63
75
|
### Expo
|
|
64
76
|
|
|
65
77
|
The SDK is a native module, so it does not run in Expo Go. Use a development build (`npx expo prebuild` or EAS Build) on Expo SDK 52 or newer. Expo's default iOS deployment target can be lower than the 14.0 the SDK needs; raise it with `expo-build-properties` in `app.json`:
|
|
@@ -156,6 +168,7 @@ All options are optional:
|
|
|
156
168
|
| `trackingConsent` | `'granted' \| 'denied' \| 'pending'` | unset | Consent at startup. Leave it unset unless your consent banner has an answer - see [Privacy controls](#privacy-controls) |
|
|
157
169
|
| `optOut` | `boolean` | `false` | Start opted out of tracking |
|
|
158
170
|
| `notificationChannelName` | `string` | `"Notifications"` | Android only: the notification channel name people see in system settings (Android 8+). Pass it localized. Ignored on iOS |
|
|
171
|
+
| `forwardUniversalLinks` | `boolean` | `false` | iOS only: an https link from Joryio content on one of your associated domains goes to your app's own universal-link handling instead of Safari. Ignored on Android |
|
|
159
172
|
|
|
160
173
|
## Push notifications
|
|
161
174
|
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
package io.joryio.reactnative
|
|
2
|
+
|
|
3
|
+
import android.content.Context
|
|
4
|
+
import android.view.View
|
|
5
|
+
import android.widget.FrameLayout
|
|
6
|
+
import com.facebook.react.bridge.Arguments
|
|
7
|
+
import com.facebook.react.bridge.ReactContext
|
|
8
|
+
import com.facebook.react.bridge.WritableMap
|
|
9
|
+
import com.facebook.react.uimanager.SimpleViewManager
|
|
10
|
+
import com.facebook.react.uimanager.ThemedReactContext
|
|
11
|
+
import com.facebook.react.uimanager.annotations.ReactProp
|
|
12
|
+
import com.facebook.react.uimanager.events.RCTEventEmitter
|
|
13
|
+
import io.joryio.sdk.ui.CardFeedView
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* The native view behind `<JoryioCardFeed />` (D444 Phase 3): the Android SDK's
|
|
17
|
+
* own CardFeedView, so the feed, paging, viewability (viewed then read), the
|
|
18
|
+
* clicked / dismissed reports and the link rule are exactly the native ones -
|
|
19
|
+
* one implementation per platform.
|
|
20
|
+
*
|
|
21
|
+
* React Native lays out only the views it created, so this wrapper measures
|
|
22
|
+
* and lays out the CardFeedView itself to the size React Native gave it.
|
|
23
|
+
* App deep links (`myapp://...`) go to JS (`onCardDeepLink`); http(s) opens in
|
|
24
|
+
* the browser natively; any other scheme is never opened.
|
|
25
|
+
*/
|
|
26
|
+
class JoryioCardFeedViewManager : SimpleViewManager<JoryioCardFeedHost>() {
|
|
27
|
+
override fun getName() = "JoryioCardFeedView"
|
|
28
|
+
|
|
29
|
+
override fun createViewInstance(context: ThemedReactContext) = JoryioCardFeedHost(context)
|
|
30
|
+
|
|
31
|
+
@ReactProp(name = "emptyText")
|
|
32
|
+
fun setEmptyText(view: JoryioCardFeedHost, text: String?) {
|
|
33
|
+
view.feed.emptyText = text ?: "No messages yet"
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
@ReactProp(name = "pinnedLabel")
|
|
37
|
+
fun setPinnedLabel(view: JoryioCardFeedHost, text: String?) {
|
|
38
|
+
view.feed.pinnedLabel = text ?: "Pinned"
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
@ReactProp(name = "dismissLabel")
|
|
42
|
+
fun setDismissLabel(view: JoryioCardFeedHost, text: String?) {
|
|
43
|
+
view.feed.dismissLabel = text ?: "Dismiss"
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
@ReactProp(name = "unreadLabel")
|
|
47
|
+
fun setUnreadLabel(view: JoryioCardFeedHost, text: String?) {
|
|
48
|
+
view.feed.unreadLabel = text ?: "Unread"
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
override fun getExportedCustomDirectEventTypeConstants(): Map<String, Any> = mapOf(
|
|
52
|
+
"onCardFeedRender" to mapOf("registrationName" to "onCardFeedRender"),
|
|
53
|
+
"onCardDeepLink" to mapOf("registrationName" to "onCardDeepLink"),
|
|
54
|
+
)
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
class JoryioCardFeedHost(context: Context) : FrameLayout(context) {
|
|
58
|
+
val feed = CardFeedView(context)
|
|
59
|
+
|
|
60
|
+
// Nullable: FrameLayout's constructor calls requestLayout before this is set.
|
|
61
|
+
private val relayout: Runnable? = Runnable { measureAndLayout() }
|
|
62
|
+
|
|
63
|
+
init {
|
|
64
|
+
addView(feed, LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT))
|
|
65
|
+
feed.onRender = { f ->
|
|
66
|
+
relayout?.let { post(it) }
|
|
67
|
+
emit("onCardFeedRender", Arguments.createMap().apply {
|
|
68
|
+
putInt("cardCount", f.cards.size)
|
|
69
|
+
putInt("unreadCount", f.unreadCount)
|
|
70
|
+
})
|
|
71
|
+
}
|
|
72
|
+
// App deep links go to JS, which routes them (the view opens only http(s)).
|
|
73
|
+
feed.onDeepLink = { url, card ->
|
|
74
|
+
emit("onCardDeepLink", Arguments.createMap().apply {
|
|
75
|
+
putString("url", url)
|
|
76
|
+
putString("cardId", card.id)
|
|
77
|
+
})
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
private fun emit(name: String, body: WritableMap) {
|
|
82
|
+
(context as? ReactContext)?.getJSModule(RCTEventEmitter::class.java)?.receiveEvent(id, name, body)
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
private fun measureAndLayout() {
|
|
86
|
+
if (width <= 0 || height <= 0) return
|
|
87
|
+
feed.measure(
|
|
88
|
+
View.MeasureSpec.makeMeasureSpec(width, View.MeasureSpec.EXACTLY),
|
|
89
|
+
View.MeasureSpec.makeMeasureSpec(height, View.MeasureSpec.EXACTLY),
|
|
90
|
+
)
|
|
91
|
+
feed.layout(0, 0, width, height)
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
override fun onLayout(changed: Boolean, left: Int, top: Int, right: Int, bottom: Int) {
|
|
95
|
+
measureAndLayout()
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
override fun requestLayout() {
|
|
99
|
+
super.requestLayout()
|
|
100
|
+
// Cards change size (an image arrives, a card is dismissed); React
|
|
101
|
+
// Native would not lay the native children out again.
|
|
102
|
+
relayout?.let { post(it) }
|
|
103
|
+
}
|
|
104
|
+
}
|
|
@@ -141,6 +141,10 @@ class JoryioModule(private val reactContext: ReactApplicationContext) :
|
|
|
141
141
|
// requestPushPermissionAtLaunch could not prompt until the user left
|
|
142
142
|
// the app and came back. The SDK keeps only the application context
|
|
143
143
|
// and a weak reference to the Activity.
|
|
144
|
+
// Every request names this bridge and its version (D427):
|
|
145
|
+
// X-Joryio-SDK-Wrapper: react-native + X-Joryio-SDK-Wrapper-Version.
|
|
146
|
+
// The JS layer sends its package version on every initialize().
|
|
147
|
+
Joryio.setSdkWrapper("react-native", config.optString("sdkWrapperVersion"))
|
|
144
148
|
Joryio.initialize(
|
|
145
149
|
context = reactApplicationContext.currentActivity ?: reactContext.applicationContext,
|
|
146
150
|
sdkKey = sdkKey,
|
|
@@ -900,6 +904,222 @@ class JoryioModule(private val reactContext: ReactApplicationContext) :
|
|
|
900
904
|
Joryio.syncInAppCampaigns()
|
|
901
905
|
}
|
|
902
906
|
|
|
907
|
+
// ── Placements (docs/PLACEMENTS_PLAN.md, D444) ──────────────────────
|
|
908
|
+
// The native SDK does the work - fetching, caching, viewability rules,
|
|
909
|
+
// reporting, the identity guard. The bridge hands the data to JS as JSON
|
|
910
|
+
// and routes JS's mark* calls back to the native objects it last handed
|
|
911
|
+
// out, so a report always goes through the native generation check.
|
|
912
|
+
|
|
913
|
+
private val lastPlacements = java.util.concurrent.ConcurrentHashMap<String, io.joryio.sdk.placements.Placement>()
|
|
914
|
+
private var placementsSubscription: java.io.Closeable? = null
|
|
915
|
+
|
|
916
|
+
private fun placementKeys(keys: ReadableArray?): List<String>? =
|
|
917
|
+
keys?.toArrayList()?.mapNotNull { it as? String }
|
|
918
|
+
|
|
919
|
+
private fun placementsJson(map: Map<String, io.joryio.sdk.placements.Placement>): String {
|
|
920
|
+
map.forEach { (k, p) -> lastPlacements[k] = p }
|
|
921
|
+
return map.entries.joinToString(",", "{", "}") { org.json.JSONObject.quote(it.key) + ":" + it.value.toJson() }
|
|
922
|
+
}
|
|
923
|
+
|
|
924
|
+
@ReactMethod
|
|
925
|
+
fun getPlacements(keys: ReadableArray?, promise: Promise) {
|
|
926
|
+
if (!Joryio.isInitialized()) {
|
|
927
|
+
promise.resolve("{}")
|
|
928
|
+
return
|
|
929
|
+
}
|
|
930
|
+
Joryio.getInstance().getPlacements(placementKeys(keys) ?: emptyList()) { map ->
|
|
931
|
+
promise.resolve(placementsJson(map))
|
|
932
|
+
}
|
|
933
|
+
}
|
|
934
|
+
|
|
935
|
+
@ReactMethod
|
|
936
|
+
fun refreshPlacements(keys: ReadableArray?) {
|
|
937
|
+
Joryio.refreshPlacements(placementKeys(keys))
|
|
938
|
+
}
|
|
939
|
+
|
|
940
|
+
@ReactMethod
|
|
941
|
+
fun enablePlacementsUpdates() {
|
|
942
|
+
if (placementsSubscription != null || !Joryio.isInitialized()) return
|
|
943
|
+
placementsSubscription = Joryio.getInstance().onPlacementsUpdated { map ->
|
|
944
|
+
val params = Arguments.createMap().apply { putString("json", placementsJson(map)) }
|
|
945
|
+
reactApplicationContext
|
|
946
|
+
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java)
|
|
947
|
+
.emit("JoryioPlacementsUpdated", params)
|
|
948
|
+
}
|
|
949
|
+
}
|
|
950
|
+
|
|
951
|
+
@ReactMethod
|
|
952
|
+
fun disablePlacementsUpdates() {
|
|
953
|
+
placementsSubscription?.close()
|
|
954
|
+
placementsSubscription = null
|
|
955
|
+
}
|
|
956
|
+
|
|
957
|
+
/** `action`: displayed | clicked | dismissed for an item, `control` for the holdout spot. */
|
|
958
|
+
@ReactMethod
|
|
959
|
+
fun markPlacement(placementKey: String?, itemId: String?, action: String?, elementId: String?) {
|
|
960
|
+
val placement = lastPlacements[placementKey ?: return] ?: return
|
|
961
|
+
if (action == "control") {
|
|
962
|
+
placement.markDisplayed()
|
|
963
|
+
return
|
|
964
|
+
}
|
|
965
|
+
val item = placement.items.firstOrNull { it.id == itemId } ?: return
|
|
966
|
+
when (action) {
|
|
967
|
+
"displayed" -> item.markDisplayed()
|
|
968
|
+
"clicked" -> item.markClicked(elementId?.takeIf { it.isNotEmpty() })
|
|
969
|
+
"dismissed" -> item.markDismissed()
|
|
970
|
+
}
|
|
971
|
+
}
|
|
972
|
+
|
|
973
|
+
// ── Content cards (docs/PLACEMENTS_PLAN.md section 11, D444 Phase 3) ──
|
|
974
|
+
// The native SDK does the work - fetching, caching, the rate limit, the
|
|
975
|
+
// anonymous visitor's device state, reporting, the identity guard. The
|
|
976
|
+
// bridge hands the feed to JS as JSON (CardFeed.toJson, no delivery
|
|
977
|
+
// tokens) and routes JS's reports back to the native Card objects it last
|
|
978
|
+
// handed out, so a report carries the card's own token and a card of a
|
|
979
|
+
// person who is no longer here is dropped by the native check. An id the
|
|
980
|
+
// bridge never handed out goes to the id overload (the native SDK looks
|
|
981
|
+
// it up in its cache).
|
|
982
|
+
|
|
983
|
+
private val lastCards = java.util.concurrent.ConcurrentHashMap<String, io.joryio.sdk.cards.Card>()
|
|
984
|
+
private var cardsSubscription: java.io.Closeable? = null
|
|
985
|
+
|
|
986
|
+
/** [page]: a cursor page (added to what was handed out) rather than the whole feed (which replaces it). */
|
|
987
|
+
private fun cardsJson(feed: io.joryio.sdk.cards.CardFeed, page: Boolean): String {
|
|
988
|
+
if (!page) lastCards.clear()
|
|
989
|
+
feed.cards.forEach { lastCards[it.id] = it }
|
|
990
|
+
return feed.toJson()
|
|
991
|
+
}
|
|
992
|
+
|
|
993
|
+
/** `cursor`: a feed's `nextCursor` for the next page, null for the feed. */
|
|
994
|
+
@ReactMethod
|
|
995
|
+
fun getCards(cursor: String?, promise: Promise) {
|
|
996
|
+
if (!Joryio.isInitialized()) {
|
|
997
|
+
promise.resolve(io.joryio.sdk.cards.CardFeed.EMPTY.toJson())
|
|
998
|
+
return
|
|
999
|
+
}
|
|
1000
|
+
val c = cursor?.takeIf { it.isNotEmpty() }
|
|
1001
|
+
Joryio.getInstance().getCards(c) { feed ->
|
|
1002
|
+
promise.resolve(cardsJson(feed, page = c != null))
|
|
1003
|
+
}
|
|
1004
|
+
}
|
|
1005
|
+
|
|
1006
|
+
/** From the native cache, never a network call. */
|
|
1007
|
+
@ReactMethod
|
|
1008
|
+
fun getUnreadCardCount(promise: Promise) {
|
|
1009
|
+
promise.resolve(if (Joryio.isInitialized()) Joryio.getInstance().getUnreadCardCount() else 0)
|
|
1010
|
+
}
|
|
1011
|
+
|
|
1012
|
+
@ReactMethod
|
|
1013
|
+
fun markCardViewed(cardId: String?) {
|
|
1014
|
+
val id = cardId?.takeIf { it.isNotEmpty() } ?: return
|
|
1015
|
+
if (!Joryio.isInitialized()) return
|
|
1016
|
+
val sdk = Joryio.getInstance()
|
|
1017
|
+
lastCards[id]?.let { sdk.markCardViewed(it) } ?: sdk.markCardViewed(id)
|
|
1018
|
+
}
|
|
1019
|
+
|
|
1020
|
+
@ReactMethod
|
|
1021
|
+
fun markCardRead(cardId: String?) {
|
|
1022
|
+
val id = cardId?.takeIf { it.isNotEmpty() } ?: return
|
|
1023
|
+
if (!Joryio.isInitialized()) return
|
|
1024
|
+
val sdk = Joryio.getInstance()
|
|
1025
|
+
lastCards[id]?.let { sdk.markCardRead(it) } ?: sdk.markCardRead(id)
|
|
1026
|
+
}
|
|
1027
|
+
|
|
1028
|
+
@ReactMethod
|
|
1029
|
+
fun markCardClicked(cardId: String?) {
|
|
1030
|
+
val id = cardId?.takeIf { it.isNotEmpty() } ?: return
|
|
1031
|
+
if (!Joryio.isInitialized()) return
|
|
1032
|
+
val sdk = Joryio.getInstance()
|
|
1033
|
+
lastCards[id]?.let { sdk.markCardClicked(it) } ?: sdk.markCardClicked(id)
|
|
1034
|
+
}
|
|
1035
|
+
|
|
1036
|
+
@ReactMethod
|
|
1037
|
+
fun dismissCard(cardId: String?) {
|
|
1038
|
+
val id = cardId?.takeIf { it.isNotEmpty() } ?: return
|
|
1039
|
+
if (!Joryio.isInitialized()) return
|
|
1040
|
+
val sdk = Joryio.getInstance()
|
|
1041
|
+
lastCards[id]?.let { sdk.dismissCard(it) } ?: sdk.dismissCard(id)
|
|
1042
|
+
}
|
|
1043
|
+
|
|
1044
|
+
/** Queued until initialize() by the native companion, like refreshPlacements. */
|
|
1045
|
+
@ReactMethod
|
|
1046
|
+
fun refreshCards() {
|
|
1047
|
+
Joryio.refreshCards()
|
|
1048
|
+
}
|
|
1049
|
+
|
|
1050
|
+
@ReactMethod
|
|
1051
|
+
fun enableCardsUpdates() {
|
|
1052
|
+
if (cardsSubscription != null || !Joryio.isInitialized()) return
|
|
1053
|
+
cardsSubscription = Joryio.getInstance().onCardsUpdated { feed ->
|
|
1054
|
+
val params = Arguments.createMap().apply { putString("json", cardsJson(feed, page = false)) }
|
|
1055
|
+
reactApplicationContext
|
|
1056
|
+
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java)
|
|
1057
|
+
.emit("JoryioCardsUpdated", params)
|
|
1058
|
+
}
|
|
1059
|
+
}
|
|
1060
|
+
|
|
1061
|
+
@ReactMethod
|
|
1062
|
+
fun disableCardsUpdates() {
|
|
1063
|
+
cardsSubscription?.close()
|
|
1064
|
+
cardsSubscription = null
|
|
1065
|
+
}
|
|
1066
|
+
|
|
1067
|
+
// ── Links (setLinkHandler) ─────────────────────────────────────────
|
|
1068
|
+
|
|
1069
|
+
/** Links waiting for the JS handler's answer, oldest first; bounded so a JS side that never answers costs little. */
|
|
1070
|
+
private val pendingLinks = java.util.LinkedHashMap<String, io.joryio.sdk.core.JoryioLink>()
|
|
1071
|
+
private var nextLinkId = 0
|
|
1072
|
+
|
|
1073
|
+
/**
|
|
1074
|
+
* JS set a link handler: every link the native SDK is about to open goes
|
|
1075
|
+
* to JS first (event `JoryioLink`) and waits there for [completeLink]. The
|
|
1076
|
+
* native handler takes the link at once - a bridge cannot answer
|
|
1077
|
+
* synchronously - and JS hands a declined one back through completeLink.
|
|
1078
|
+
* The handler is app-wide in the native SDK, so this works before
|
|
1079
|
+
* initialize().
|
|
1080
|
+
*/
|
|
1081
|
+
@ReactMethod
|
|
1082
|
+
fun enableLinkHandler() {
|
|
1083
|
+
linkOwner.set(ownerToken)
|
|
1084
|
+
Joryio.setLinkHandler { link ->
|
|
1085
|
+
if (!reactApplicationContext.hasActiveReactInstance()) return@setLinkHandler false
|
|
1086
|
+
val id = synchronized(pendingLinks) {
|
|
1087
|
+
nextLinkId += 1
|
|
1088
|
+
val next = "l$nextLinkId"
|
|
1089
|
+
pendingLinks[next] = link
|
|
1090
|
+
while (pendingLinks.size > MAX_PENDING_LINKS) pendingLinks.remove(pendingLinks.keys.first())
|
|
1091
|
+
next
|
|
1092
|
+
}
|
|
1093
|
+
val params = Arguments.createMap().apply {
|
|
1094
|
+
putString("linkId", id)
|
|
1095
|
+
putString("url", link.url)
|
|
1096
|
+
putString("source", link.source.wire)
|
|
1097
|
+
putBoolean("isAppDeepLink", link.isAppDeepLink)
|
|
1098
|
+
link.campaignId?.let { putString("campaignId", it) }
|
|
1099
|
+
link.placementKey?.let { putString("placementKey", it) }
|
|
1100
|
+
link.itemId?.let { putString("itemId", it) }
|
|
1101
|
+
link.cardId?.let { putString("cardId", it) }
|
|
1102
|
+
}
|
|
1103
|
+
reactApplicationContext
|
|
1104
|
+
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java)
|
|
1105
|
+
.emit("JoryioLink", params)
|
|
1106
|
+
true
|
|
1107
|
+
}
|
|
1108
|
+
}
|
|
1109
|
+
|
|
1110
|
+
@ReactMethod
|
|
1111
|
+
fun disableLinkHandler() {
|
|
1112
|
+
if (linkOwner.compareAndSet(ownerToken, null)) Joryio.clearLinkHandler()
|
|
1113
|
+
}
|
|
1114
|
+
|
|
1115
|
+
/** The JS handler's answer: `handled` false opens the link as the SDK does without a handler. */
|
|
1116
|
+
@ReactMethod
|
|
1117
|
+
fun completeLink(linkId: String?, handled: Boolean?) {
|
|
1118
|
+
if (linkId == null) return
|
|
1119
|
+
val link = synchronized(pendingLinks) { pendingLinks.remove(linkId) } ?: return
|
|
1120
|
+
if (handled != true) link.openDefault()
|
|
1121
|
+
}
|
|
1122
|
+
|
|
903
1123
|
/**
|
|
904
1124
|
* Forget local frequency state so a campaign can be re-tested.
|
|
905
1125
|
*
|
|
@@ -1103,6 +1323,99 @@ class JoryioModule(private val reactContext: ReactApplicationContext) :
|
|
|
1103
1323
|
}
|
|
1104
1324
|
}
|
|
1105
1325
|
|
|
1326
|
+
// ─── Feature flags (BACKLOG D446) ─────────────────────────────────────
|
|
1327
|
+
//
|
|
1328
|
+
// Every getter carries the app's key AND default to the native getter
|
|
1329
|
+
// (the companion: the default before initialize()), which answers
|
|
1330
|
+
// value-or-default and logs the exposure as for a Kotlin caller. getFlag
|
|
1331
|
+
// and getJsonFlag resolve `{ value }`, so a JSON null stays null in JS.
|
|
1332
|
+
|
|
1333
|
+
/** The one native subscription this module holds; closed in invalidate(). */
|
|
1334
|
+
private var flagsSubscription: java.io.Closeable? = null
|
|
1335
|
+
|
|
1336
|
+
@ReactMethod
|
|
1337
|
+
fun getFlag(key: String?, defaultValue: Dynamic?, promise: Promise) {
|
|
1338
|
+
val fallback = fromDynamic(defaultValue)
|
|
1339
|
+
promise.resolve(wrapFlagValue(if (key.isNullOrEmpty()) fallback else Joryio.getFlag(key, fallback)))
|
|
1340
|
+
}
|
|
1341
|
+
|
|
1342
|
+
@ReactMethod
|
|
1343
|
+
fun getBoolFlag(key: String?, defaultValue: Dynamic?, promise: Promise) {
|
|
1344
|
+
// Dynamic, not Boolean: a JS null would throw before the method ran.
|
|
1345
|
+
val fallback = fromDynamic(defaultValue) as? Boolean ?: false
|
|
1346
|
+
promise.resolve(if (key.isNullOrEmpty()) fallback else Joryio.getBoolFlag(key, fallback))
|
|
1347
|
+
}
|
|
1348
|
+
|
|
1349
|
+
@ReactMethod
|
|
1350
|
+
fun getStringFlag(key: String?, defaultValue: String?, promise: Promise) {
|
|
1351
|
+
val fallback = defaultValue ?: ""
|
|
1352
|
+
promise.resolve(if (key.isNullOrEmpty()) fallback else Joryio.getStringFlag(key, fallback))
|
|
1353
|
+
}
|
|
1354
|
+
|
|
1355
|
+
@ReactMethod
|
|
1356
|
+
fun getNumberFlag(key: String?, defaultValue: Dynamic?, promise: Promise) {
|
|
1357
|
+
// Dynamic, not Double: a JS null would throw before the method ran.
|
|
1358
|
+
val fallback = fromDynamic(defaultValue) as? Double ?: 0.0
|
|
1359
|
+
promise.resolve(if (key.isNullOrEmpty()) fallback else Joryio.getNumberFlag(key, fallback))
|
|
1360
|
+
}
|
|
1361
|
+
|
|
1362
|
+
@ReactMethod
|
|
1363
|
+
fun getJsonFlag(key: String?, defaultValue: Dynamic?, promise: Promise) {
|
|
1364
|
+
val fallback = fromDynamic(defaultValue)
|
|
1365
|
+
promise.resolve(wrapFlagValue(if (key.isNullOrEmpty()) fallback else Joryio.getJsonFlag(key, fallback)))
|
|
1366
|
+
}
|
|
1367
|
+
|
|
1368
|
+
/** Every flag held, key -> value. Logs no exposure. */
|
|
1369
|
+
@ReactMethod
|
|
1370
|
+
fun getAllFlags(promise: Promise) {
|
|
1371
|
+
promise.resolve(Arguments.makeNativeMap(Joryio.getAllFlags()))
|
|
1372
|
+
}
|
|
1373
|
+
|
|
1374
|
+
/** Resolves once the answer is in (or the request failed: the held flags stay). */
|
|
1375
|
+
@ReactMethod
|
|
1376
|
+
fun refreshFlags(promise: Promise) {
|
|
1377
|
+
Joryio.refreshFlags { promise.resolve(null) }
|
|
1378
|
+
}
|
|
1379
|
+
|
|
1380
|
+
/** Start JoryioFlagsUpdated events (one native subscription; JS fans out). */
|
|
1381
|
+
@ReactMethod
|
|
1382
|
+
fun enableFlagsUpdates() {
|
|
1383
|
+
synchronized(this) {
|
|
1384
|
+
if (flagsSubscription != null) return
|
|
1385
|
+
flagsSubscription = Joryio.onFlagsUpdated { keys ->
|
|
1386
|
+
val params = Arguments.createMap()
|
|
1387
|
+
params.putArray("keys", Arguments.fromList(keys))
|
|
1388
|
+
reactContext
|
|
1389
|
+
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java)
|
|
1390
|
+
.emit("JoryioFlagsUpdated", params)
|
|
1391
|
+
}
|
|
1392
|
+
}
|
|
1393
|
+
}
|
|
1394
|
+
|
|
1395
|
+
private fun fromDynamic(value: Dynamic?): Any? = if (value == null) null else when (value.type) {
|
|
1396
|
+
ReadableType.Null -> null
|
|
1397
|
+
ReadableType.Boolean -> value.asBoolean()
|
|
1398
|
+
ReadableType.Number -> value.asDouble()
|
|
1399
|
+
ReadableType.String -> value.asString()
|
|
1400
|
+
ReadableType.Map -> value.asMap()?.toHashMap()
|
|
1401
|
+
ReadableType.Array -> value.asArray()?.toArrayList()
|
|
1402
|
+
}
|
|
1403
|
+
|
|
1404
|
+
private fun wrapFlagValue(value: Any?): WritableMap {
|
|
1405
|
+
val map = Arguments.createMap()
|
|
1406
|
+
@Suppress("UNCHECKED_CAST")
|
|
1407
|
+
when (value) {
|
|
1408
|
+
null -> map.putNull("value")
|
|
1409
|
+
is Boolean -> map.putBoolean("value", value)
|
|
1410
|
+
is Number -> map.putDouble("value", value.toDouble())
|
|
1411
|
+
is String -> map.putString("value", value)
|
|
1412
|
+
is Map<*, *> -> map.putMap("value", Arguments.makeNativeMap(value as Map<String, Any?>))
|
|
1413
|
+
is List<*> -> map.putArray("value", Arguments.makeNativeArray(value))
|
|
1414
|
+
else -> map.putString("value", value.toString())
|
|
1415
|
+
}
|
|
1416
|
+
return map
|
|
1417
|
+
}
|
|
1418
|
+
|
|
1106
1419
|
// ─── Utilities ─────────────────────────────────────────────────────────
|
|
1107
1420
|
|
|
1108
1421
|
@ReactMethod
|
|
@@ -1185,12 +1498,26 @@ class JoryioModule(private val reactContext: ReactApplicationContext) :
|
|
|
1185
1498
|
if (authOwner.compareAndSet(ownerToken, null)) {
|
|
1186
1499
|
Joryio.setSdkAuthenticationErrorHandler(null)
|
|
1187
1500
|
}
|
|
1501
|
+
// The link handler forwards to THIS module's JS; without it links open natively again.
|
|
1502
|
+
if (linkOwner.compareAndSet(ownerToken, null)) {
|
|
1503
|
+
Joryio.clearLinkHandler()
|
|
1504
|
+
}
|
|
1505
|
+
synchronized(pendingLinks) { pendingLinks.clear() }
|
|
1506
|
+
placementsSubscription?.close()
|
|
1507
|
+
placementsSubscription = null
|
|
1508
|
+
cardsSubscription?.close()
|
|
1509
|
+
cardsSubscription = null
|
|
1510
|
+
synchronized(this) {
|
|
1511
|
+
flagsSubscription?.close()
|
|
1512
|
+
flagsSubscription = null
|
|
1513
|
+
}
|
|
1188
1514
|
super.invalidate()
|
|
1189
1515
|
}
|
|
1190
1516
|
|
|
1191
1517
|
/** Identity of this module instance for the owner checks above. Holds nothing. */
|
|
1192
1518
|
private val ownerToken = Any()
|
|
1193
1519
|
|
|
1520
|
+
|
|
1194
1521
|
// Required for NativeEventEmitter
|
|
1195
1522
|
@ReactMethod
|
|
1196
1523
|
fun addListener(eventName: String?) {}
|
|
@@ -1212,6 +1539,10 @@ class JoryioModule(private val reactContext: ReactApplicationContext) :
|
|
|
1212
1539
|
/** The module whose callback the native SDK currently holds; see invalidate(). */
|
|
1213
1540
|
val inAppOwner = AtomicReference<Any?>(null)
|
|
1214
1541
|
val authOwner = AtomicReference<Any?>(null)
|
|
1542
|
+
val linkOwner = AtomicReference<Any?>(null)
|
|
1543
|
+
|
|
1544
|
+
/** Links held at once for the JS link handler's answer (enableLinkHandler). */
|
|
1545
|
+
const val MAX_PENDING_LINKS = 32
|
|
1215
1546
|
|
|
1216
1547
|
/**
|
|
1217
1548
|
* How long after returning to the foreground a permission answer may
|
|
@@ -22,6 +22,7 @@ class JoryioPackage : ReactPackage {
|
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
override fun createViewManagers(reactContext: ReactApplicationContext): List<ViewManager<*, *>> {
|
|
25
|
-
|
|
25
|
+
// <JoryioPlacement placementKey="..."/> and <JoryioCardFeed /> (D444).
|
|
26
|
+
return listOf(JoryioPlacementViewManager(), JoryioCardFeedViewManager())
|
|
26
27
|
}
|
|
27
28
|
}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
package io.joryio.reactnative
|
|
2
|
+
|
|
3
|
+
import android.content.Context
|
|
4
|
+
import android.view.View
|
|
5
|
+
import android.widget.FrameLayout
|
|
6
|
+
import com.facebook.react.bridge.Arguments
|
|
7
|
+
import com.facebook.react.bridge.ReactContext
|
|
8
|
+
import com.facebook.react.bridge.WritableMap
|
|
9
|
+
import com.facebook.react.uimanager.SimpleViewManager
|
|
10
|
+
import com.facebook.react.uimanager.ThemedReactContext
|
|
11
|
+
import com.facebook.react.uimanager.annotations.ReactProp
|
|
12
|
+
import com.facebook.react.uimanager.events.RCTEventEmitter
|
|
13
|
+
import io.joryio.sdk.placements.PLACEMENT_PRODUCT_CARD_WIDTH
|
|
14
|
+
import io.joryio.sdk.ui.PlacementView
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* The native view behind `<JoryioPlacement placementKey="..." />` (D444): the
|
|
18
|
+
* Android SDK's own PlacementView, so fetching, viewability, the holdout and
|
|
19
|
+
* the reports are exactly the native ones.
|
|
20
|
+
*
|
|
21
|
+
* React Native lays out only the views it created, so this wrapper measures
|
|
22
|
+
* and lays out the PlacementView itself on every layout request, and tells JS
|
|
23
|
+
* the content height (`onPlacementRender`) so the JS component can size the
|
|
24
|
+
* spot - `collapse` gives 0.
|
|
25
|
+
*/
|
|
26
|
+
class JoryioPlacementViewManager : SimpleViewManager<JoryioPlacementHost>() {
|
|
27
|
+
override fun getName() = "JoryioPlacementView"
|
|
28
|
+
|
|
29
|
+
override fun createViewInstance(context: ThemedReactContext) = JoryioPlacementHost(context)
|
|
30
|
+
|
|
31
|
+
@ReactProp(name = "placementKey")
|
|
32
|
+
fun setPlacementKey(view: JoryioPlacementHost, key: String?) {
|
|
33
|
+
view.placement.setPlacementKey(key ?: "")
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// The built-in product cards row: the native PlacementView's properties.
|
|
37
|
+
@ReactProp(name = "showProducts", defaultBoolean = true)
|
|
38
|
+
fun setShowProducts(view: JoryioPlacementHost, show: Boolean) {
|
|
39
|
+
view.placement.showProducts = show
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
@ReactProp(name = "productButtonText")
|
|
43
|
+
fun setProductButtonText(view: JoryioPlacementHost, text: String?) {
|
|
44
|
+
view.placement.productButtonText = text
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
@ReactProp(name = "productCardWidth", defaultInt = PLACEMENT_PRODUCT_CARD_WIDTH)
|
|
48
|
+
fun setProductCardWidth(view: JoryioPlacementHost, width: Int) {
|
|
49
|
+
view.placement.productCardWidth = width
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
override fun getExportedCustomDirectEventTypeConstants(): Map<String, Any> = mapOf(
|
|
53
|
+
"onPlacementRender" to mapOf("registrationName" to "onPlacementRender"),
|
|
54
|
+
"onPlacementDeepLink" to mapOf("registrationName" to "onPlacementDeepLink"),
|
|
55
|
+
)
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
class JoryioPlacementHost(context: Context) : FrameLayout(context) {
|
|
59
|
+
val placement = PlacementView(context)
|
|
60
|
+
|
|
61
|
+
init {
|
|
62
|
+
addView(placement, LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT))
|
|
63
|
+
placement.onRender = { p ->
|
|
64
|
+
post {
|
|
65
|
+
measureAndLayout()
|
|
66
|
+
emit("onPlacementRender", Arguments.createMap().apply {
|
|
67
|
+
putString("placementKey", p.placementKey)
|
|
68
|
+
putInt("itemCount", p.items.size)
|
|
69
|
+
putBoolean("isControl", p.isControl)
|
|
70
|
+
putString("emptyBehavior", p.emptyBehavior)
|
|
71
|
+
putDouble("height", placement.measuredHeight / resources.displayMetrics.density.toDouble())
|
|
72
|
+
})
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
// deep_link buttons go to JS, which routes them (the SDK opens only http(s)).
|
|
76
|
+
placement.onDeepLink = { url, item ->
|
|
77
|
+
emit("onPlacementDeepLink", Arguments.createMap().apply {
|
|
78
|
+
putString("url", url)
|
|
79
|
+
putString("itemId", item.id)
|
|
80
|
+
})
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
private fun emit(name: String, body: WritableMap) {
|
|
85
|
+
(context as? ReactContext)?.getJSModule(RCTEventEmitter::class.java)?.receiveEvent(id, name, body)
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
private fun measureAndLayout() {
|
|
89
|
+
val w = if (width > 0) width else resources.displayMetrics.widthPixels
|
|
90
|
+
placement.measure(
|
|
91
|
+
View.MeasureSpec.makeMeasureSpec(w, View.MeasureSpec.EXACTLY),
|
|
92
|
+
View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED),
|
|
93
|
+
)
|
|
94
|
+
placement.layout(0, 0, placement.measuredWidth, placement.measuredHeight)
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
private val relayout = Runnable { measureAndLayout() }
|
|
98
|
+
|
|
99
|
+
override fun requestLayout() {
|
|
100
|
+
super.requestLayout()
|
|
101
|
+
// Native children change size (an image arrives, the card is drawn);
|
|
102
|
+
// React Native would not lay them out.
|
|
103
|
+
post(relayout)
|
|
104
|
+
}
|
|
105
|
+
}
|