Skip to content

Commit

Permalink
Merge branch 'main' into NC-5315-update-rn-sdk
Browse files Browse the repository at this point in the history
  • Loading branch information
namidan authored Sep 5, 2024
2 parents 79e4f3b + ad96c01 commit ee665a3
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 26 deletions.
2 changes: 1 addition & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
node_modules/
.eslintrc
.eslintrc.*
*.d.ts
10 changes: 8 additions & 2 deletions android/src/main/java/com/nami/reactlibrary/NamiCampaignManagerBridge.kt
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -294,8 +294,14 @@ class NamiCampaignManagerBridgeModule(reactContext: ReactApplicationContext) :
}

@ReactMethod
fun refresh() {
NamiCampaignManager.refresh { }
fun refresh(promise: Promise) {
NamiCampaignManager.refresh { campaigns ->
val array = WritableNativeArray()
campaigns?.forEach { campaign ->
array.pushMap(campaignToReadableMap(campaign))
}
promise.resolve(array)
}
}

@ReactMethod
Expand Down
23 changes: 16 additions & 7 deletions examples/Basic/containers/CampaignScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,15 @@ const CampaignScreen: FC<CampaignScreenProps> = ({ navigation }) => {
return sortedCampaigns;
}, []);

const getRefreshedCampaigns = useCallback(async () => {
const fetchedCampaigns = await NamiCampaignManager.refresh();
const refreshedCampaigns = fetchedCampaigns.filter((campaign) =>
Boolean(campaign.value),
);
setCampaigns(refreshedCampaigns);
return refreshedCampaigns;
}, []);

useEffect(() => {

const subscriptionSignInRemover = NamiPaywallManager.registerSignInHandler(
Expand Down Expand Up @@ -162,7 +171,7 @@ const CampaignScreen: FC<CampaignScreenProps> = ({ navigation }) => {
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);

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

NamiPaywallManager.setAppSuppliedVideoDetails('https://storage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4', 'app-supplied-video');
Expand Down Expand Up @@ -200,7 +209,7 @@ const CampaignScreen: FC<CampaignScreenProps> = ({ navigation }) => {
setAction(event.action);
},
);
};
}, [])

const isCampaignAvailable = async (value?: string | null | undefined) => {
try {
Expand All @@ -218,14 +227,14 @@ const CampaignScreen: FC<CampaignScreenProps> = ({ navigation }) => {
? triggerLaunch(item.value, null)
: triggerLaunch(null, item.value);
}
}, []);
}, [triggerLaunch]);

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

const onRefreshPress = useCallback(() => {
getAllCampaigns();
setRefresh(!refresh);
NamiCampaignManager.refresh();
getRefreshedCampaigns();
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);

Expand All @@ -240,13 +249,13 @@ const CampaignScreen: FC<CampaignScreenProps> = ({ navigation }) => {
onRefreshPress={() => {
getAllCampaigns();
setRefresh(!refresh);
NamiCampaignManager.refresh();
getRefreshedCampaigns();
}}
/>
),
headerLeft: () => <HeaderLeft onButtonPress={onButtonPress} />,
});
}, [navigation, onRefreshPress, onButtonPress, getAllCampaigns, refresh]);
}, [navigation, onRefreshPress, onButtonPress, getAllCampaigns, getRefreshedCampaigns, refresh]);

const renderItem = ({ item, index }: {item: NamiCampaign; index: number}) => {
const lasItem = index === campaigns.length - 1;
Expand Down
11 changes: 3 additions & 8 deletions examples/Basic/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,26 +39,21 @@ const Root = () => {
};

useEffect(() => {

async function configureSDK() {
// You can await here
async function configureNami() {
checkSdkConfigured();

const result = await Nami.configure(configDict);
if(result.success){
if (result.success) {
setIsConfigurationComplete(true);
checkSdkConfigured();
}

initStoreConnection();
// ...
}
configureSDK();
configureNami();

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


}, []);

useEffect(() => {
Expand Down
8 changes: 6 additions & 2 deletions examples/TestNamiTV/containers/CampaignScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,12 @@ const CampaignScreen: FC<CampaignScreenProps> = ({ navigation }) => {

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

const onRefreshPress = useCallback(() => {
NamiCampaignManager.refresh();
const onRefreshPress = useCallback(async () => {
const fetchedCampaigns = await NamiCampaignManager.refresh();
const refreshedCampaigns = fetchedCampaigns.filter(campaign =>
Boolean(campaign.value),
);
setCampaigns(refreshedCampaigns);
}, []);

useLayoutEffect(() => {
Expand Down
2 changes: 1 addition & 1 deletion ios/NamiCampaignManagerBridge.m
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ @interface RCT_EXTERN_MODULE(RNNamiCampaignManager, NSObject)

RCT_EXTERN_METHOD(isCampaignAvailable:(nullable NSString *)campaignSource resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject)

RCT_EXTERN_METHOD(refresh)
RCT_EXTERN_METHOD(refresh:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject)

RCT_EXTERN_METHOD(registerAvailableCampaignsHandler)

Expand Down
9 changes: 6 additions & 3 deletions ios/NamiCampaignManagerBridge.swift
Original file line number Diff line number Diff line change
Expand Up @@ -270,9 +270,12 @@ class RNNamiCampaignManager: RCTEventEmitter {
resolve(isCampaignAvailable)
}

@objc(refresh)
func refresh() {
NamiCampaignManager.refresh()
@objc(refresh:rejecter:)
func refresh(resolve: @escaping RCTPromiseResolveBlock, reject _: @escaping RCTPromiseRejectBlock) {
NamiCampaignManager.refresh { campaigns in
let dictionaries = campaigns.map { campaign in self.campaignInToDictionary(campaign) }
resolve(dictionaries)
}
}

@objc(registerAvailableCampaignsHandler)
Expand Down
2 changes: 1 addition & 1 deletion src/NamiCampaignManager.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ interface ICampaignManager {
allCampaigns: () => Promise<Array<NamiCampaign>>;
isCampaignAvailable(campaignSource: string | null): Promise<boolean>;
launch: (label?: string, withUrl?: string, context?: PaywallLaunchContext, resultCallback?: (success: boolean, error?: LaunchCampaignError) => void, actionCallback?: NamiPaywallActionHandler) => void;
refresh: () => void;
refresh: () => Promise<Array<NamiCampaign>>;
registerAvailableCampaignsHandler: (callback: (availableCampaigns: NamiCampaign[]) => void) => EmitterSubscription['remove'];
}
export declare const NamiCampaignManager: ICampaignManager;
Expand Down
2 changes: 1 addition & 1 deletion src/NamiCampaignManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ interface ICampaignManager {
resultCallback?: (success: boolean, error?: LaunchCampaignError) => void,
actionCallback?: NamiPaywallActionHandler,
) => void;
refresh: () => void;
refresh: () => Promise<Array<NamiCampaign>>;
registerAvailableCampaignsHandler: (
callback: (availableCampaigns: NamiCampaign[]) => void,
) => EmitterSubscription['remove'];
Expand Down

0 comments on commit ee665a3

Please sign in to comment.