@norcy/react-native-toolkit 0.1.112 → 0.1.113

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.
@@ -2,7 +2,7 @@ import { Object } from 'leancloud-storage';
2
2
  import { Platform } from 'react-native';
3
3
  import { getReadableVersion } from 'react-native-device-info';
4
4
  import { DevConfig } from './DevConfig';
5
- import { LoginResultDataType } from './LoginManager';
5
+ import { LoginManager, LoginResultDataType } from './LoginManager';
6
6
  import { Notification } from './Notification';
7
7
  import { BuildInPrefs } from './PrefData';
8
8
  import { VipAndroidManager } from './VipAndroidManager';
@@ -85,9 +85,8 @@ const handleVersionInfo = () => {
85
85
 
86
86
  let isDataReady = false;
87
87
  let isNetwordDataReady = false;
88
- let OnlineItems: Object[] = [];
89
88
 
90
- const _handleResponse = () => {
89
+ const _handleResponse = (OnlineItems: Object[]) => {
91
90
  if (!isNetwordDataReady) {
92
91
  return;
93
92
  }
@@ -103,6 +102,7 @@ const _handleResponse = () => {
103
102
  ConfigDataModel.emitChange();
104
103
  };
105
104
 
105
+ // ConfigDataModel 的 Config 是支持后台配置多条同一个 Key 的,按版本区分
106
106
  const ConfigDataModel = {
107
107
  init: (defaultValues: ConfigsType) => {
108
108
  MyItems = defaultValues;
@@ -113,7 +113,6 @@ const ConfigDataModel = {
113
113
  if (!isAuto && user && !error) {
114
114
  isDataReady = false;
115
115
  isNetwordDataReady = false;
116
- OnlineItems = [];
117
116
  ConfigDataModel.fetch();
118
117
  }
119
118
  }
@@ -135,8 +134,7 @@ const ConfigDataModel = {
135
134
  .then((items: Object[]) => {
136
135
  console.log('Config 抓取完毕');
137
136
  isNetwordDataReady = true;
138
- OnlineItems = items;
139
- _handleResponse();
137
+ _handleResponse(items);
140
138
  })
141
139
  .catch((e: any) => {
142
140
  console.error(e);
@@ -170,6 +168,21 @@ const ConfigDataModel = {
170
168
  }
171
169
  eventEmitter.on('change', callback);
172
170
  },
171
+
172
+ shouldEnableByRate: (enable?: boolean, rate?: number) => {
173
+ if (!enable) {
174
+ return false;
175
+ }
176
+ // rate 不传,默认为全量
177
+ const r = rate ?? 1;
178
+ if (r <= 0) {
179
+ return false;
180
+ }
181
+ // ID 最后一位是 16 进制(0-f),未登录默认为全量
182
+ const lastChar =
183
+ LoginManager.currentUser()?.AVUser?.get('objectId')?.slice(-1) ?? '0';
184
+ return '0123456789abcdef'.indexOf(lastChar.toLowerCase()) < r * 16;
185
+ },
173
186
  };
174
187
 
175
188
  export { ConfigDataModel };
package/src/Tool.ts CHANGED
@@ -73,7 +73,7 @@ const _jsonify = (target: any): any => {
73
73
  return target;
74
74
  };
75
75
 
76
- const _getAlertDataFromConfig = (config: AlertConfig) => {
76
+ const _getAlertDataFromConfig = (config?: AlertConfig) => {
77
77
  if (!config) {
78
78
  return undefined;
79
79
  }
@@ -220,10 +220,12 @@ export const Tool = {
220
220
  },
221
221
 
222
222
  showToast: (toast: string) => {
223
- Toast.showWithGravity(toast, Toast.SHORT, Toast.CENTER);
223
+ if (toast) {
224
+ Toast.showWithGravity(toast, Toast.SHORT, Toast.CENTER);
225
+ }
224
226
  },
225
227
 
226
- alertWithConfig: (config: AlertConfig) => {
228
+ alertWithConfig: (config?: AlertConfig) => {
227
229
  const alertData = _getAlertDataFromConfig(config);
228
230
  if (alertData) {
229
231
  Alert.alert(alertData.title, alertData.message, alertData.buttons);
@@ -1,9 +0,0 @@
1
- {
2
- "editor.formatOnSave": true,
3
- "editor.codeActionsOnSave": {
4
- "source.organizeImports": "explicit"
5
- },
6
- "prettier.tabWidth": 4,
7
- "prettier.jsxBracketSameLine": true,
8
- "editor.tabSize": 2
9
- }
@@ -1,4 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <Workspace
3
- version = "1.0">
4
- </Workspace>