Skip to content

Commit

Permalink
update android bridge for 3.1.x
Browse files Browse the repository at this point in the history
  • Loading branch information
namidan committed Jul 27, 2023
1 parent 704fb0a commit bd16594
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 72 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ class NamiBridgeModule(reactContext: ReactApplicationContext) :
} else {
Arguments.createArray()
}
val settingsList = mutableListOf("extendedClientInfo:react-native:3.0.24")
val settingsList = mutableListOf("extendedClientInfo:react-native:3.0.25")
namiCommandsReact?.toArrayList()?.filterIsInstance<String>()?.let { commandsFromReact ->
settingsList.addAll(commandsFromReact)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ import com.namiml.billing.NamiPurchase
import com.namiml.campaign.LaunchCampaignResult
import com.namiml.campaign.NamiCampaign
import com.namiml.campaign.NamiCampaignManager
import com.namiml.paywall.NamiSKU
import com.namiml.paywall.model.NamiPaywallAction
import com.namiml.paywall.model.PaywallLaunchContext

class NamiCampaignManagerBridgeModule(reactContext: ReactApplicationContext) :
Expand Down Expand Up @@ -92,42 +90,16 @@ class NamiCampaignManagerBridgeModule(reactContext: ReactApplicationContext) :
} else {
paywallLaunchContext = PaywallLaunchContext(null, customAttributes)
}

}

if (theActivity != null) {
reactApplicationContext.runOnUiQueueThread {
val paywallActionCallback = {
campaignId: String,
campaignName: String?,
campaignType: String?,
campaignLabel: String?,
campaignUrl: String?,
paywallId: String,
paywallName: String?,
segmentId: String?,
externalSegmentId: String?,
action: NamiPaywallAction,
sku: NamiSKU?,
purchaseError: String?,
purchases: List<NamiPurchase>?,
deeplinkUrl: String? ->
paywallEvent: NamiPaywallEvent ->
handlePaywallCallback(
campaignId,
campaignName,
campaignType,
campaignLabel,
campaignUrl,
paywallId,
paywallName,
segmentId,
externalSegmentId,
action,
sku,
purchaseError,
purchases,
deeplinkUrl,
actionCallback)
paywallEvent,
actionCallback,
)
}

val uriObject: Uri? = if (withUrl != null) Uri.parse(withUrl) else null
Expand All @@ -154,48 +126,34 @@ class NamiCampaignManagerBridgeModule(reactContext: ReactApplicationContext) :
}
}
}

}

private fun handlePaywallCallback(
campaignId: String,
campaignName: String?,
campaignType: String?,
campaignLabel: String?,
campaignUrl: String?,
paywallId: String,
paywallName: String?,
segmentId: String?,
externalSegmentId: String?,
action: NamiPaywallAction,
sku: NamiSKU?,
purchaseError: String?,
purchases: List<NamiPurchase>?,
deeplinkUrl: String?,
actionCallback: Callback
paywallEvent: NamiPaywallEvent,
actionCallback: Callback,
) {
val actionString = action.toString()
val skuString = sku?.skuId ?: ""
val actionString = paywallEvent.action.toString()
val skuString = paywallEvent.sku?.skuId ?: ""

val purchasesArray = createPurchaseArray(purchases)

val resultMap = Arguments.createMap().apply {
putString(CAMPAIGN_ID, campaignId)
putString(CAMPAIGN_LABEL, campaignLabel ?: "")
putString(PAYWALL_ID, paywallId)
putString(ACTION, actionString)
putString(CAMPAIGN_ID, paywallEvent.campaignId)
putString(CAMPAIGN_LABEL, paywallEvent.campaignLabel ?: "")
putString(PAYWALL_ID, paywallEvent.paywallId)
putString(ACTION, paywallEvent.actionString)
putString(SKU_ID, skuString)
putString(PURCHASE_ERROR, purchaseError ?: "")
putArray(PURCHASES, purchasesArray)
putString(CAMPAIGN_NAME, campaignName ?: "")
putString(CAMPAIGN_TYPE, campaignType ?: "")
putString(CAMPAIGN_URL, campaignUrl ?: "")
putString(PAYWALL_NAME, paywallName ?: "")
putString(COMPONENT_CHANGE_ID, "")
putString(COMPONENT_CHANGE_NAME, "")
putString(SEGMENT_ID, segmentId ?: "")
putString(EXTERNAL_SEGMENT_ID, externalSegmentId ?: "")
putString(DEEP_LINK_URL, deeplinkUrl ?: "")
putString(PURCHASE_ERROR, paywallEvent.purchaseError ?: "")
putArray(PURCHASES, paywallEvent.purchasesArray)
putString(CAMPAIGN_NAME, paywallEvent.campaignName ?: "")
putString(CAMPAIGN_TYPE, paywallEvent.campaignType ?: "")
putString(CAMPAIGN_URL, paywallEvent.campaignUrl ?: "")
putString(PAYWALL_NAME, paywallEvent.paywallName ?: "")
putString(COMPONENT_CHANGE_ID, paywallEvent?.componentChange?.id ?: "")
putString(COMPONENT_CHANGE_NAME, paywallEvent?.componentChange?.name ?: "")
putString(SEGMENT_ID, paywallEvent.segmentId ?: "")
putString(EXTERNAL_SEGMENT_ID, paywallEvent.externalSegmentId ?: "")
putString(DEEP_LINK_URL, paywallEvent.deeplinkUrl ?: "")
}

emitEvent(_RESULT_CAMPAIGN, resultMap)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ class NamiPaywallManagerBridgeModule(reactContext: ReactApplicationContext) :
if (productId != null && skuId != null && skuType != null) {
val namiSku = NamiSKU(
skuId = skuId,
skuDetails = null,
productDetails = null,
amazonProduct = null,
id = productId,
type = skuType,
Expand Down
3 changes: 1 addition & 2 deletions android/src/main/java/com/nami/reactlibrary/NamiUtil.kt
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,7 @@ fun NamiSKU.toSkuDict(): WritableMap {
productDict.putString("skuId", this.skuId)
productDict.putString("id", this.id)
productDict.putString("type", this.type.toString())
productDict.putString("promoId","")
productDict.putString("promoToken","")
productDict.putString("promoId", "")

return productDict
}
Expand Down
2 changes: 1 addition & 1 deletion ios/Nami.m
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ @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.0.24"]];
NSMutableArray *namiCommandStrings = [NSMutableArray arrayWithArray:@[@"extendedClientInfo:react-native:3.0.25"]];

// Add additional namiCommands app may have sent in.
NSObject *appCommandStrings = configDict[@"namiCommands"];
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-native-nami-sdk",
"version": "3.0.24",
"version": "3.0.25",
"description": "React Native Module for Nami - Easy subscriptions & in-app purchases, with powerful built-in paywalls and A/B testing.",
"main": "index.js",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion react-native-nami-sdk.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Pod::Spec.new do |s|
s.source_files = "ios/**/*.{h,m,swift}"
s.requires_arc = true

s.dependency 'Nami', '3.1.1'
s.dependency 'Nami', '3.1.2'
s.dependency 'React'

end

0 comments on commit bd16594

Please sign in to comment.