mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9c034a9904 | ||
|
|
b0a6010191 |
+1
-1
@@ -1,6 +1,6 @@
|
||||
Pod::Spec.new do |s|
|
||||
s.name = "React"
|
||||
s.version = "0.15.0"
|
||||
s.version = "0.17.0-rc"
|
||||
s.summary = "Build high quality mobile apps using React."
|
||||
s.description = <<-DESC
|
||||
React Native apps are built using the React JS
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
VERSION_NAME=0.12.0-SNAPSHOT
|
||||
VERSION_NAME=0.17.0
|
||||
GROUP=com.facebook.react
|
||||
|
||||
POM_NAME=ReactNative
|
||||
|
||||
+42
-9
@@ -1,4 +1,11 @@
|
||||
// Copyright 2004-present Facebook. All Rights Reserved.
|
||||
/**
|
||||
* Copyright (c) 2015-present, Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD-style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*/
|
||||
|
||||
package com.facebook.react.modules.netinfo;
|
||||
|
||||
@@ -10,6 +17,7 @@ import android.net.ConnectivityManager;
|
||||
import android.net.NetworkInfo;
|
||||
import android.support.v4.net.ConnectivityManagerCompat;
|
||||
|
||||
import com.facebook.common.logging.FLog;
|
||||
import com.facebook.react.bridge.Callback;
|
||||
import com.facebook.react.bridge.LifecycleEventListener;
|
||||
import com.facebook.react.bridge.ReactApplicationContext;
|
||||
@@ -17,25 +25,32 @@ import com.facebook.react.bridge.ReactContextBaseJavaModule;
|
||||
import com.facebook.react.bridge.ReactMethod;
|
||||
import com.facebook.react.bridge.WritableMap;
|
||||
import com.facebook.react.bridge.WritableNativeMap;
|
||||
import com.facebook.react.common.ReactConstants;
|
||||
|
||||
import static com.facebook.react.modules.core.DeviceEventManagerModule.RCTDeviceEventEmitter;
|
||||
|
||||
/**
|
||||
* Module that monitors and provides information about the connectivity state of the device.
|
||||
*/
|
||||
public class ConnectivityModule extends ReactContextBaseJavaModule
|
||||
public class NetInfoModule extends ReactContextBaseJavaModule
|
||||
implements LifecycleEventListener {
|
||||
|
||||
private static final String CONNECTION_TYPE_NONE = "NONE";
|
||||
private static final String CONNECTION_TYPE_UNKNOWN = "UNKNOWN";
|
||||
|
||||
private static final String MISSING_PERMISSION_MESSAGE =
|
||||
"To use NetInfo on Android, add the following to your AndroidManifest.xml:\n" +
|
||||
"<uses-permission android:name=\"android.permission.ACCESS_NETWORK_STATE\" />";
|
||||
|
||||
private final ConnectivityManager mConnectivityManager;
|
||||
private final ConnectivityManagerCompat mConnectivityManagerCompat;
|
||||
private final ConnectivityBroadcastReceiver mConnectivityBroadcastReceiver;
|
||||
|
||||
private boolean mNoNetworkPermission = false;
|
||||
|
||||
private String mConnectivity = "";
|
||||
|
||||
public ConnectivityModule(ReactApplicationContext reactContext) {
|
||||
public NetInfoModule(ReactApplicationContext reactContext) {
|
||||
super(reactContext);
|
||||
mConnectivityManager =
|
||||
(ConnectivityManager) reactContext.getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||
@@ -69,11 +84,23 @@ public class ConnectivityModule extends ReactContextBaseJavaModule
|
||||
|
||||
@ReactMethod
|
||||
public void getCurrentConnectivity(Callback successCallback, Callback errorCallback) {
|
||||
if (mNoNetworkPermission) {
|
||||
if (errorCallback == null) {
|
||||
FLog.e(ReactConstants.TAG, MISSING_PERMISSION_MESSAGE);
|
||||
return;
|
||||
}
|
||||
errorCallback.invoke(MISSING_PERMISSION_MESSAGE);
|
||||
return;
|
||||
}
|
||||
successCallback.invoke(createConnectivityEventMap());
|
||||
}
|
||||
|
||||
@ReactMethod
|
||||
public void isConnectionMetered(Callback successCallback) {
|
||||
if (mNoNetworkPermission) {
|
||||
FLog.e(ReactConstants.TAG, MISSING_PERMISSION_MESSAGE);
|
||||
return;
|
||||
}
|
||||
successCallback.invoke(mConnectivityManagerCompat.isActiveNetworkMetered(mConnectivityManager));
|
||||
}
|
||||
|
||||
@@ -98,15 +125,21 @@ public class ConnectivityModule extends ReactContextBaseJavaModule
|
||||
}
|
||||
|
||||
private String getCurrentConnectionType() {
|
||||
NetworkInfo networkInfo = mConnectivityManager.getActiveNetworkInfo();
|
||||
if (networkInfo == null || !networkInfo.isConnected()) {
|
||||
return CONNECTION_TYPE_NONE;
|
||||
} else if (ConnectivityManager.isNetworkTypeValid(networkInfo.getType())) {
|
||||
return networkInfo.getTypeName().toUpperCase();
|
||||
} else {
|
||||
try {
|
||||
NetworkInfo networkInfo = mConnectivityManager.getActiveNetworkInfo();
|
||||
if (networkInfo == null || !networkInfo.isConnected()) {
|
||||
return CONNECTION_TYPE_NONE;
|
||||
} else if (ConnectivityManager.isNetworkTypeValid(networkInfo.getType())) {
|
||||
return networkInfo.getTypeName().toUpperCase();
|
||||
} else {
|
||||
return CONNECTION_TYPE_UNKNOWN;
|
||||
}
|
||||
} catch (SecurityException e) {
|
||||
mNoNetworkPermission = true;
|
||||
return CONNECTION_TYPE_UNKNOWN;
|
||||
}
|
||||
}
|
||||
|
||||
private void sendConnectivityChangedEvent() {
|
||||
getReactApplicationContext().getJSModule(RCTDeviceEventEmitter.class)
|
||||
.emit("networkStatusDidChange", createConnectivityEventMap());
|
||||
@@ -20,7 +20,7 @@ import com.facebook.react.bridge.ReactApplicationContext;
|
||||
import com.facebook.react.modules.fresco.FrescoModule;
|
||||
import com.facebook.react.modules.intent.IntentModule;
|
||||
import com.facebook.react.modules.location.LocationModule;
|
||||
import com.facebook.react.modules.netinfo.ConnectivityModule;
|
||||
import com.facebook.react.modules.netinfo.NetInfoModule;
|
||||
import com.facebook.react.modules.network.NetworkingModule;
|
||||
import com.facebook.react.modules.storage.AsyncStorageModule;
|
||||
import com.facebook.react.modules.toast.ToastModule;
|
||||
@@ -57,7 +57,7 @@ public class MainReactPackage implements ReactPackage {
|
||||
new IntentModule(reactContext),
|
||||
new LocationModule(reactContext),
|
||||
new NetworkingModule(reactContext),
|
||||
new ConnectivityModule(reactContext),
|
||||
new NetInfoModule(reactContext),
|
||||
new WebSocketModule(reactContext),
|
||||
new ToastModule(reactContext));
|
||||
}
|
||||
|
||||
@@ -74,5 +74,5 @@ android {
|
||||
dependencies {
|
||||
compile fileTree(dir: "libs", include: ["*.jar"])
|
||||
compile "com.android.support:appcompat-v7:23.0.1"
|
||||
compile "com.facebook.react:react-native:0.13.0"
|
||||
compile "com.facebook.react:react-native:0.17.+"
|
||||
}
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "react-native",
|
||||
"version": "0.12.0",
|
||||
"version": "0.17.0-rc",
|
||||
"description": "A framework for building native apps using React",
|
||||
"license": "BSD-3-Clause",
|
||||
"repository": {
|
||||
|
||||
Reference in New Issue
Block a user