Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

3.1.11: improvements to configure and dependency updates #257

Merged
merged 7 commits into from
Sep 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"

implementation 'com.github.jeziellago:compose-markdown:0.3.0'
compileOnly "com.namiml:sdk-amazon:3.1.10"
compileOnly "com.namiml:sdk-amazon:3.1.13"

implementation 'com.facebook.react:react-native:+' // From node_modules
coreLibraryDesugaring "com.android.tools:desugar_jdk_libs:1.1.5"
Expand Down
33 changes: 14 additions & 19 deletions android/src/main/java/com/nami/reactlibrary/NamiBridgeModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import com.facebook.react.bridge.ReactContextBaseJavaModule
import com.facebook.react.bridge.ReactMethod
import com.facebook.react.bridge.ReadableArray
import com.facebook.react.bridge.ReadableMap
import com.facebook.react.bridge.Promise
import com.namiml.Nami
import com.namiml.NamiConfiguration
import com.namiml.NamiLanguageCode
Expand Down Expand Up @@ -44,15 +45,7 @@ class NamiBridgeModule(reactContext: ReactApplicationContext) :
}

val appContext: Context = reactApplicationContext.applicationContext
Log.i(LOG_TAG, "Configure called with appID $appPlatformID")
Log.i(LOG_TAG, "Configure called with context $reactApplicationContext")
Log.i(LOG_TAG, "Nami Configure called with context.applicationContext $appContext")

val isApplication: Boolean = (appContext is Application)
Log.i(LOG_TAG, "Configure called with (context as Application) $isApplication.")
Log.i(LOG_TAG, "End Application check ")

// Application fred = (reactContext as Application);
Log.d(LOG_TAG, "NAMI: RN Bridge - Configure called with appPlatformID $appPlatformID")

val builder: NamiConfiguration.Builder =
NamiConfiguration.Builder(appContext, appPlatformID)
Expand All @@ -78,15 +71,15 @@ class NamiBridgeModule(reactContext: ReactApplicationContext) :
builder.logLevel(NamiLogLevel.DEBUG)
}
}
Log.i(LOG_TAG, "Nami Configuration log level passed in is $logLevelString")
Log.d(LOG_TAG, "NAMI: RN Bridge - configuration log level is $logLevelString")

val developmentMode = if (configDict.hasKey(CONFIG_MAP_DEVELOPMENT_MODE_KEY)) {
configDict.getBoolean(CONFIG_MAP_DEVELOPMENT_MODE_KEY)
} else {
false
}
Log.i(LOG_TAG, "Nami Configuration developmentMode is $developmentMode")
if (developmentMode) {
Log.d(LOG_TAG, "NAMI: RN Bridge - development mode is $developmentMode")
builder.developmentMode = true
}

Expand Down Expand Up @@ -115,11 +108,11 @@ class NamiBridgeModule(reactContext: ReactApplicationContext) :
} else {
Arguments.createArray()
}
val settingsList = mutableListOf("extendedClientInfo:react-native:3.1.10")
val settingsList = mutableListOf("extendedClientInfo:react-native:3.1.11")
namiCommandsReact?.toArrayList()?.filterIsInstance<String>()?.let { commandsFromReact ->
settingsList.addAll(commandsFromReact)
}
Log.i(LOG_TAG, "Nami Configuration command settings are $settingsList")
Log.d(LOG_TAG, "Nami Configuration command settings are $settingsList")
builder.settingsList = settingsList

val initialConfig = if (configDict.hasKey(CONFIG_MAP_INITIAL_CONFIG_KEY)) {
Expand All @@ -128,22 +121,24 @@ class NamiBridgeModule(reactContext: ReactApplicationContext) :
null
}
initialConfig?.let { initialConfigString ->
Log.i(
Log.d(
LOG_TAG,
"Nami Configuration initialConfig found.",
)
builder.initialConfig = initialConfigString
}

val builtConfig: NamiConfiguration = builder.build()
Log.i(LOG_TAG, "Nami Configuration object is $builtConfig")
Log.d(LOG_TAG, "Nami Configuration object is $builtConfig")

reactApplicationContext.runOnUiQueueThread {

// Configure must be called on main thread
Nami.configure(builtConfig)
val resultMap = Arguments.createMap()
resultMap.putBoolean("success", true)
completion.invoke(resultMap)
Nami.configure(builtConfig) { result ->
val resultMap = Arguments.createMap()
resultMap.putBoolean("success", result)
completion.invoke(resultMap)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public List<NativeModule> createNativeModules(@NotNull ReactApplicationContext r
moduleList.add(new NamiPurchaseManagerBridgeModule(reactContext));
moduleList.add(new NamiEntitlementManagerBridgeModule(reactContext));
moduleList.add(new NamiMLManagerBridgeModule(reactContext));
moduleList.add(new NamiManagerBridgeModule(reactContext));
moduleList.add(new NamiCustomerManagerBridgeModule(reactContext));
moduleList.add(new NamiCampaignManagerBridgeModule(reactContext));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,6 @@ class NamiCampaignManagerBridgeModule(reactContext: ReactApplicationContext) :
putString(EXTERNAL_SEGMENT_ID, paywallEvent.externalSegmentId ?: "")
putString(DEEP_LINK_URL, paywallEvent.deeplinkUrl ?: "")
}

emitEvent(_RESULT_CAMPAIGN, resultMap)
}

Expand Down
28 changes: 28 additions & 0 deletions android/src/main/java/com/nami/reactlibrary/NamiManagerBridge.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.nami.reactlibrary

import android.util.Log
import com.facebook.react.bridge.*
import com.facebook.react.modules.core.DeviceEventManagerModule
import com.namiml.Nami

class NamiManagerBridgeModule(reactContext: ReactApplicationContext) :
ReactContextBaseJavaModule(reactContext) {

override fun getName(): String {
return "RNNamiManager"
}

@ReactMethod
fun sdkConfigured(promise: Promise) {
val sdkConfigured = Nami.isInitialized()
promise.resolve(sdkConfigured)
}

@ReactMethod
fun addListener(eventName: String?) {
}

@ReactMethod
fun removeListeners(count: Int?) {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,12 @@ class NamiPaywallManagerBridgeModule(reactContext: ReactApplicationContext) :
promise.resolve(false)
}

@ReactMethod
fun isPaywallOpen(promise: Promise) {
val paywallOpen = NamiPaywallManager.isPaywallOpen()
promise.resolve(paywallOpen)
}

@ReactMethod
fun buySkuCancel() {
NamiPaywallManager.buySkuCancel()
Expand Down
3 changes: 1 addition & 2 deletions examples/Basic/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Linking, Platform } from 'react-native';
import { NavigationContainer } from '@react-navigation/native';
import { NativeStackNavigationProp } from '@react-navigation/native-stack';
import { createBottomTabNavigator } from '@react-navigation/bottom-tabs';
import { NamiCustomerManager, NamiPaywallManager } from 'react-native-nami-sdk';
import { NamiPaywallManager } from 'react-native-nami-sdk';

import CampaignScreen from './containers/CampaignScreen';
import ProfileScreen from './containers/ProfileScreen';
Expand Down Expand Up @@ -93,7 +93,6 @@ const App = () => {
},
);

NamiCustomerManager.setCustomerDataPlatformId('2135');
return () => {
subscriptionRemover();
};
Expand Down
10 changes: 8 additions & 2 deletions examples/Basic/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,10 @@ android {
targetCompatibility JavaVersion.VERSION_1_8
}

lintOptions {
checkReleaseBuilds false
}

defaultConfig {
applicationId "com.namiml.stg.testreactnative"
minSdkVersion 26
Expand Down Expand Up @@ -177,6 +181,7 @@ android {
storePassword 'android'
keyAlias 'androidreleasekey'
keyPassword 'android'
v2SigningEnabled true
}
}
buildTypes {
Expand All @@ -187,7 +192,8 @@ android {
// Caution! In production, you need to generate your own keystore file.
// see https://facebook.github.io/react-native/docs/signed-apk-android.
signingConfig null
minifyEnabled enableProguardInReleaseBuilds
minifyEnabled true
shrinkResources = true
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
proguardFile "${rootProject.projectDir}/../node_modules/detox/android/detox/proguard-rules-app.pro"
}
Expand Down Expand Up @@ -218,7 +224,7 @@ dependencies {
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation "com.facebook.react:react-native:+" // From node_modules
implementation 'com.github.jeziellago:compose-markdown:0.3.0'
implementation "com.namiml:sdk-android:3.1.10"
implementation "com.namiml:sdk-android:3.1.13"

implementation project(':react-native-screens')

Expand Down
2 changes: 1 addition & 1 deletion examples/Basic/config/getInitialConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const getInitialConfig = () => {
);
case 'ios':
return JSON.stringify(
flavor !== 'production'
flavor === 'production'
? initAppleProductionConfig
: initAppleStageConfig,
);
Expand Down
10 changes: 10 additions & 0 deletions examples/Basic/containers/CampaignScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@
'INITIAL',
);

const checkIfPaywallOpen = async () => {
const isOpen = await NamiPaywallManager.isPaywallOpen();
console.log('NamiSDK: paywall open? ', isOpen);
};

const showPaywallIfHidden = async () => {
try {
const isHidden = await NamiPaywallManager.isHidden()
Expand Down Expand Up @@ -129,13 +134,18 @@
}, []);

const triggerLaunch = (label?: any, url?: any) => {
checkIfPaywallOpen();

return NamiCampaignManager.launch(
label,
url,
{ customAttributes: {} },
(successAction, error) => {
console.log('successAction', successAction);
console.log('error', error);

checkIfPaywallOpen();

},
(
action,
Expand Down Expand Up @@ -192,9 +202,9 @@
? triggerLaunch(item.value, null)
: triggerLaunch(null, item.value);
}
}, []);

Check warning on line 205 in examples/Basic/containers/CampaignScreen.tsx

View workflow job for this annotation

GitHub Actions / ESLint

React Hook useCallback has a missing dependency: 'triggerLaunch'. Either include it or remove the dependency array

const onItemPressDefault = useCallback(() => triggerLaunch(null, null), []);

Check warning on line 207 in examples/Basic/containers/CampaignScreen.tsx

View workflow job for this annotation

GitHub Actions / ESLint

React Hook useCallback has a missing dependency: 'triggerLaunch'. Either include it or remove the dependency array

const onRefreshPress = useCallback(() => {
getAllCampaigns();
Expand Down
3 changes: 3 additions & 0 deletions examples/Basic/containers/ProfileScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,9 @@ const ProfileScreen: FC<ProfileScreenProps> = ({ navigation }) => {
}
},
);

NamiCustomerManager.setCustomerDataPlatformId('4444');

return () => {
subscriptionJourneyStateRemover();
subscriptionAccountStateRemover();
Expand Down
19 changes: 17 additions & 2 deletions examples/Basic/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,37 @@
import React, { useEffect, useState } from 'react';
import { View } from 'react-native';
import { AppRegistry } from 'react-native';
import { Nami } from 'react-native-nami-sdk';
import { Nami, NamiManager } from 'react-native-nami-sdk';
import App from './App';
import { name as appName } from './app.json';
import { getConfigObject } from './config';

const configDict = getConfigObject();
console.log('configDict', configDict);


const Root = () => {
const [isConfigurationComplete, setIsConfigurationComplete] = useState();

const checkSdkConfigured = async () => {
const configured = await NamiManager.sdkConfigured();
console.log('NamiSDK: configured', configured);
};

useEffect(() => {

checkSdkConfigured();

Nami.configure(configDict, (resultObject) => {
setIsConfigurationComplete(resultObject.success);
setIsConfigurationComplete(true);
checkSdkConfigured();

});

// eslint-disable-next-line @typescript-eslint/no-empty-function
return () => {};


}, []);

return isConfigurationComplete ? <App /> : <View />;
Expand Down
4 changes: 2 additions & 2 deletions examples/TestNamiTV/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -227,8 +227,8 @@ dependencies {
implementation "com.facebook.react:react-native:+" // From node_modules
implementation 'com.github.jeziellago:compose-markdown:0.3.0'

amazonImplementation "com.namiml:sdk-amazon:3.1.10"
playImplementation "com.namiml:sdk-android:3.1.10"
amazonImplementation "com.namiml:sdk-amazon::3.1.13"
playImplementation "com.namiml:sdk-android::3.1.13"

if (enableHermes) {
def hermesPath = "../../node_modules/hermes-engine/android/";
Expand Down
1 change: 1 addition & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ export { NamiMLManager } from './src/NamiMLManager';
export { NamiCampaignManager } from './src/NamiCampaignManager';
export { NamiCustomerManager } from './src/NamiCustomerManager';
export { NamiEntitlementManager } from './src/NamiEntitlementManager';
export { NamiManager } from './src/NamiManager';
export { NamiPurchaseManager } from './src/NamiPurchaseManager';
export { NamiPaywallManager } from './src/NamiPaywallManager';
export * from './src/types';
1 change: 1 addition & 0 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ export { NamiMLManager } from './src/NamiMLManager';
export { NamiCampaignManager } from './src/NamiCampaignManager';
export { NamiCustomerManager } from './src/NamiCustomerManager';
export { NamiEntitlementManager } from './src/NamiEntitlementManager';
export { NamiManager } from './src/NamiManager';
export { NamiPurchaseManager } from './src/NamiPurchaseManager';
export { NamiPaywallManager } from './src/NamiPaywallManager';
export * from './src/types';
24 changes: 14 additions & 10 deletions ios/Nami.m
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,11 @@ @interface NamiBridge : NSObject <RCTBridgeModule>
@implementation NamiBridge (RCTExternModule)

RCT_EXPORT_METHOD(configure: (NSDictionary *)configDict completion: (RCTResponseSenderBlock) completion) {
if ([configDict count] == 0 || [configDict[@"logLevel"] isEqual: @"DEBUG"] ) {
NSLog(@"Configure dictionary is %@", configDict);
}
NSString *appID = configDict[@"appPlatformID-apple"];

if ([appID length] > 0 ) {
NamiConfiguration *config = [NamiConfiguration configurationForAppPlatformId:appID];
NSLog(@"NAMI: RN Bridge - appPlatformId: %@", appID);

NSString *logLevelString = configDict[@"logLevel"];
if ([logLevelString isEqualToString:@"ERROR" ]) {
Expand All @@ -42,7 +40,7 @@ @implementation NamiBridge (RCTExternModule)

NSString *languageString = configDict[@"namiLanguageCode"];
if ([languageString length] > 0) {
NSLog(@"Nami language code from config dictionary is %@", languageString);
NSLog(@"NAMI: RN Bridge - language code: %@", languageString);
if ([[NamiLanguageCodes allAvailableNamiLanguageCodes]
containsObject:[languageString lowercaseString]] ) {
config.namiLanguageCode = languageString;
Expand All @@ -52,12 +50,12 @@ @implementation NamiBridge (RCTExternModule)
}

// Start commands with header iformation for Nami to let them know this is a React client.
NSMutableArray *namiCommandStrings = [NSMutableArray arrayWithArray:@[@"extendedClientInfo:react-native:3.1.10"]];
NSMutableArray *namiCommandStrings = [NSMutableArray arrayWithArray:@[@"extendedClientInfo:react-native:3.1.11"]];

// Add additional namiCommands app may have sent in.
NSObject *appCommandStrings = configDict[@"namiCommands"];
if ( appCommandStrings != NULL ) {
NSLog(@"NamiCommand from dictionary is %@", configDict[@"namiCommands"]);
NSLog(@"NAMI: RN Bridge - additional config settings %@", configDict[@"namiCommands"]);
if ([appCommandStrings isKindOfClass:[NSArray class]] ) {
for (NSObject *commandObj in ((NSArray *)appCommandStrings)){
if ([commandObj isKindOfClass:[NSString class]]) {
Expand All @@ -71,13 +69,19 @@ @implementation NamiBridge (RCTExternModule)

NSString *initialConfigString = configDict[@"initialConfig"];
if ([initialConfigString length] > 0) {
NSLog(@"Found an initialConfig file to use for Nami SDK setup.");
NSLog(@"NAMI: RN Bridge - Found an initialConfig file to use for Nami SDK setup.");
config.initialConfig = initialConfigString;
}

[Nami configureWith:config];
NSDictionary *dict = @{@"success": @YES};
completion(@[dict]);
[Nami configureWith:config :^(BOOL sdkConfigured) {
if ( sdkConfigured == YES ) {
NSDictionary *dict = @{@"success": @YES};
completion(@[dict]);
} else {
NSDictionary *dict = @{@"success": @NO};
completion(@[dict]);
}
}];
}
}

Expand Down
Loading
Loading