@ethicly/react-native 0.3.0 → 0.4.0
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 +59 -0
- package/README.md +112 -13
- package/lib/commonjs/core/cache.js +2 -0
- package/lib/commonjs/core/client.js +168 -53
- package/lib/commonjs/core/config.js +4 -1
- package/lib/commonjs/core/houseTracker.js +92 -0
- package/lib/commonjs/react/EthiclyInterstitial.js +23 -4
- package/lib/commonjs/react/useEthiclyInterstitial.js +22 -6
- package/lib/commonjs/version.js +1 -1
- package/lib/module/core/cache.js +2 -0
- package/lib/module/core/client.js +168 -53
- package/lib/module/core/config.js +4 -1
- package/lib/module/core/houseTracker.js +88 -0
- package/lib/module/react/EthiclyInterstitial.js +23 -4
- package/lib/module/react/useEthiclyInterstitial.js +22 -6
- package/lib/module/version.js +1 -1
- package/lib/typescript/core/cache.d.ts +3 -1
- package/lib/typescript/core/client.d.ts +24 -4
- package/lib/typescript/core/houseTracker.d.ts +53 -0
- package/lib/typescript/core/index.d.ts +1 -1
- package/lib/typescript/core/types.d.ts +44 -2
- package/lib/typescript/react/EthiclyInterstitial.d.ts +7 -0
- package/lib/typescript/react/useEthiclyInterstitial.d.ts +16 -2
- package/lib/typescript/version.d.ts +1 -1
- package/package.json +1 -1
- package/src/core/cache.ts +4 -2
- package/src/core/client.ts +186 -55
- package/src/core/config.ts +4 -1
- package/src/core/houseTracker.ts +108 -0
- package/src/core/index.ts +1 -1
- package/src/core/types.ts +44 -2
- package/src/react/EthiclyInterstitial.tsx +26 -4
- package/src/react/useEthiclyInterstitial.ts +38 -8
- package/src/version.ts +1 -1
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
// Optional ready-made fullscreen screen. Needs expo-video (Expo SDK 52+).
|
|
2
2
|
// Layout follows a typical in-app video player: 9:16 video, a skip control that counts
|
|
3
3
|
// down then reads "Skip Ad", a white call-to-action button, an optional
|
|
4
|
-
// "Remove ads" slot and a small "Sponsored by Ethicly.ch" line under it.
|
|
4
|
+
// "Remove ads" slot and a small "Sponsored by Ethicly.ch" line under it. The
|
|
5
|
+
// line follows ad.showSponsorLabel: hidden for house ads, and for paid ads when
|
|
6
|
+
// the publisher switched it off in the dashboard.
|
|
5
7
|
// Video starts with sound unless the effective audio (the `audio` prop, else
|
|
6
8
|
// ad.audio: createEthicly's `audio` option, else /config) is 'none' or 'optional'.
|
|
7
9
|
// The controls keep clear of the notch, status bar and home indicator: see
|
|
@@ -26,6 +28,13 @@ export interface EthiclyInterstitialProps {
|
|
|
26
28
|
/** Shows a "Remove ads" link under the button that calls this. */
|
|
27
29
|
onRemoveAds?(): void;
|
|
28
30
|
removeAdsLabel?: string;
|
|
31
|
+
/**
|
|
32
|
+
* House ads only: a tap on the button counts the tap, closes the ad (as
|
|
33
|
+
* onClose does) and calls this instead of opening the house ad's link, for
|
|
34
|
+
* example to open the app's premium screen. Wins over the hook's and
|
|
35
|
+
* createEthicly's onHouseAdPress. Paid ads always open the advertiser's page.
|
|
36
|
+
*/
|
|
37
|
+
onHouseAdPress?(ad: EthiclyAd): void;
|
|
29
38
|
/** Replaces the "Remove ads" link with anything the app wants. */
|
|
30
39
|
renderBelowButton?(): React.ReactNode;
|
|
31
40
|
/** Default true: wraps the screen in a fullscreen Modal. */
|
|
@@ -160,7 +169,7 @@ interface BodyProps extends EthiclyInterstitialProps {
|
|
|
160
169
|
}
|
|
161
170
|
|
|
162
171
|
function InterstitialBody({
|
|
163
|
-
ad, tracker, onClose, onRemoveAds, removeAdsLabel, renderBelowButton, skipStyle, skipTextStyle, insets, backRef, audio: audioProp,
|
|
172
|
+
ad, tracker, onClose, onRemoveAds, removeAdsLabel, onHouseAdPress, renderBelowButton, skipStyle, skipTextStyle, insets, backRef, audio: audioProp,
|
|
164
173
|
}: BodyProps) {
|
|
165
174
|
const audio = effectiveAudio(audioProp, ad);
|
|
166
175
|
const safe = useSafeInsets(insets);
|
|
@@ -291,12 +300,25 @@ function InterstitialBody({
|
|
|
291
300
|
}, [ended, failed, isVideo, onClose, tracker]);
|
|
292
301
|
|
|
293
302
|
const onCta = useCallback(() => {
|
|
303
|
+
// A house ad the app routes to its own screen: count the tap, close the
|
|
304
|
+
// ad the normal way, then hand over. Never for a paid ad.
|
|
305
|
+
const housePress = ad.house
|
|
306
|
+
? onHouseAdPress || (tracker as { houseAdPress?: (a: EthiclyAd) => void }).houseAdPress
|
|
307
|
+
: undefined;
|
|
308
|
+
if (housePress) {
|
|
309
|
+
// A second tap before the screen unmounts must not run the handler twice.
|
|
310
|
+
if (closedRef.current) return;
|
|
311
|
+
void tracker.clicked({ open: false });
|
|
312
|
+
close();
|
|
313
|
+
try { housePress(ad); } catch { /* the app's handler must not break the screen */ }
|
|
314
|
+
return;
|
|
315
|
+
}
|
|
294
316
|
if (isVideo) player.pause();
|
|
295
317
|
// Once the user has visited the advertiser, they can always close the ad
|
|
296
318
|
// when they come back.
|
|
297
319
|
setClicked(true);
|
|
298
320
|
void tracker.clicked();
|
|
299
|
-
}, [isVideo, player, tracker]);
|
|
321
|
+
}, [ad, close, isVideo, onHouseAdPress, player, tracker]);
|
|
300
322
|
|
|
301
323
|
const toggleSound = useCallback(() => {
|
|
302
324
|
setMuted((m) => {
|
|
@@ -373,7 +395,7 @@ function InterstitialBody({
|
|
|
373
395
|
<Text style={styles.removeAds}>{removeAdsLabel || 'Remove ads'}</Text>
|
|
374
396
|
</Pressable>
|
|
375
397
|
) : null}
|
|
376
|
-
<Text style={styles.sponsor}>Sponsored by Ethicly.ch</Text>
|
|
398
|
+
{ad.showSponsorLabel ? <Text style={styles.sponsor}>Sponsored by Ethicly.ch</Text> : null}
|
|
377
399
|
</View>
|
|
378
400
|
</View>
|
|
379
401
|
);
|
|
@@ -8,13 +8,27 @@ import type { EthiclyAd, NextAdStatus, NoFillReason, Tracker } from '../core/typ
|
|
|
8
8
|
export interface UseEthiclyInterstitialOptions {
|
|
9
9
|
/** Preload on mount and after each dismiss. Default true. */
|
|
10
10
|
preload?: boolean;
|
|
11
|
+
/**
|
|
12
|
+
* false treats a house ad as no fill, so `reason` is set and the app shows
|
|
13
|
+
* its own fallback. Default: the client's setting (createEthicly houseAds).
|
|
14
|
+
*/
|
|
15
|
+
houseAds?: boolean;
|
|
16
|
+
/**
|
|
17
|
+
* House ads only: where EthiclyInterstitial sends a tap on the button
|
|
18
|
+
* instead of opening the link (the ad closes first). Wins over
|
|
19
|
+
* createEthicly's onHouseAdPress; the screen's own prop wins over this.
|
|
20
|
+
*/
|
|
21
|
+
onHouseAdPress?: (ad: EthiclyAd) => void;
|
|
11
22
|
}
|
|
12
23
|
|
|
13
24
|
export interface EthiclyInterstitialState {
|
|
14
|
-
/** The ad to render, set by a successful show(). */
|
|
25
|
+
/** The ad to render, set by a successful show(). `ad.house` is true for the publisher's house ad. */
|
|
15
26
|
ad: EthiclyAd | null;
|
|
16
27
|
tracker: Tracker | null;
|
|
17
|
-
/**
|
|
28
|
+
/**
|
|
29
|
+
* Why the last show() found no ad: show your own fallback if you have one,
|
|
30
|
+
* except for 'ads_disabled' (a paid user). Null when a house ad was shown.
|
|
31
|
+
*/
|
|
18
32
|
reason: NoFillReason | null;
|
|
19
33
|
loading: boolean;
|
|
20
34
|
/** Load the ad to show now. Resolves true when `ad` is set, false on no fill. */
|
|
@@ -31,6 +45,9 @@ export function useEthiclyInterstitial(
|
|
|
31
45
|
options: UseEthiclyInterstitialOptions = {},
|
|
32
46
|
): EthiclyInterstitialState {
|
|
33
47
|
const preload = options.preload !== false;
|
|
48
|
+
const houseAds = options.houseAds;
|
|
49
|
+
const housePressRef = useRef(options.onHouseAdPress);
|
|
50
|
+
housePressRef.current = options.onHouseAdPress;
|
|
34
51
|
const [current, setCurrent] = useState<{ ad: EthiclyAd; tracker: Tracker } | null>(null);
|
|
35
52
|
const [reason, setReason] = useState<NoFillReason | null>(null);
|
|
36
53
|
const [loading, setLoading] = useState(false);
|
|
@@ -40,19 +57,32 @@ export function useEthiclyInterstitial(
|
|
|
40
57
|
|
|
41
58
|
useEffect(() => {
|
|
42
59
|
mounted.current = true;
|
|
43
|
-
if (preload) void ethicly.preload();
|
|
60
|
+
if (preload) void ethicly.preload({ houseAds });
|
|
44
61
|
return () => {
|
|
45
62
|
mounted.current = false;
|
|
46
63
|
void currentRef.current?.tracker.closed();
|
|
47
64
|
};
|
|
48
|
-
}, [ethicly, preload]);
|
|
65
|
+
}, [ethicly, preload, houseAds]);
|
|
49
66
|
|
|
50
67
|
const show = useCallback(async (): Promise<boolean> => {
|
|
51
68
|
setLoading(true);
|
|
52
69
|
try {
|
|
53
|
-
const r = await ethicly.loadInterstitial();
|
|
70
|
+
const r = await ethicly.loadInterstitial({ houseAds });
|
|
54
71
|
if (!mounted.current) return false;
|
|
55
72
|
if (r.ad) {
|
|
73
|
+
if (r.ad.house) {
|
|
74
|
+
// Read at tap time: the hook's latest handler wins, else the client's
|
|
75
|
+
// (set when the ad was built), else the link opens. A handler added or
|
|
76
|
+
// removed after the ad loaded is respected.
|
|
77
|
+
const t = r.tracker as { houseAdPress?: (a: EthiclyAd) => void };
|
|
78
|
+
const clientPress = t.houseAdPress;
|
|
79
|
+
Object.defineProperty(t, 'houseAdPress', {
|
|
80
|
+
configurable: true,
|
|
81
|
+
enumerable: true,
|
|
82
|
+
get: () => housePressRef.current ?? clientPress,
|
|
83
|
+
set: () => { /* fixed for this ad: the hook resolves it */ },
|
|
84
|
+
});
|
|
85
|
+
}
|
|
56
86
|
setCurrent({ ad: r.ad, tracker: r.tracker });
|
|
57
87
|
setReason(null);
|
|
58
88
|
return true;
|
|
@@ -62,13 +92,13 @@ export function useEthiclyInterstitial(
|
|
|
62
92
|
} finally {
|
|
63
93
|
if (mounted.current) setLoading(false);
|
|
64
94
|
}
|
|
65
|
-
}, [ethicly]);
|
|
95
|
+
}, [ethicly, houseAds]);
|
|
66
96
|
|
|
67
97
|
const dismiss = useCallback(() => {
|
|
68
98
|
void currentRef.current?.tracker.closed();
|
|
69
99
|
setCurrent(null);
|
|
70
|
-
if (preload) void ethicly.preload();
|
|
71
|
-
}, [ethicly, preload]);
|
|
100
|
+
if (preload) void ethicly.preload({ houseAds });
|
|
101
|
+
}, [ethicly, preload, houseAds]);
|
|
72
102
|
|
|
73
103
|
const canShow = useCallback(() => ethicly.canShow(), [ethicly]);
|
|
74
104
|
const nextAdStatus = useCallback(() => ethicly.nextAdStatus(), [ethicly]);
|
package/src/version.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/** SDK version, sent as sdk_version and in X-Ethicly-SDK. Keep in step with package.json. */
|
|
2
|
-
export const SDK_VERSION = '0.
|
|
2
|
+
export const SDK_VERSION = '0.4.0';
|