inAppPurchases: Call a function from App.js to child Screen

Please provide the following:

  1. SDK Version: 40
  2. Platforms(Android/iOS/web/all): Android and iOS

I have an App in Expo (SDK 40) migrated from SDK 36, in Bare worflow, because I’m using a library for InAppPurchases (InAppPurchases - Expo Documentation). For navigation I’m using react-navigation.

In SDK36 the library for InApp Purchases was very simple to implement. Just a function to purchase, with a callback to do the transaction functions and enable the things that user just bought.

in SDK40, the library InApp Purchases is a little bit more complicated. I have to define a setPurchaseListener defined in the global scope (for me works defined in App.js), so, in the screen when the purchase is made, we do:

  1. PurchaseScreen: we call purchaseItemAsync(sku). if is done, will call setPurchaseListener
  2. App.js: is defined setPurchaseListener(responseCode, results, errorCode), so if purchase is done this will be called, and all things to unlock is declared here (previously in SDK36 this was on PurchaseScreen) / I tried def the function in purchaseItemAsync too but not work.
  3. App.js → PurchaseScreen: I need to call a function defined in PurchaseScreen to unlock the things user’s purchased, but from App.js

I think I can solve using Mobx, I created a store shared for both, but, how can I execute the function in PurchaseScreen?

I though using mobx because is easier to implement as redux, but maybe is not necesary solve with mobx, maybe I can do just using javascript.

Thanks very much for your help

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.