mirror of
https://github.com/zhigang1992/react-native-firebase.git
synced 2026-04-23 20:10:05 +08:00
Merge commit '49d29b53f21e530f5c918e472db93ee856947426'
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
package io.invertase.firebase.analytics;
|
||||
|
||||
import android.support.annotation.RequiresPermission;
|
||||
|
||||
import com.facebook.react.ReactPackage;
|
||||
import com.facebook.react.bridge.JavaScriptModule;
|
||||
import com.facebook.react.bridge.NativeModule;
|
||||
@@ -13,6 +15,9 @@ import java.util.List;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public class RNFirebaseAnalyticsPackage implements ReactPackage {
|
||||
@RequiresPermission(
|
||||
allOf = {"android.permission.INTERNET", "android.permission.ACCESS_NETWORK_STATE", "android.permission.WAKE_LOCK"}
|
||||
)
|
||||
public RNFirebaseAnalyticsPackage() {
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package io.invertase.firebase.auth;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.os.Parcel;
|
||||
import android.util.Log;
|
||||
import android.net.Uri;
|
||||
import android.support.annotation.NonNull;
|
||||
@@ -721,6 +723,101 @@ class RNFirebaseAuth extends ReactContextBaseJavaModule {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* verifyPhoneNumber
|
||||
*
|
||||
* @param appName
|
||||
* @param phoneNumber
|
||||
* @param timeout
|
||||
*/
|
||||
@ReactMethod
|
||||
public void verifyPhoneNumber(final String appName, final String phoneNumber, final String requestKey, final int timeout) {
|
||||
FirebaseApp firebaseApp = FirebaseApp.getInstance(appName);
|
||||
final FirebaseAuth firebaseAuth = FirebaseAuth.getInstance(firebaseApp);
|
||||
final Activity activity = mReactContext.getCurrentActivity();
|
||||
|
||||
Log.d(TAG, "verifyPhoneNumber:" + phoneNumber);
|
||||
|
||||
PhoneAuthProvider.OnVerificationStateChangedCallbacks callbacks = new PhoneAuthProvider.OnVerificationStateChangedCallbacks() {
|
||||
|
||||
@Override
|
||||
public void onVerificationCompleted(final PhoneAuthCredential phoneAuthCredential) {
|
||||
Log.d(TAG, "verifyPhoneNumber:verification:onVerificationCompleted");
|
||||
WritableMap state = Arguments.createMap();
|
||||
|
||||
Parcel parcel = Parcel.obtain();
|
||||
phoneAuthCredential.writeToParcel(parcel, 0);
|
||||
|
||||
// verificationId
|
||||
parcel.setDataPosition(16);
|
||||
String verificationId = parcel.readString();
|
||||
|
||||
// sms Code
|
||||
parcel.setDataPosition(parcel.dataPosition() + 8);
|
||||
String code = parcel.readString();
|
||||
|
||||
state.putString("code", code);
|
||||
state.putString("verificationId", verificationId);
|
||||
parcel.recycle();
|
||||
sendPhoneStateEvent(appName, requestKey, "onVerificationComplete", state);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onVerificationFailed(FirebaseException e) {
|
||||
// This callback is invoked in an invalid request for verification is made,
|
||||
// e.g. phone number format is incorrect, or the SMS quota for the project
|
||||
// has been exceeded
|
||||
Log.d(TAG, "verifyPhoneNumber:verification:onVerificationFailed");
|
||||
WritableMap state = Arguments.createMap();
|
||||
state.putMap("error", getJSError(e));
|
||||
sendPhoneStateEvent(appName, requestKey, "onVerificationFailed", state);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCodeSent(String verificationId, PhoneAuthProvider.ForceResendingToken forceResendingToken) {
|
||||
Log.d(TAG, "verifyPhoneNumber:verification:onCodeSent");
|
||||
WritableMap state = Arguments.createMap();
|
||||
state.putString("verificationId", verificationId);
|
||||
|
||||
// todo forceResendingToken - it's actually just an empty class ... no actual token >.>
|
||||
// Parcel parcel = Parcel.obtain();
|
||||
// forceResendingToken.writeToParcel(parcel, 0);
|
||||
//
|
||||
// // verificationId
|
||||
// parcel.setDataPosition(0);
|
||||
// int int1 = parcel.readInt();
|
||||
// String token = parcel.readString();
|
||||
//
|
||||
// state.putString("refreshToken", token);
|
||||
// parcel.recycle();
|
||||
|
||||
state.putString("verificationId", verificationId);
|
||||
sendPhoneStateEvent(appName, requestKey, "onCodeSent", state);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCodeAutoRetrievalTimeOut(String verificationId) {
|
||||
super.onCodeAutoRetrievalTimeOut(verificationId);
|
||||
Log.d(TAG, "verifyPhoneNumber:verification:onCodeAutoRetrievalTimeOut");
|
||||
WritableMap state = Arguments.createMap();
|
||||
state.putString("verificationId", verificationId);
|
||||
sendPhoneStateEvent(appName, requestKey, "onCodeAutoRetrievalTimeout", state);
|
||||
}
|
||||
};
|
||||
|
||||
if (activity != null) {
|
||||
PhoneAuthProvider.getInstance(firebaseAuth)
|
||||
.verifyPhoneNumber(
|
||||
phoneNumber,
|
||||
timeout,
|
||||
TimeUnit.SECONDS,
|
||||
activity,
|
||||
callbacks
|
||||
//, PhoneAuthProvider.ForceResendingToken.zzboe() // TODO FORCE RESENDING
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* confirmPasswordReset
|
||||
*
|
||||
@@ -1270,4 +1367,19 @@ class RNFirebaseAuth extends ReactContextBaseJavaModule {
|
||||
|
||||
return userMap;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param appName
|
||||
* @param requestKey
|
||||
* @param type
|
||||
* @param state
|
||||
*/
|
||||
private void sendPhoneStateEvent(String appName, String requestKey, String type, WritableMap state) {
|
||||
WritableMap eventMap = Arguments.createMap();
|
||||
eventMap.putString("appName", appName);
|
||||
eventMap.putString("requestKey", requestKey);
|
||||
eventMap.putString("type", type);
|
||||
eventMap.putMap("state", state);
|
||||
Utils.sendEvent(mReactContext, "phone_auth_state_changed", eventMap);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,6 +27,7 @@ import com.google.firebase.messaging.RemoteMessage.Notification;
|
||||
|
||||
import io.invertase.firebase.Utils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
@@ -72,6 +73,18 @@ public class RNFirebaseMessaging extends ReactContextBaseJavaModule implements L
|
||||
promise.resolve(FirebaseInstanceId.getInstance().getToken());
|
||||
}
|
||||
|
||||
@ReactMethod
|
||||
public void deleteInstanceId(Promise promise){
|
||||
try {
|
||||
Log.d(TAG, "Deleting instance id");
|
||||
FirebaseInstanceId.getInstance().deleteInstanceId();
|
||||
promise.resolve(null);
|
||||
} catch (IOException e) {
|
||||
Log.e(TAG, e.getMessage());
|
||||
promise.reject(null, e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@ReactMethod
|
||||
public void createLocalNotification(ReadableMap details) {
|
||||
Bundle bundle = Arguments.toBundle(details);
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package io.invertase.firebase.storage;
|
||||
|
||||
import android.support.annotation.RequiresPermission;
|
||||
|
||||
import com.facebook.react.ReactPackage;
|
||||
import com.facebook.react.bridge.JavaScriptModule;
|
||||
import com.facebook.react.bridge.NativeModule;
|
||||
@@ -13,6 +15,9 @@ import java.util.List;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public class RNFirebaseStoragePackage implements ReactPackage {
|
||||
@RequiresPermission(
|
||||
allOf = {"android.permission.INTERNET", "android.permission.ACCESS_NETWORK_STATE", "android.permission.READ_EXTERNAL_STORAGE", "android.permission.WRITE_EXTERNAL_STORAGE"}
|
||||
)
|
||||
public RNFirebaseStoragePackage() {
|
||||
}
|
||||
|
||||
@@ -35,7 +40,7 @@ public class RNFirebaseStoragePackage implements ReactPackage {
|
||||
* listed here. Also listing a native module here doesn't imply that the JS implementation of it
|
||||
* will be automatically included in the JS bundle.
|
||||
*/
|
||||
// TODO: Removed in 0.47.0. Here for backwards compatability
|
||||
// TODO: Removed in 0.47.0. Here for backwards compatibility
|
||||
public List<Class<? extends JavaScriptModule>> createJSModules() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user