@chipmobilesdk/rn-ads 0.4.0 → 0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +224 -196
- package/README.md +6 -1
- package/package.json +2 -5
- package/skills/sdk-rn-ads/SKILL.md +1 -2
- package/src/config/resolveAdUnit.ts +85 -85
- package/src/config/types.ts +318 -321
- package/src/config/validate.ts +1 -4
- package/src/core/adOriginatedReturn.ts +134 -134
- package/src/core/adsInstance.ts +76 -37
- package/src/core/consentFlow.ts +182 -180
- package/src/core/enablement.ts +76 -76
- package/src/core/fullScreenLock.ts +54 -54
- package/src/core/gates.ts +94 -91
- package/src/core/initMachine.ts +187 -187
- package/src/core/placementMachine.ts +124 -114
- package/src/core/privacyGate.ts +93 -85
- package/src/core/retryPolicy.ts +127 -127
- package/src/core/rewardedSession.ts +84 -84
- package/src/core/timers.ts +216 -208
- package/src/diagnostics/correlation.ts +31 -31
- package/src/diagnostics/errors.ts +230 -234
- package/src/diagnostics/events.ts +238 -232
- package/src/engine/admobEngine.ts +399 -399
- package/src/engine/port.ts +144 -125
- package/src/engine/testAdUnits.ts +61 -61
- package/src/react/AdsBanner.tsx +17 -17
- package/src/react/AdsProvider.tsx +57 -57
- package/src/react/hooks.ts +75 -75
- package/src/testing/index.ts +463 -460
package/src/react/hooks.ts
CHANGED
|
@@ -1,75 +1,75 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* React bindings (US1, FR-027).
|
|
3
|
-
*
|
|
4
|
-
* Each hook subscribes to exactly what it reads. `usePlacementState` subscribes
|
|
5
|
-
* to one placement rather than to the whole event stream, which is what keeps a
|
|
6
|
-
* banner from re-rendering because an unrelated interstitial was clicked —
|
|
7
|
-
* PERF-002's bounded re-render assertion depends on it.
|
|
8
|
-
*
|
|
9
|
-
* None of these hand back an ad object. A consumer queries and subscribes to
|
|
10
|
-
* state; it never holds provider-owned memory (FR-027).
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
import { useEffect, useState } from 'react';
|
|
14
|
-
|
|
15
|
-
import type { InitStatus, PlacementState } from '../config/types';
|
|
16
|
-
import type { AdEventListener } from '../diagnostics/events';
|
|
17
|
-
import { useAds } from './AdsProvider';
|
|
18
|
-
|
|
19
|
-
/** Live state for one placement. `unavailable` outside a provider. */
|
|
20
|
-
export function usePlacementState(placementKey: string): PlacementState {
|
|
21
|
-
const ads = useAds();
|
|
22
|
-
const [state, setState] = useState<PlacementState>(() =>
|
|
23
|
-
ads ? ads.getPlacementState(placementKey) : 'unavailable',
|
|
24
|
-
);
|
|
25
|
-
|
|
26
|
-
useEffect(() => {
|
|
27
|
-
if (!ads) {
|
|
28
|
-
setState('unavailable');
|
|
29
|
-
return;
|
|
30
|
-
}
|
|
31
|
-
// Re-read on subscribe: the state may have moved between the initial
|
|
32
|
-
// render and this effect, and dropping that transition would leave the
|
|
33
|
-
// UI showing a state the instance has already left.
|
|
34
|
-
setState(ads.getPlacementState(placementKey));
|
|
35
|
-
return ads.subscribePlacement(placementKey, setState);
|
|
36
|
-
}, [ads, placementKey]);
|
|
37
|
-
|
|
38
|
-
return state;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
/** Live initialization status. `unavailable` outside a provider. */
|
|
42
|
-
export function useAdsStatus(): InitStatus {
|
|
43
|
-
const ads = useAds();
|
|
44
|
-
const [status, setStatus] = useState<InitStatus>(() => (ads ? ads.getStatus() : 'unavailable'));
|
|
45
|
-
|
|
46
|
-
useEffect(() => {
|
|
47
|
-
if (!ads) {
|
|
48
|
-
setStatus('unavailable');
|
|
49
|
-
return;
|
|
50
|
-
}
|
|
51
|
-
setStatus(ads.getStatus());
|
|
52
|
-
return ads.subscribeStatus(setStatus);
|
|
53
|
-
}, [ads]);
|
|
54
|
-
|
|
55
|
-
return status;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* Forwards every event to a listener without causing a render.
|
|
60
|
-
*
|
|
61
|
-
* Deliberately does not accumulate events into state: a package that kept an
|
|
62
|
-
* event log would be persisting exactly the kind of history it promises not to
|
|
63
|
-
* (FR-021), and re-rendering on every impression would defeat PERF-002. A screen
|
|
64
|
-
* that wants a visible log keeps its own.
|
|
65
|
-
*/
|
|
66
|
-
export function useAdsEvents(listener: AdEventListener): void {
|
|
67
|
-
const ads = useAds();
|
|
68
|
-
|
|
69
|
-
useEffect(() => {
|
|
70
|
-
if (!ads) {
|
|
71
|
-
return;
|
|
72
|
-
}
|
|
73
|
-
return ads.subscribeEvents(listener);
|
|
74
|
-
}, [ads, listener]);
|
|
75
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* React bindings (US1, FR-027).
|
|
3
|
+
*
|
|
4
|
+
* Each hook subscribes to exactly what it reads. `usePlacementState` subscribes
|
|
5
|
+
* to one placement rather than to the whole event stream, which is what keeps a
|
|
6
|
+
* banner from re-rendering because an unrelated interstitial was clicked —
|
|
7
|
+
* PERF-002's bounded re-render assertion depends on it.
|
|
8
|
+
*
|
|
9
|
+
* None of these hand back an ad object. A consumer queries and subscribes to
|
|
10
|
+
* state; it never holds provider-owned memory (FR-027).
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import { useEffect, useState } from 'react';
|
|
14
|
+
|
|
15
|
+
import type { InitStatus, PlacementState } from '../config/types';
|
|
16
|
+
import type { AdEventListener } from '../diagnostics/events';
|
|
17
|
+
import { useAds } from './AdsProvider';
|
|
18
|
+
|
|
19
|
+
/** Live state for one placement. `unavailable` outside a provider. */
|
|
20
|
+
export function usePlacementState(placementKey: string): PlacementState {
|
|
21
|
+
const ads = useAds();
|
|
22
|
+
const [state, setState] = useState<PlacementState>(() =>
|
|
23
|
+
ads ? ads.getPlacementState(placementKey) : 'unavailable',
|
|
24
|
+
);
|
|
25
|
+
|
|
26
|
+
useEffect(() => {
|
|
27
|
+
if (!ads) {
|
|
28
|
+
setState('unavailable');
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
// Re-read on subscribe: the state may have moved between the initial
|
|
32
|
+
// render and this effect, and dropping that transition would leave the
|
|
33
|
+
// UI showing a state the instance has already left.
|
|
34
|
+
setState(ads.getPlacementState(placementKey));
|
|
35
|
+
return ads.subscribePlacement(placementKey, setState);
|
|
36
|
+
}, [ads, placementKey]);
|
|
37
|
+
|
|
38
|
+
return state;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** Live initialization status. `unavailable` outside a provider. */
|
|
42
|
+
export function useAdsStatus(): InitStatus {
|
|
43
|
+
const ads = useAds();
|
|
44
|
+
const [status, setStatus] = useState<InitStatus>(() => (ads ? ads.getStatus() : 'unavailable'));
|
|
45
|
+
|
|
46
|
+
useEffect(() => {
|
|
47
|
+
if (!ads) {
|
|
48
|
+
setStatus('unavailable');
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
setStatus(ads.getStatus());
|
|
52
|
+
return ads.subscribeStatus(setStatus);
|
|
53
|
+
}, [ads]);
|
|
54
|
+
|
|
55
|
+
return status;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Forwards every event to a listener without causing a render.
|
|
60
|
+
*
|
|
61
|
+
* Deliberately does not accumulate events into state: a package that kept an
|
|
62
|
+
* event log would be persisting exactly the kind of history it promises not to
|
|
63
|
+
* (FR-021), and re-rendering on every impression would defeat PERF-002. A screen
|
|
64
|
+
* that wants a visible log keeps its own.
|
|
65
|
+
*/
|
|
66
|
+
export function useAdsEvents(listener: AdEventListener): void {
|
|
67
|
+
const ads = useAds();
|
|
68
|
+
|
|
69
|
+
useEffect(() => {
|
|
70
|
+
if (!ads) {
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
return ads.subscribeEvents(listener);
|
|
74
|
+
}, [ads, listener]);
|
|
75
|
+
}
|