@norcy/react-native-toolkit 0.1.145 → 0.1.146
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/android/src/main/java/com/norcy/reactnativetoolkit/BaseToolkitActivity.java +3 -0
- package/android/src/main/java/com/norcy/reactnativetoolkit/BaseToolkitApplication.java +52 -45
- package/android/src/main/java/com/norcy/reactnativetoolkit/NCYAPI.java +3 -17
- package/android/src/main/java/com/norcy/reactnativetoolkit/PreferencesManager.java +50 -0
- package/android/src/main/java/com/norcy/reactnativetoolkit/UMengManager.java +54 -0
- package/package.json +3 -1
- package/yarn.lock +5 -0
@@ -6,6 +6,7 @@ import android.net.Uri;
|
|
6
6
|
import android.os.Bundle;
|
7
7
|
import android.view.WindowManager;
|
8
8
|
import android.content.res.Configuration;
|
9
|
+
import org.devio.rn.splashscreen.SplashScreen;
|
9
10
|
|
10
11
|
public abstract class BaseToolkitActivity extends ReactActivity {
|
11
12
|
@Override
|
@@ -13,6 +14,8 @@ public abstract class BaseToolkitActivity extends ReactActivity {
|
|
13
14
|
// 处理 DEBUG 模式下的屏幕常亮
|
14
15
|
if (getReactNativeHost().getUseDeveloperSupport()) {
|
15
16
|
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
|
17
|
+
} else {
|
18
|
+
SplashScreen.show(this, true);
|
16
19
|
}
|
17
20
|
super.onCreate(savedInstanceState);
|
18
21
|
|
@@ -3,57 +3,64 @@ package com.norcy.reactnativetoolkit;
|
|
3
3
|
import android.app.Application;
|
4
4
|
import android.content.Context;
|
5
5
|
|
6
|
+
import com.facebook.react.BuildConfig;
|
6
7
|
import com.facebook.react.PackageList;
|
7
8
|
import com.facebook.react.ReactApplication;
|
8
9
|
import com.facebook.react.ReactNativeHost;
|
9
10
|
import com.facebook.react.ReactPackage;
|
10
11
|
import com.facebook.soloader.SoLoader;
|
11
|
-
import cn.reactnative.modules.update.UpdateContext;
|
12
12
|
|
13
13
|
import java.util.List;
|
14
14
|
|
15
15
|
public abstract class BaseToolkitApplication extends Application implements ReactApplication {
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
}
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
16
|
+
private final ReactNativeHost mReactNativeHost;
|
17
|
+
|
18
|
+
public BaseToolkitApplication() {
|
19
|
+
mReactNativeHost = createReactNativeHost();
|
20
|
+
}
|
21
|
+
|
22
|
+
// 让子类可以完全控制要使用哪些包
|
23
|
+
protected abstract List<ReactPackage> getPackages();
|
24
|
+
|
25
|
+
// 让子类决定如何获取 JS Bundle URL,返回 null 则使用默认的 bundle
|
26
|
+
protected abstract String getJSBundleUrl();
|
27
|
+
|
28
|
+
// 让子类提供友盟统计的 AppKey
|
29
|
+
protected abstract String getUmengAppKey();
|
30
|
+
|
31
|
+
protected ReactNativeHost createReactNativeHost() {
|
32
|
+
return new ReactNativeHost(this) {
|
33
|
+
@Override
|
34
|
+
public boolean getUseDeveloperSupport() {
|
35
|
+
return BuildConfig.DEBUG;
|
36
|
+
}
|
37
|
+
|
38
|
+
@Override
|
39
|
+
protected List<ReactPackage> getPackages() {
|
40
|
+
return BaseToolkitApplication.this.getPackages();
|
41
|
+
}
|
42
|
+
|
43
|
+
@Override
|
44
|
+
protected String getJSBundleFile() {
|
45
|
+
return BaseToolkitApplication.this.getJSBundleUrl();
|
46
|
+
}
|
47
|
+
|
48
|
+
@Override
|
49
|
+
protected String getJSMainModuleName() {
|
50
|
+
return "index";
|
51
|
+
}
|
52
|
+
};
|
53
|
+
}
|
54
|
+
|
55
|
+
@Override
|
56
|
+
public ReactNativeHost getReactNativeHost() {
|
57
|
+
return mReactNativeHost;
|
58
|
+
}
|
59
|
+
|
60
|
+
@Override
|
61
|
+
public void onCreate() {
|
62
|
+
super.onCreate();
|
63
|
+
SoLoader.init(this, false);
|
64
|
+
UMengManager.getInstance().setup(this, getUmengAppKey());
|
65
|
+
}
|
66
|
+
}
|
@@ -6,7 +6,6 @@ import static android.Manifest.permission.READ_EXTERNAL_STORAGE;
|
|
6
6
|
import android.app.Activity;
|
7
7
|
import android.content.Context;
|
8
8
|
import android.content.Intent;
|
9
|
-
import android.content.SharedPreferences;
|
10
9
|
import android.content.pm.PackageManager;
|
11
10
|
import android.net.Uri;
|
12
11
|
import android.os.Build;
|
@@ -21,7 +20,6 @@ import com.facebook.react.bridge.ReactApplicationContext;
|
|
21
20
|
import com.facebook.react.bridge.ReactContextBaseJavaModule;
|
22
21
|
import com.facebook.react.bridge.ReactMethod;
|
23
22
|
import com.facebook.react.bridge.ReadableMap;
|
24
|
-
import com.umeng.commonsdk.UMConfigure;
|
25
23
|
|
26
24
|
import androidx.core.app.ActivityCompat;
|
27
25
|
import androidx.core.content.ContextCompat;
|
@@ -29,7 +27,6 @@ import androidx.core.content.ContextCompat;
|
|
29
27
|
import java.io.File;
|
30
28
|
|
31
29
|
public class NCYAPI extends ReactContextBaseJavaModule implements ActivityEventListener {
|
32
|
-
private static final String PREFS_NAME = "NCYAPIPrefs"; // 偏好设置文件名
|
33
30
|
private static final int REQUEST_CODE = 228228;
|
34
31
|
public static final String NAME = "ManageExternalStorage";
|
35
32
|
Promise promise;
|
@@ -46,28 +43,17 @@ public class NCYAPI extends ReactContextBaseJavaModule implements ActivityEventL
|
|
46
43
|
|
47
44
|
@ReactMethod
|
48
45
|
public void onAgree() {
|
49
|
-
|
50
|
-
editor.putBoolean("umeng_agreed", true);
|
51
|
-
editor.apply();
|
52
|
-
UMConfigure.init(getReactApplicationContext(), "638196f005844627b58c1db6", "Umeng", UMConfigure.DEVICE_TYPE_PHONE, "");
|
46
|
+
UMengManager.getInstance().onUserAgree();
|
53
47
|
}
|
54
48
|
|
55
49
|
@ReactMethod(isBlockingSynchronousMethod = true)
|
56
50
|
public void setData(String key, String value) {
|
57
|
-
|
58
|
-
editor.putString(key, value);
|
59
|
-
editor.apply();
|
51
|
+
PreferencesManager.getInstance(getReactApplicationContext()).setString(key, value);
|
60
52
|
}
|
61
53
|
|
62
54
|
@ReactMethod(isBlockingSynchronousMethod = true)
|
63
55
|
public String getData(String key) {
|
64
|
-
|
65
|
-
return preferences.getString(key, "");
|
66
|
-
}
|
67
|
-
|
68
|
-
private SharedPreferences getSharedPreferences() {
|
69
|
-
Context context = getReactApplicationContext();
|
70
|
-
return context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE);
|
56
|
+
return PreferencesManager.getInstance(getReactApplicationContext()).getString(key, "");
|
71
57
|
}
|
72
58
|
|
73
59
|
@ReactMethod
|
@@ -0,0 +1,50 @@
|
|
1
|
+
package com.norcy.reactnativetoolkit;
|
2
|
+
|
3
|
+
import android.content.Context;
|
4
|
+
import android.content.SharedPreferences;
|
5
|
+
|
6
|
+
public class PreferencesManager {
|
7
|
+
private static final String PREFS_NAME = "NCYAPIPrefs";
|
8
|
+
private static PreferencesManager instance;
|
9
|
+
private Context context;
|
10
|
+
|
11
|
+
private PreferencesManager(Context context) {
|
12
|
+
this.context = context.getApplicationContext();
|
13
|
+
}
|
14
|
+
|
15
|
+
public static PreferencesManager getInstance(Context context) {
|
16
|
+
if (instance == null) {
|
17
|
+
instance = new PreferencesManager(context);
|
18
|
+
}
|
19
|
+
return instance;
|
20
|
+
}
|
21
|
+
|
22
|
+
// 通用数据存储
|
23
|
+
public void setString(String key, String value) {
|
24
|
+
getSharedPreferences().edit().putString(key, value).apply();
|
25
|
+
}
|
26
|
+
|
27
|
+
public String getString(String key, String defaultValue) {
|
28
|
+
return getSharedPreferences().getString(key, defaultValue);
|
29
|
+
}
|
30
|
+
|
31
|
+
public void setBoolean(String key, boolean value) {
|
32
|
+
getSharedPreferences().edit().putBoolean(key, value).apply();
|
33
|
+
}
|
34
|
+
|
35
|
+
public boolean getBoolean(String key, boolean defaultValue) {
|
36
|
+
return getSharedPreferences().getBoolean(key, defaultValue);
|
37
|
+
}
|
38
|
+
|
39
|
+
public void setInt(String key, int value) {
|
40
|
+
getSharedPreferences().edit().putInt(key, value).apply();
|
41
|
+
}
|
42
|
+
|
43
|
+
public int getInt(String key, int defaultValue) {
|
44
|
+
return getSharedPreferences().getInt(key, defaultValue);
|
45
|
+
}
|
46
|
+
|
47
|
+
private SharedPreferences getSharedPreferences() {
|
48
|
+
return context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE);
|
49
|
+
}
|
50
|
+
}
|
@@ -0,0 +1,54 @@
|
|
1
|
+
package com.norcy.reactnativetoolkit;
|
2
|
+
|
3
|
+
import android.content.Context;
|
4
|
+
import com.facebook.react.BuildConfig;
|
5
|
+
import com.umeng.analytics.MobclickAgent;
|
6
|
+
import com.umeng.commonsdk.UMConfigure;
|
7
|
+
|
8
|
+
public class UMengManager {
|
9
|
+
private static final UMengManager instance = new UMengManager();
|
10
|
+
private String appKey;
|
11
|
+
private boolean isInitialized = false;
|
12
|
+
private Context context;
|
13
|
+
|
14
|
+
private UMengManager() {}
|
15
|
+
|
16
|
+
public static UMengManager getInstance() {
|
17
|
+
return instance;
|
18
|
+
}
|
19
|
+
|
20
|
+
// 唯一的外部调用方法 - 初始化
|
21
|
+
public void setup(Context context, String appKey) {
|
22
|
+
this.context = context;
|
23
|
+
this.appKey = appKey;
|
24
|
+
|
25
|
+
if (BuildConfig.DEBUG) {
|
26
|
+
UMConfigure.setLogEnabled(true);
|
27
|
+
} else {
|
28
|
+
if (appKey != null && !appKey.isEmpty()) {
|
29
|
+
UMConfigure.preInit(context, appKey, "Umeng");
|
30
|
+
// 检查用户是否已同意
|
31
|
+
if (PreferencesManager.getInstance(context).getBoolean("umeng_agreed", false)) {
|
32
|
+
init();
|
33
|
+
}
|
34
|
+
}
|
35
|
+
}
|
36
|
+
}
|
37
|
+
|
38
|
+
// 用户同意后调用 - 包含存储逻辑
|
39
|
+
public void onUserAgree() {
|
40
|
+
if (appKey != null && !appKey.isEmpty() && !isInitialized) {
|
41
|
+
// 存储用户同意状态
|
42
|
+
PreferencesManager.getInstance(context).setBoolean("umeng_agreed", true);
|
43
|
+
|
44
|
+
// 初始化友盟
|
45
|
+
init();
|
46
|
+
}
|
47
|
+
}
|
48
|
+
|
49
|
+
private void init() {
|
50
|
+
UMConfigure.init(context, appKey, "Umeng", UMConfigure.DEVICE_TYPE_PHONE, "");
|
51
|
+
MobclickAgent.setPageCollectionMode(MobclickAgent.PageMode.MANUAL);
|
52
|
+
isInitialized = true;
|
53
|
+
}
|
54
|
+
}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@norcy/react-native-toolkit",
|
3
|
-
"version": "0.1.
|
3
|
+
"version": "0.1.146",
|
4
4
|
"description": "My Toolkit",
|
5
5
|
"main": "lib/commonjs/index",
|
6
6
|
"module": "lib/module/index",
|
@@ -75,6 +75,7 @@
|
|
75
75
|
"react-native-device-info": "^10.0.2",
|
76
76
|
"react-native-purchases": "^7.28.1",
|
77
77
|
"react-native-simple-toast": "^1.1.3",
|
78
|
+
"react-native-splash-screen": "^3.3.0",
|
78
79
|
"react-native-wechat-lib": "^1.1.26",
|
79
80
|
"release-it": "^13.5.8",
|
80
81
|
"typescript": "^5.0.2"
|
@@ -97,6 +98,7 @@
|
|
97
98
|
"react-native-device-info": "*",
|
98
99
|
"react-native-purchases": "*",
|
99
100
|
"react-native-simple-toast": "*",
|
101
|
+
"react-native-splash-screen": "*",
|
100
102
|
"react-native-wechat-lib": "*"
|
101
103
|
},
|
102
104
|
"jest": {
|
package/yarn.lock
CHANGED
@@ -9304,6 +9304,11 @@ react-native-simple-toast@^1.1.3:
|
|
9304
9304
|
resolved "https://registry.yarnpkg.com/react-native-simple-toast/-/react-native-simple-toast-1.1.4.tgz#6a962beea87b86228a4f8c51bc93761108740b1c"
|
9305
9305
|
integrity sha512-7D8o8L445XDz7Rdh0pMgCIWuevv1FnGyuD7F8Nz/XhzMInmU4jL5VFJI25VVqQ2uGTaUSuo2ogXSgKnv6p9NJg==
|
9306
9306
|
|
9307
|
+
react-native-splash-screen@^3.3.0:
|
9308
|
+
version "3.3.0"
|
9309
|
+
resolved "https://registry.yarnpkg.com/react-native-splash-screen/-/react-native-splash-screen-3.3.0.tgz#3af71ed17afe50fee69590a45aec399d071ead02"
|
9310
|
+
integrity sha512-rGjt6HkoSXxMqH4SQUJ1gnPQlPJV8+J47+4yhgTIan4bVvAwJhEeJH7wWt9hXSdH4+VfwTS0GTaflj1Tw83IhA==
|
9311
|
+
|
9307
9312
|
react-native-wechat-lib@^1.1.26:
|
9308
9313
|
version "1.1.27"
|
9309
9314
|
resolved "https://registry.yarnpkg.com/react-native-wechat-lib/-/react-native-wechat-lib-1.1.27.tgz#22d8c74bd6099627978ffe898f0ee089e113c7e9"
|