I'm trying to build react-native
module that require pass the Activity
to some method
private ReactApplicationContext reactContext;
...
@ReactMethod
public void sendVerificationCode(String phoneNumber)
{
PhoneAuthProvider.getInstance().verifyPhoneNumber(
phoneNumber, // Phone number to verify
60, // Timeout duration
TimeUnit.SECONDS, // Unit of timeout
reactContext.getCurrentActivity(), // Activity (for callback binding)
callback); // OnVerificationStateChangedCallbacks
}
I used reactContext.getCurrentActivity()
to get the current activity from but it tells me that getCurrentActivity()
is not public and cannot be accessed from outside package
getCurrentActivity is not public 'com.facebook.react.bridge.React Context` cannot be accessed from outside package
how could I get the current activity ?
full code :
public class FirebasePhoneAuth extends ReactContextBaseJavaModule
{
private ReactApplicationContext reactContext;
private OnVerificationStateChanged callback;
public FirebasePhoneAuth(ReactApplicationContext reactContext)
{
super(reactContext);
this.reactContext = reactContext;
}
@Override
public String getName()
{
return "FirebasePhoneAuth";
}
@ReactMethod
public void sendVerificationCode(String phoneNumber)
{
PhoneAuthProvider.getInstance().verifyPhoneNumber(
phoneNumber, // Phone number to verify
60, // Timeout duration
TimeUnit.SECONDS, // Unit of timeout
reactContext.getCurrentActivity(), // Activity (for callback binding)
callback); // OnVerificationStateChangedCallbacks
}
}
the class ReactContextBaseJavaModule
already have method getCurrentActivity()
code :
public class FirebasePhoneAuth extends ReactContextBaseJavaModule
{
...
@ReactMethod
public void sendVerificationCode(String phoneNumber)
{
Activity activity = getCurrentActivity();
PhoneAuthProvider.getInstance().verifyPhoneNumber(
phoneNumber,
60,
TimeUnit.SECONDS,
activity,
callback);
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With