react-native-applovin-max 6.4.2 → 7.0.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/README.md +1 -1
- package/android/build.gradle +46 -100
- package/android/gradle.properties +4 -4
- package/android/src/main/AndroidManifest.xml +2 -2
- package/android/src/main/AndroidManifestNew.xml +2 -0
- package/android/src/main/java/com/applovin/reactnative/AppLovinMAXAdView.java +123 -163
- package/android/src/main/java/com/applovin/reactnative/AppLovinMAXAdViewManager.java +24 -17
- package/android/src/main/java/com/applovin/reactnative/AppLovinMAXAdViewUiComponent.java +239 -0
- package/android/src/main/java/com/applovin/reactnative/AppLovinMAXModule.java +297 -336
- package/android/src/main/java/com/applovin/reactnative/AppLovinMAXNativeAdView.java +13 -12
- package/android/src/main/java/com/applovin/reactnative/AppLovinMAXNativeAdViewManager.java +11 -14
- package/android/src/main/java/com/applovin/reactnative/AppLovinMAXPackage.java +3 -3
- package/ios/AppLovinMAX.h +1 -1
- package/ios/AppLovinMAX.m +62 -12
- package/ios/AppLovinMAXAdView.h +12 -0
- package/ios/AppLovinMAXAdView.m +120 -142
- package/ios/AppLovinMAXAdViewUIComponent.h +27 -0
- package/ios/AppLovinMAXAdViewUIComponent.m +199 -0
- package/package.json +94 -21
- package/react-native-applovin-max.podspec +30 -6
- package/src/AdView.tsx +83 -26
- package/src/AppLovinMAX.ts +1 -1
- package/src/InterstitialAd.ts +1 -3
- package/src/MRecAd.ts +2 -8
- package/src/TargetingData.ts +2 -15
- package/src/index.ts +9 -10
- package/src/nativeAd/NativeAdView.tsx +33 -49
- package/src/nativeAd/NativeAdViewComponents.tsx +22 -31
- package/src/types/AdViewProps.ts +29 -1
- package/android/.project +0 -17
- package/android/.settings/org.eclipse.buildship.core.prefs +0 -13
- package/android/gradle/wrapper/gradle-wrapper.jar +0 -0
- package/android/gradle/wrapper/gradle-wrapper.properties +0 -6
- package/android/gradlew +0 -172
- package/android/gradlew.bat +0 -84
- package/ios/AppLovinMAX.xcodeproj/project.pbxproj +0 -368
- package/ios/AppLovinMAX.xcodeproj/xcshareddata/xcschemes/AppLovinMAX.xcscheme +0 -67
- package/ios/AppLovinMAX.xcworkspace/contents.xcworkspacedata +0 -10
- package/ios/AppLovinMAX.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +0 -8
- package/ios/Podfile +0 -40
- package/ios/Podfile.lock +0 -373
package/package.json
CHANGED
|
@@ -1,39 +1,112 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-applovin-max",
|
|
3
|
-
"author": "AppLovin Corporation",
|
|
4
|
-
"version": "
|
|
3
|
+
"author": "AppLovin Corporation <support@applovin.com> (https://applovin.com)",
|
|
4
|
+
"version": "7.0.0",
|
|
5
5
|
"description": "AppLovin MAX React Native Plugin for Android and iOS",
|
|
6
|
-
"
|
|
7
|
-
"
|
|
8
|
-
"
|
|
6
|
+
"main": "lib/commonjs/index",
|
|
7
|
+
"module": "lib/module/index",
|
|
8
|
+
"types": "lib/typescript/src/index.d.ts",
|
|
9
9
|
"react-native": "src/index",
|
|
10
10
|
"source": "src/index",
|
|
11
|
-
"module": "lib/module/index",
|
|
12
11
|
"files": [
|
|
13
12
|
"src",
|
|
13
|
+
"lib",
|
|
14
14
|
"android",
|
|
15
15
|
"ios",
|
|
16
16
|
"react-native-applovin-max.podspec",
|
|
17
|
-
"package.json"
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
"
|
|
22
|
-
"
|
|
23
|
-
"
|
|
17
|
+
"package.json",
|
|
18
|
+
"!ios/build",
|
|
19
|
+
"!android/build",
|
|
20
|
+
"!android/gradle",
|
|
21
|
+
"!android/gradlew",
|
|
22
|
+
"!android/gradlew.bat",
|
|
23
|
+
"!android/local.properties",
|
|
24
|
+
"!**/__tests__",
|
|
25
|
+
"!**/__fixtures__",
|
|
26
|
+
"!**/__mocks__",
|
|
27
|
+
"!**/.*"
|
|
24
28
|
],
|
|
25
|
-
"repository":
|
|
29
|
+
"repository": {
|
|
30
|
+
"type": "git",
|
|
31
|
+
"url": "git+https://github.com/AppLovin/AppLovin-MAX-React-Native.git"
|
|
32
|
+
},
|
|
33
|
+
"license": "MIT",
|
|
34
|
+
"bugs": {
|
|
35
|
+
"url": "https://github.com/AppLovin/AppLovin-MAX-React-Native/issues"
|
|
36
|
+
},
|
|
37
|
+
"homepage": "https://github.com/AppLovin/AppLovin-MAX-React-Native#readme",
|
|
26
38
|
"devDependencies": {
|
|
27
|
-
"@
|
|
28
|
-
"@
|
|
29
|
-
"@
|
|
30
|
-
"
|
|
31
|
-
"
|
|
32
|
-
"react": "^
|
|
33
|
-
"
|
|
39
|
+
"@commitlint/config-conventional": "^17.0.2",
|
|
40
|
+
"@evilmartians/lefthook": "^1.5.0",
|
|
41
|
+
"@react-native/eslint-config": "^0.73.1",
|
|
42
|
+
"@release-it/conventional-changelog": "^5.0.0",
|
|
43
|
+
"@types/jest": "^29.5.5",
|
|
44
|
+
"@types/react": "^18.2.44",
|
|
45
|
+
"commitlint": "^17.0.2",
|
|
46
|
+
"eslint": "^8.51.0",
|
|
47
|
+
"eslint-config-prettier": "^9.0.0",
|
|
48
|
+
"eslint-plugin-prettier": "^5.0.1",
|
|
49
|
+
"jest": "^29.7.0",
|
|
50
|
+
"prettier": "^3.0.3",
|
|
51
|
+
"react": "18.2.0",
|
|
52
|
+
"react-native": "0.73.6",
|
|
53
|
+
"typescript": "^5.2.2"
|
|
54
|
+
},
|
|
55
|
+
"resolutions": {
|
|
56
|
+
"@types/react": "^18.2.44"
|
|
34
57
|
},
|
|
35
58
|
"peerDependencies": {
|
|
36
59
|
"react": "*",
|
|
37
60
|
"react-native": "*"
|
|
61
|
+
},
|
|
62
|
+
"workspaces": [
|
|
63
|
+
"example"
|
|
64
|
+
],
|
|
65
|
+
"packageManager": "yarn@3.6.1",
|
|
66
|
+
"jest": {
|
|
67
|
+
"preset": "react-native",
|
|
68
|
+
"modulePathIgnorePatterns": [
|
|
69
|
+
"<rootDir>/example/node_modules",
|
|
70
|
+
"<rootDir>/lib/"
|
|
71
|
+
]
|
|
72
|
+
},
|
|
73
|
+
"commitlint": {
|
|
74
|
+
"extends": [
|
|
75
|
+
"@commitlint/config-conventional"
|
|
76
|
+
]
|
|
77
|
+
},
|
|
78
|
+
"eslintConfig": {
|
|
79
|
+
"root": true,
|
|
80
|
+
"extends": [
|
|
81
|
+
"@react-native",
|
|
82
|
+
"prettier"
|
|
83
|
+
],
|
|
84
|
+
"rules": {
|
|
85
|
+
"prettier/prettier": [
|
|
86
|
+
"error",
|
|
87
|
+
{
|
|
88
|
+
"quoteProps": "consistent",
|
|
89
|
+
"singleQuote": true,
|
|
90
|
+
"tabWidth": 4,
|
|
91
|
+
"trailingComma": "es5",
|
|
92
|
+
"useTabs": false,
|
|
93
|
+
"printWidth": 180,
|
|
94
|
+
"endOfLine": "auto"
|
|
95
|
+
}
|
|
96
|
+
]
|
|
97
|
+
}
|
|
98
|
+
},
|
|
99
|
+
"eslintIgnore": [
|
|
100
|
+
"node_modules/",
|
|
101
|
+
"lib/"
|
|
102
|
+
],
|
|
103
|
+
"prettier": {
|
|
104
|
+
"quoteProps": "consistent",
|
|
105
|
+
"singleQuote": true,
|
|
106
|
+
"tabWidth": 4,
|
|
107
|
+
"trailingComma": "es5",
|
|
108
|
+
"useTabs": false,
|
|
109
|
+
"printWidth": 180,
|
|
110
|
+
"endOfLine": "auto"
|
|
38
111
|
}
|
|
39
112
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
require "json"
|
|
2
2
|
|
|
3
3
|
package = JSON.parse(File.read(File.join(__dir__, "package.json")))
|
|
4
|
+
folly_compiler_flags = '-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1 -Wno-comma -Wno-shorten-64-to-32'
|
|
4
5
|
|
|
5
6
|
Pod::Spec.new do |s|
|
|
6
7
|
s.name = "react-native-applovin-max"
|
|
@@ -10,11 +11,34 @@ Pod::Spec.new do |s|
|
|
|
10
11
|
s.license = package["license"]
|
|
11
12
|
s.authors = package["author"]
|
|
12
13
|
|
|
13
|
-
s.platforms = { :ios =>
|
|
14
|
-
s.source = { :git => "https://github.com/AppLovin/AppLovin-MAX-React-Native.git", :tag => "
|
|
15
|
-
|
|
16
|
-
s.source_files = "ios/AppLovinMAX*.{h,m}"
|
|
14
|
+
s.platforms = { :ios => min_ios_version_supported }
|
|
15
|
+
s.source = { :git => "https://github.com/AppLovin/AppLovin-MAX-React-Native.git", :tag => "release_7_0_0" }
|
|
17
16
|
|
|
18
|
-
s.
|
|
19
|
-
|
|
17
|
+
s.source_files = "ios/AppLovinMAX*.{h,m}"
|
|
18
|
+
|
|
19
|
+
s.dependency "AppLovinSDK", "12.5.0"
|
|
20
|
+
|
|
21
|
+
# Use install_modules_dependencies helper to install the dependencies if React Native version >=0.71.0.
|
|
22
|
+
# See https://github.com/facebook/react-native/blob/febf6b7f33fdb4904669f99d795eba4c0f95d7bf/scripts/cocoapods/new_architecture.rb#L79.
|
|
23
|
+
if respond_to?(:install_modules_dependencies, true)
|
|
24
|
+
install_modules_dependencies(s)
|
|
25
|
+
else
|
|
26
|
+
s.dependency "React-Core"
|
|
27
|
+
|
|
28
|
+
# Don't install the dependencies when we run `pod install` in the old architecture.
|
|
29
|
+
if ENV['RCT_NEW_ARCH_ENABLED'] == '1' then
|
|
30
|
+
s.compiler_flags = folly_compiler_flags + " -DRCT_NEW_ARCH_ENABLED=1"
|
|
31
|
+
s.pod_target_xcconfig = {
|
|
32
|
+
"HEADER_SEARCH_PATHS" => "\"$(PODS_ROOT)/boost\"",
|
|
33
|
+
"OTHER_CPLUSPLUSFLAGS" => "-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1",
|
|
34
|
+
"CLANG_CXX_LANGUAGE_STANDARD" => "c++17"
|
|
35
|
+
}
|
|
36
|
+
s.dependency "React-RCTFabric"
|
|
37
|
+
s.dependency "React-Codegen"
|
|
38
|
+
s.dependency "RCT-Folly"
|
|
39
|
+
s.dependency "RCTRequired"
|
|
40
|
+
s.dependency "RCTTypeSafety"
|
|
41
|
+
s.dependency "ReactCommon/turbomodule/core"
|
|
42
|
+
end
|
|
43
|
+
end
|
|
20
44
|
end
|
package/src/AdView.tsx
CHANGED
|
@@ -1,17 +1,11 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { useEffect, useState, useRef, useCallback, useImperativeHandle, useReducer, forwardRef } from 'react';
|
|
3
|
-
import {
|
|
4
|
-
NativeModules,
|
|
5
|
-
requireNativeComponent,
|
|
6
|
-
StyleSheet,
|
|
7
|
-
UIManager,
|
|
8
|
-
findNodeHandle,
|
|
9
|
-
useWindowDimensions,
|
|
10
|
-
} from 'react-native';
|
|
3
|
+
import { NativeModules, requireNativeComponent, StyleSheet, UIManager, findNodeHandle, useWindowDimensions } from 'react-native';
|
|
11
4
|
import type { ViewProps, ViewStyle, StyleProp, NativeMethods, DimensionValue } from 'react-native';
|
|
12
5
|
import type { AdDisplayFailedInfo, AdInfo, AdLoadFailedInfo, AdRevenueInfo } from './types/AdInfo';
|
|
13
6
|
import type { AdNativeEvent } from './types/AdEvent';
|
|
14
|
-
import type { AdViewProps, AdViewHandler } from './types/AdViewProps';
|
|
7
|
+
import type { AdViewProps, AdViewHandler, NativeUIComponentAdViewOptions } from './types/AdViewProps';
|
|
8
|
+
import { addEventListener, removeEventListener } from './EventEmitter';
|
|
15
9
|
|
|
16
10
|
const { AppLovinMAX } = NativeModules;
|
|
17
11
|
|
|
@@ -28,6 +22,9 @@ const {
|
|
|
28
22
|
BOTTOM_LEFT_POSITION,
|
|
29
23
|
BOTTOM_CENTER_POSITION,
|
|
30
24
|
BOTTOM_RIGHT_POSITION,
|
|
25
|
+
|
|
26
|
+
ON_NATIVE_UI_COMPONENT_ADVIEW_AD_LOADED_EVENT,
|
|
27
|
+
ON_NATIVE_UI_COMPONENT_ADVIEW_AD_LOAD_FAILED_EVENT,
|
|
31
28
|
} = AppLovinMAX.getConstants();
|
|
32
29
|
|
|
33
30
|
/**
|
|
@@ -89,12 +86,7 @@ const getOutlineViewSize = (style: StyleProp<ViewStyle>) => {
|
|
|
89
86
|
return [viewStyle?.width ?? 'auto', viewStyle?.height ?? 'auto'];
|
|
90
87
|
};
|
|
91
88
|
|
|
92
|
-
const sizeBannerDimensions = (
|
|
93
|
-
sizeProps: SizeRecord,
|
|
94
|
-
adaptiveBannerEnabled: boolean,
|
|
95
|
-
screenWidth: number,
|
|
96
|
-
bannerFormatSize: SizeRecord
|
|
97
|
-
): Promise<SizeRecord> => {
|
|
89
|
+
const sizeBannerDimensions = (sizeProps: SizeRecord, adaptiveBannerEnabled: boolean, screenWidth: number, bannerFormatSize: SizeRecord): Promise<SizeRecord> => {
|
|
98
90
|
const sizeForBannerFormat = async () => {
|
|
99
91
|
const width = sizeProps.width === 'auto' ? screenWidth : sizeProps.width;
|
|
100
92
|
|
|
@@ -207,7 +199,7 @@ export const AdView = forwardRef<AdViewHandler, AdViewProps & ViewProps>(functio
|
|
|
207
199
|
console.warn('AdView is mounted before the initialization of the AppLovin MAX React Native module');
|
|
208
200
|
}
|
|
209
201
|
});
|
|
210
|
-
}, []); // Run once when mounted
|
|
202
|
+
}, [adFormat]); // Run once when mounted
|
|
211
203
|
|
|
212
204
|
useEffect(() => {
|
|
213
205
|
if (!isInitialized) return;
|
|
@@ -219,17 +211,12 @@ export const AdView = forwardRef<AdViewHandler, AdViewProps & ViewProps>(functio
|
|
|
219
211
|
sizeProps.current = { width: width, height: height };
|
|
220
212
|
|
|
221
213
|
if (adFormat === AdFormat.BANNER) {
|
|
222
|
-
sizeBannerDimensions(sizeProps.current, adaptiveBannerEnabled, screenWidth, adFormatSize.current).then(
|
|
223
|
-
(adaptedSize
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
dimensions.current.height !== adaptedSize.height
|
|
227
|
-
) {
|
|
228
|
-
dimensions.current = adaptedSize;
|
|
229
|
-
forceUpdate();
|
|
230
|
-
}
|
|
214
|
+
sizeBannerDimensions(sizeProps.current, adaptiveBannerEnabled, screenWidth, adFormatSize.current).then((adaptedSize: SizeRecord) => {
|
|
215
|
+
if (dimensions.current.width !== adaptedSize.width || dimensions.current.height !== adaptedSize.height) {
|
|
216
|
+
dimensions.current = adaptedSize;
|
|
217
|
+
forceUpdate();
|
|
231
218
|
}
|
|
232
|
-
);
|
|
219
|
+
});
|
|
233
220
|
} else {
|
|
234
221
|
dimensions.current = {
|
|
235
222
|
width: width === 'auto' ? adFormatSize.current.width : width,
|
|
@@ -303,3 +290,73 @@ export const AdView = forwardRef<AdViewHandler, AdViewProps & ViewProps>(functio
|
|
|
303
290
|
/>
|
|
304
291
|
);
|
|
305
292
|
});
|
|
293
|
+
|
|
294
|
+
/**
|
|
295
|
+
* Preloads a native UI component for {@link AdView}. When you mount {@link AdView} with the Ad Unit
|
|
296
|
+
* ID you preloaded, it will be constructed with the preloaded native UI component, allowing the ads
|
|
297
|
+
* to be displayed quickly. When you unmount {@link AdView}, the preloaded native UI component won't
|
|
298
|
+
* be destroyed. Instead, it will be reused for the next mount. You must manually destroy it when it
|
|
299
|
+
* is no longer needed.
|
|
300
|
+
*
|
|
301
|
+
* You can preload only one native UI component for a single Ad Unit ID. If you mount two of
|
|
302
|
+
* {@link AdView} with the same Ad Unit ID, the first {@link AdView} will be constructed with the
|
|
303
|
+
* preloaded native UI component, but the second {@link AdView} will create its own native UI
|
|
304
|
+
* component and destroy it when unmounting.
|
|
305
|
+
*
|
|
306
|
+
* @param adUnitId The Ad Unit ID to load ads for.
|
|
307
|
+
* @param adFormat An enum value representing the ad format to load ads for. Should be either
|
|
308
|
+
* {@link AdFormat.BANNER} or {@link AdFormat.MREC}.
|
|
309
|
+
* @param options Optional props used to construct a native UI component.
|
|
310
|
+
* @returns A promise that resolves when preload starts. The resolved object contains void.
|
|
311
|
+
* @throws Throws an error if the request fails.
|
|
312
|
+
*/
|
|
313
|
+
export const preloadNativeUIComponentAdView = async (adUnitId: string, adFormat: AdFormat, options?: NativeUIComponentAdViewOptions): Promise<void> => {
|
|
314
|
+
return AppLovinMAX.preloadNativeUIComponentAdView(adUnitId, adFormat, options?.placement, options?.customData, options?.extraParameters, options?.localExtraParameters);
|
|
315
|
+
};
|
|
316
|
+
|
|
317
|
+
/**
|
|
318
|
+
* Destroys the native UI component.
|
|
319
|
+
*
|
|
320
|
+
* @param adUnitId The ad unit ID of the native UI component to destroy.
|
|
321
|
+
* @returns A promise that resolves upon the destruction of the native UI component. The resolved
|
|
322
|
+
* object contains void.
|
|
323
|
+
* @throws Throws an error if the request fails.
|
|
324
|
+
*/
|
|
325
|
+
export const destroyNativeUIComponentAdView = async (adUnitId: string): Promise<void> => {
|
|
326
|
+
return AppLovinMAX.destroyNativeUIComponentAdView(adUnitId);
|
|
327
|
+
};
|
|
328
|
+
|
|
329
|
+
/**
|
|
330
|
+
* Adds the specified event listener to receive {@link AdInfo} when a native UI component loads a
|
|
331
|
+
* new ad.
|
|
332
|
+
*
|
|
333
|
+
* @param listener Listener to be notified.
|
|
334
|
+
*/
|
|
335
|
+
export const addNativeUIComponentAdViewAdLoadedEventListener = (listener: (adInfo: AdInfo) => void) => {
|
|
336
|
+
addEventListener(ON_NATIVE_UI_COMPONENT_ADVIEW_AD_LOADED_EVENT, (adInfo: AdInfo) => listener(adInfo));
|
|
337
|
+
};
|
|
338
|
+
|
|
339
|
+
/**
|
|
340
|
+
* Removes the event listener to receive {@link AdInfo} when a native UI component loads a new ad.
|
|
341
|
+
*/
|
|
342
|
+
export const removeNativeUIComponentAdViewAdLoadedEventListener = () => {
|
|
343
|
+
removeEventListener(ON_NATIVE_UI_COMPONENT_ADVIEW_AD_LOADED_EVENT);
|
|
344
|
+
};
|
|
345
|
+
|
|
346
|
+
/**
|
|
347
|
+
* Adds the specified event listener to receive {@link AdLoadFailedInfo} when a native UI component
|
|
348
|
+
* could not load a new ad.
|
|
349
|
+
*
|
|
350
|
+
* @param listener Listener to be notified.
|
|
351
|
+
*/
|
|
352
|
+
export const addNativeUIComponentAdViewAdLoadFailedEventListener = (listener: (errorInfo: AdLoadFailedInfo) => void) => {
|
|
353
|
+
addEventListener(ON_NATIVE_UI_COMPONENT_ADVIEW_AD_LOAD_FAILED_EVENT, (errorInfo: AdLoadFailedInfo) => listener(errorInfo));
|
|
354
|
+
};
|
|
355
|
+
|
|
356
|
+
/**
|
|
357
|
+
* Removes the event listener to receive {@link AdLoadFailedInfo} when a native UI component could
|
|
358
|
+
* not load a new ad.
|
|
359
|
+
*/
|
|
360
|
+
export const removeNativeUIComponentAdViewAdLoadFailedEventListener = () => {
|
|
361
|
+
removeEventListener(ON_NATIVE_UI_COMPONENT_ADVIEW_AD_LOAD_FAILED_EVENT);
|
|
362
|
+
};
|
package/src/AppLovinMAX.ts
CHANGED
|
@@ -4,7 +4,7 @@ import type { Configuration } from './types/Configuration';
|
|
|
4
4
|
|
|
5
5
|
const NativeAppLovinMAX = NativeModules.AppLovinMAX;
|
|
6
6
|
|
|
7
|
-
const VERSION = '
|
|
7
|
+
const VERSION = '7.0.0';
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
10
|
* This enum represents the user's geography used to determine the type of consent flow shown to the
|
package/src/InterstitialAd.ts
CHANGED
|
@@ -69,9 +69,7 @@ const removeAdDisplayedEventListener = () => {
|
|
|
69
69
|
};
|
|
70
70
|
|
|
71
71
|
const addAdFailedToDisplayEventListener = (listener: (errorInfo: AdDisplayFailedInfo) => void) => {
|
|
72
|
-
addEventListener(ON_INTERSTITIAL_AD_FAILED_TO_DISPLAY_EVENT, (errorInfo: AdDisplayFailedInfo) =>
|
|
73
|
-
listener(errorInfo)
|
|
74
|
-
);
|
|
72
|
+
addEventListener(ON_INTERSTITIAL_AD_FAILED_TO_DISPLAY_EVENT, (errorInfo: AdDisplayFailedInfo) => listener(errorInfo));
|
|
75
73
|
};
|
|
76
74
|
|
|
77
75
|
const removeAdFailedToDisplayEventListener = () => {
|
package/src/MRecAd.ts
CHANGED
|
@@ -7,14 +7,8 @@ import type { AdViewPosition } from './AdView';
|
|
|
7
7
|
|
|
8
8
|
const { AppLovinMAX } = NativeModules;
|
|
9
9
|
|
|
10
|
-
const {
|
|
11
|
-
|
|
12
|
-
ON_MREC_AD_LOAD_FAILED_EVENT,
|
|
13
|
-
ON_MREC_AD_CLICKED_EVENT,
|
|
14
|
-
ON_MREC_AD_COLLAPSED_EVENT,
|
|
15
|
-
ON_MREC_AD_EXPANDED_EVENT,
|
|
16
|
-
ON_MREC_AD_REVENUE_PAID,
|
|
17
|
-
} = AppLovinMAX.getConstants();
|
|
10
|
+
const { ON_MREC_AD_LOADED_EVENT, ON_MREC_AD_LOAD_FAILED_EVENT, ON_MREC_AD_CLICKED_EVENT, ON_MREC_AD_COLLAPSED_EVENT, ON_MREC_AD_EXPANDED_EVENT, ON_MREC_AD_REVENUE_PAID } =
|
|
11
|
+
AppLovinMAX.getConstants();
|
|
18
12
|
|
|
19
13
|
const createAd = (adUnitId: string, position: AdViewPosition): void => {
|
|
20
14
|
AppLovinMAX.createMRec(adUnitId, position);
|
package/src/TargetingData.ts
CHANGED
|
@@ -71,12 +71,7 @@ export const TargetingData: TargetingDataType = {
|
|
|
71
71
|
* Sets the gender of the user. Set this to {@link UserGender.Unknown} to clear this value.
|
|
72
72
|
*/
|
|
73
73
|
set gender(value: UserGender | Promise<UserGender>) {
|
|
74
|
-
if (
|
|
75
|
-
value === UserGender.UNKNOWN ||
|
|
76
|
-
value === UserGender.FEMALE ||
|
|
77
|
-
value === UserGender.MALE ||
|
|
78
|
-
value === UserGender.OTHER
|
|
79
|
-
) {
|
|
74
|
+
if (value === UserGender.UNKNOWN || value === UserGender.FEMALE || value === UserGender.MALE || value === UserGender.OTHER) {
|
|
80
75
|
nativeMethods.setTargetingDataGender(value);
|
|
81
76
|
} else {
|
|
82
77
|
printError('TargetingData.gender', 'UserGender', typeof value);
|
|
@@ -213,13 +208,5 @@ const isStringArray = (strs: object): boolean => {
|
|
|
213
208
|
};
|
|
214
209
|
|
|
215
210
|
const printError = (fieldName: string, correctType: string, wrongType: string) => {
|
|
216
|
-
console.error(
|
|
217
|
-
'Cannot set value to ' +
|
|
218
|
-
fieldName +
|
|
219
|
-
' with unsupported type: ' +
|
|
220
|
-
wrongType +
|
|
221
|
-
'. Value has to be of type ' +
|
|
222
|
-
correctType +
|
|
223
|
-
'.'
|
|
224
|
-
);
|
|
211
|
+
console.error('Cannot set value to ' + fieldName + ' with unsupported type: ' + wrongType + '. Value has to be of type ' + correctType + '.');
|
|
225
212
|
};
|
package/src/index.ts
CHANGED
|
@@ -7,15 +7,14 @@ export { AppOpenAd } from './AppOpenAd';
|
|
|
7
7
|
export { BannerAd } from './BannerAd';
|
|
8
8
|
export { MRecAd } from './MRecAd';
|
|
9
9
|
export { AdView, AdFormat, AdViewPosition } from './AdView';
|
|
10
|
-
export { NativeAdView } from './nativeAd/NativeAdView';
|
|
11
10
|
export {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
} from './nativeAd/NativeAdViewComponents';
|
|
11
|
+
preloadNativeUIComponentAdView,
|
|
12
|
+
destroyNativeUIComponentAdView,
|
|
13
|
+
addNativeUIComponentAdViewAdLoadFailedEventListener,
|
|
14
|
+
removeNativeUIComponentAdViewAdLoadedEventListener,
|
|
15
|
+
addNativeUIComponentAdViewAdLoadedEventListener,
|
|
16
|
+
removeNativeUIComponentAdViewAdLoadFailedEventListener,
|
|
17
|
+
} from './AdView';
|
|
18
|
+
export { NativeAdView } from './nativeAd/NativeAdView';
|
|
19
|
+
export { TitleView, AdvertiserView, BodyView, CallToActionView, IconView, OptionsView, MediaView, StarRatingView } from './nativeAd/NativeAdViewComponents';
|
|
21
20
|
export * from './types';
|
|
@@ -18,9 +18,7 @@ type NativeAdViewNativeEvents = {
|
|
|
18
18
|
onAdRevenuePaidEvent(event: AdNativeEvent<AdRevenueInfo>): void;
|
|
19
19
|
};
|
|
20
20
|
|
|
21
|
-
const NativeAdViewComponent = requireNativeComponent<NativeAdViewProps & ViewProps & NativeAdViewNativeEvents>(
|
|
22
|
-
'AppLovinMAXNativeAdView'
|
|
23
|
-
);
|
|
21
|
+
const NativeAdViewComponent = requireNativeComponent<NativeAdViewProps & ViewProps & NativeAdViewNativeEvents>('AppLovinMAXNativeAdView');
|
|
24
22
|
|
|
25
23
|
/**
|
|
26
24
|
* The {@link NativeAdView} component that you use building a native ad. This loads a native ad and
|
|
@@ -59,50 +57,33 @@ const NativeAdViewComponent = requireNativeComponent<NativeAdViewProps & ViewPro
|
|
|
59
57
|
* </NativeAdView>
|
|
60
58
|
* ```
|
|
61
59
|
*/
|
|
62
|
-
export const NativeAdView = forwardRef<NativeAdViewHandler, NativeAdViewProps & ViewProps>(
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
}
|
|
75
|
-
});
|
|
76
|
-
}, []);
|
|
77
|
-
|
|
78
|
-
// Not ready to render NativeAdView
|
|
79
|
-
if (!isInitialized) {
|
|
80
|
-
return null;
|
|
81
|
-
}
|
|
60
|
+
export const NativeAdView = forwardRef<NativeAdViewHandler, NativeAdViewProps & ViewProps>(function NativeAdView(props, ref) {
|
|
61
|
+
const [isInitialized, setIsInitialized] = useState<boolean>(false);
|
|
62
|
+
|
|
63
|
+
useEffect(() => {
|
|
64
|
+
// check that AppLovinMAX has been initialized
|
|
65
|
+
AppLovinMAX.isInitialized().then((result: boolean) => {
|
|
66
|
+
setIsInitialized(result);
|
|
67
|
+
if (!result) {
|
|
68
|
+
console.warn('NativeAdView is mounted before the initialization of the AppLovin MAX React Native module');
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
}, []);
|
|
82
72
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
</NativeAdViewProvider>
|
|
87
|
-
);
|
|
73
|
+
// Not ready to render NativeAdView
|
|
74
|
+
if (!isInitialized) {
|
|
75
|
+
return null;
|
|
88
76
|
}
|
|
89
|
-
|
|
77
|
+
|
|
78
|
+
return (
|
|
79
|
+
<NativeAdViewProvider>
|
|
80
|
+
<NativeAdViewImpl {...props} ref={ref} />
|
|
81
|
+
</NativeAdViewProvider>
|
|
82
|
+
);
|
|
83
|
+
});
|
|
90
84
|
|
|
91
85
|
const NativeAdViewImpl = forwardRef<NativeAdViewHandler, NativeAdViewProps & ViewProps>(function NativeAdViewImpl(
|
|
92
|
-
{
|
|
93
|
-
adUnitId,
|
|
94
|
-
placement,
|
|
95
|
-
customData,
|
|
96
|
-
extraParameters,
|
|
97
|
-
localExtraParameters,
|
|
98
|
-
onAdLoaded,
|
|
99
|
-
onAdLoadFailed,
|
|
100
|
-
onAdClicked,
|
|
101
|
-
onAdRevenuePaid,
|
|
102
|
-
children,
|
|
103
|
-
style,
|
|
104
|
-
...otherProps
|
|
105
|
-
},
|
|
86
|
+
{ adUnitId, placement, customData, extraParameters, localExtraParameters, onAdLoaded, onAdLoadFailed, onAdClicked, onAdRevenuePaid, children, style, ...otherProps },
|
|
106
87
|
ref
|
|
107
88
|
) {
|
|
108
89
|
// context from NativeAdViewProvider
|
|
@@ -127,12 +108,15 @@ const NativeAdViewImpl = forwardRef<NativeAdViewHandler, NativeAdViewProps & Vie
|
|
|
127
108
|
useImperativeHandle(ref, () => ({ loadAd }), []);
|
|
128
109
|
|
|
129
110
|
// save the DOM element via the ref callback
|
|
130
|
-
const saveElement = useCallback(
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
111
|
+
const saveElement = useCallback(
|
|
112
|
+
(element: NativeAdViewType | null) => {
|
|
113
|
+
if (element) {
|
|
114
|
+
nativeAdViewRef.current = element;
|
|
115
|
+
setNativeAdView(element);
|
|
116
|
+
}
|
|
117
|
+
},
|
|
118
|
+
[setNativeAdView]
|
|
119
|
+
);
|
|
136
120
|
|
|
137
121
|
const onAdLoadedEvent = (event: { nativeEvent: { nativeAd: NativeAd; adInfo: AdInfo } }) => {
|
|
138
122
|
setNativeAd(event.nativeEvent.nativeAd);
|
|
@@ -15,7 +15,7 @@ export const TitleView = (props: TextProps) => {
|
|
|
15
15
|
nativeAdView?.setNativeProps({
|
|
16
16
|
titleView: findNodeHandle(titleRef.current),
|
|
17
17
|
});
|
|
18
|
-
}, [nativeAd]);
|
|
18
|
+
}, [nativeAd, nativeAdView]);
|
|
19
19
|
|
|
20
20
|
return (
|
|
21
21
|
<Text {...props} ref={titleRef}>
|
|
@@ -34,7 +34,7 @@ export const AdvertiserView = (props: TextProps) => {
|
|
|
34
34
|
nativeAdView?.setNativeProps({
|
|
35
35
|
advertiserView: findNodeHandle(advertiserRef.current),
|
|
36
36
|
});
|
|
37
|
-
}, [nativeAd]);
|
|
37
|
+
}, [nativeAd, nativeAdView]);
|
|
38
38
|
|
|
39
39
|
return (
|
|
40
40
|
<Text {...props} ref={advertiserRef}>
|
|
@@ -53,7 +53,7 @@ export const BodyView = (props: TextProps) => {
|
|
|
53
53
|
nativeAdView?.setNativeProps({
|
|
54
54
|
bodyView: findNodeHandle(bodyRef.current),
|
|
55
55
|
});
|
|
56
|
-
}, [nativeAd]);
|
|
56
|
+
}, [nativeAd, nativeAdView]);
|
|
57
57
|
|
|
58
58
|
return (
|
|
59
59
|
<Text {...props} ref={bodyRef}>
|
|
@@ -72,7 +72,7 @@ export const CallToActionView = (props: TextProps) => {
|
|
|
72
72
|
nativeAdView?.setNativeProps({
|
|
73
73
|
callToActionView: findNodeHandle(callToActionRef.current),
|
|
74
74
|
});
|
|
75
|
-
}, [nativeAd]);
|
|
75
|
+
}, [nativeAd, nativeAdView]);
|
|
76
76
|
|
|
77
77
|
return (
|
|
78
78
|
<TouchableOpacity>
|
|
@@ -93,7 +93,7 @@ export const IconView = (props: Omit<ImageProps, 'source'>) => {
|
|
|
93
93
|
nativeAdView?.setNativeProps({
|
|
94
94
|
iconView: findNodeHandle(imageRef.current),
|
|
95
95
|
});
|
|
96
|
-
}, [nativeAd]);
|
|
96
|
+
}, [nativeAd, nativeAdView]);
|
|
97
97
|
|
|
98
98
|
return nativeAd.url ? (
|
|
99
99
|
<Image {...props} ref={imageRef} source={{ uri: nativeAd.url }} />
|
|
@@ -113,7 +113,7 @@ export const OptionsView = (props: ViewProps) => {
|
|
|
113
113
|
nativeAdView?.setNativeProps({
|
|
114
114
|
optionsView: findNodeHandle(viewRef.current),
|
|
115
115
|
});
|
|
116
|
-
}, [nativeAd]);
|
|
116
|
+
}, [nativeAd, nativeAdView]);
|
|
117
117
|
|
|
118
118
|
return <View {...props} ref={viewRef} />;
|
|
119
119
|
};
|
|
@@ -128,7 +128,7 @@ export const MediaView = (props: ViewProps) => {
|
|
|
128
128
|
nativeAdView?.setNativeProps({
|
|
129
129
|
mediaView: findNodeHandle(viewRef.current),
|
|
130
130
|
});
|
|
131
|
-
}, [nativeAd]);
|
|
131
|
+
}, [nativeAd, nativeAdView]);
|
|
132
132
|
|
|
133
133
|
return <View {...props} ref={viewRef} />;
|
|
134
134
|
};
|
|
@@ -142,22 +142,8 @@ export const StarRatingView = (props: ViewProps) => {
|
|
|
142
142
|
|
|
143
143
|
const { nativeAd } = useContext(NativeAdViewContext);
|
|
144
144
|
|
|
145
|
-
const FilledStar = () => {
|
|
146
|
-
return (
|
|
147
|
-
// black star in unicode
|
|
148
|
-
<Text style={{ fontSize: starSize, color: starColor }}>{String.fromCodePoint(0x2605)}</Text>
|
|
149
|
-
);
|
|
150
|
-
};
|
|
151
|
-
|
|
152
|
-
const EmptyStar = () => {
|
|
153
|
-
return (
|
|
154
|
-
// white star in unicode
|
|
155
|
-
<Text style={{ fontSize: starSize, color: starColor }}>{String.fromCodePoint(0x2606)}</Text>
|
|
156
|
-
);
|
|
157
|
-
};
|
|
158
|
-
|
|
159
145
|
return (
|
|
160
|
-
<View {...restProps} style={[style,
|
|
146
|
+
<View {...restProps} style={[style, styles.starRatingContainer]}>
|
|
161
147
|
{(() => {
|
|
162
148
|
const stars: ReactNode[] = [];
|
|
163
149
|
for (let index = 0; index < maxStarCount; index++) {
|
|
@@ -165,16 +151,10 @@ export const StarRatingView = (props: ViewProps) => {
|
|
|
165
151
|
const width = (nativeAd.starRating - index) * starSize;
|
|
166
152
|
stars.push(
|
|
167
153
|
<View key={index}>
|
|
168
|
-
<
|
|
154
|
+
<Text style={{ fontSize: starSize, color: starColor }}>{String.fromCodePoint(0x2606)}</Text>
|
|
169
155
|
{nativeAd.starRating > index && (
|
|
170
|
-
<View
|
|
171
|
-
style={{
|
|
172
|
-
width: width,
|
|
173
|
-
overflow: 'hidden',
|
|
174
|
-
position: 'absolute',
|
|
175
|
-
}}
|
|
176
|
-
>
|
|
177
|
-
<FilledStar />
|
|
156
|
+
<View style={[{ width: width }, styles.starRating]}>
|
|
157
|
+
<Text style={{ fontSize: starSize, color: starColor }}>{String.fromCodePoint(0x2605)}</Text>
|
|
178
158
|
</View>
|
|
179
159
|
)}
|
|
180
160
|
</View>
|
|
@@ -192,3 +172,14 @@ export const StarRatingView = (props: ViewProps) => {
|
|
|
192
172
|
</View>
|
|
193
173
|
);
|
|
194
174
|
};
|
|
175
|
+
|
|
176
|
+
const styles = StyleSheet.create({
|
|
177
|
+
starRatingContainer: {
|
|
178
|
+
flexDirection: 'row',
|
|
179
|
+
alignItems: 'center',
|
|
180
|
+
},
|
|
181
|
+
starRating: {
|
|
182
|
+
overflow: 'hidden',
|
|
183
|
+
position: 'absolute',
|
|
184
|
+
},
|
|
185
|
+
});
|