react-native-beidou 1.1.3 → 1.1.6

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.
Files changed (55) hide show
  1. package/Compass.android.tsx +4 -12
  2. package/Compass.ios.tsx +2 -3
  3. package/android/build.gradle +22 -9
  4. package/android/src/main/AndroidManifest.xml +1 -0
  5. package/android/src/main/java/com/fxzs.rnbeidou/BeiDouBluetoothModule.java +528 -188
  6. package/android/src/main/java/com/fxzs.rnbeidou/BeiDouBluetoothPackage.java +10 -13
  7. package/android/src/main/java/com/fxzs.rnbeidou/BeidouAidlHelper.java +45 -13
  8. package/android/src/main/java/com/fxzs.rnbeidou/SuperSimModule.java +301 -0
  9. package/android/src/main/java/com/fxzs.rnbeidou/view/CompassManager.java +15 -15
  10. package/android/src/main/java/com/fxzs.rnbeidou/view/CompassView.java +10 -4
  11. package/index.ts +128 -228
  12. package/ios/BeiDouBluetoothModule.m +147 -20
  13. package/ios/BeidouBluetooth.framework/BeidouBluetooth +0 -0
  14. package/ios/BeidouBluetooth.framework/FMDB.bundle/Info.plist +0 -0
  15. package/ios/BeidouBluetooth.framework/Info.plist +0 -0
  16. package/ios/BeidouBluetooth.framework/_CodeSignature/CodeDirectory +0 -0
  17. package/ios/BeidouBluetooth.framework/_CodeSignature/CodeRequirements-1 +0 -0
  18. package/ios/BeidouBluetooth.framework/_CodeSignature/CodeResources +4 -4
  19. package/ios/BeidouBluetooth.framework/_CodeSignature/CodeSignature +0 -0
  20. package/ios/CompassView.h +1 -0
  21. package/ios/CompassView.m +3 -0
  22. package/ios/CompassViewComponentView.h +11 -0
  23. package/ios/CompassViewComponentView.mm +64 -0
  24. package/package.json +3 -5
  25. package/react-native-beidou.podspec +6 -3
  26. package/react-native.config.js +2 -5
  27. package/src/CompassViewNativeComponent.ts +13 -0
  28. package/src/NativeBeiDouBluetooth.ts +57 -0
  29. package/src/NativeSuperSim.ts +21 -0
  30. package/BeiDouAIDLTestPage.tsx +0 -1196
  31. package/LogManager.ts +0 -285
  32. package/TestPage.ts +0 -6
  33. package/android/.gradle/8.10/checksums/checksums.lock +0 -0
  34. package/android/.gradle/8.10/dependencies-accessors/gc.properties +0 -0
  35. package/android/.gradle/8.10/fileChanges/last-build.bin +0 -0
  36. package/android/.gradle/8.10/fileHashes/fileHashes.lock +0 -0
  37. package/android/.gradle/8.10/gc.properties +0 -0
  38. package/android/.gradle/8.9/checksums/checksums.lock +0 -0
  39. package/android/.gradle/8.9/dependencies-accessors/gc.properties +0 -0
  40. package/android/.gradle/8.9/fileChanges/last-build.bin +0 -0
  41. package/android/.gradle/8.9/fileHashes/fileHashes.lock +0 -0
  42. package/android/.gradle/8.9/gc.properties +0 -0
  43. package/android/.gradle/buildOutputCleanup/buildOutputCleanup.lock +0 -0
  44. package/android/.gradle/buildOutputCleanup/cache.properties +0 -2
  45. package/android/.gradle/config.properties +0 -2
  46. package/android/.gradle/vcs-1/gc.properties +0 -0
  47. package/android/.idea/AndroidProjectSystem.xml +0 -6
  48. package/android/.idea/caches/deviceStreaming.xml +0 -1138
  49. package/android/.idea/gradle.xml +0 -13
  50. package/android/.idea/migrations.xml +0 -10
  51. package/android/.idea/misc.xml +0 -9
  52. package/android/.idea/runConfigurations.xml +0 -17
  53. package/android/.idea/vcs.xml +0 -6
  54. package/android/local.properties +0 -8
  55. package/android/src/main/java/com/fxzs.rnbeidou/LogManager.java +0 -488
@@ -1,30 +1,27 @@
1
1
  package com.fxzs.rnbeidou;
2
2
 
3
- import androidx.annotation.NonNull;
4
-
5
- import com.fxzs.rnbeidou.view.CompassManager;
6
- import com.facebook.react.ReactPackage;
7
3
  import com.facebook.react.bridge.NativeModule;
8
4
  import com.facebook.react.bridge.ReactApplicationContext;
5
+ import com.facebook.react.ReactPackage;
9
6
  import com.facebook.react.uimanager.ViewManager;
10
-
7
+ import com.fxzs.rnbeidou.view.CompassManager;
11
8
  import java.util.Arrays;
12
- import java.util.Collections;
13
9
  import java.util.List;
14
10
 
15
11
  public class BeiDouBluetoothPackage implements ReactPackage {
16
- @NonNull
12
+
17
13
  @Override
18
- public List<NativeModule> createNativeModules(@NonNull ReactApplicationContext reactContext) {
19
- return Arrays.asList(
20
- new BeiDouBluetoothModule(reactContext));
14
+ public List<NativeModule> createNativeModules(ReactApplicationContext reactContext) {
15
+ return Arrays.<NativeModule>asList(
16
+ new BeiDouBluetoothModule(reactContext),
17
+ new SuperSimModule(reactContext)
18
+ );
21
19
  }
22
20
 
23
- @NonNull
24
21
  @Override
25
- public List<ViewManager> createViewManagers(@NonNull ReactApplicationContext reactContext) {
22
+ public List<ViewManager> createViewManagers(ReactApplicationContext reactContext) {
26
23
  return Arrays.<ViewManager>asList(
27
- new CompassManager(reactContext)
24
+ new CompassManager()
28
25
  );
29
26
  }
30
27
  }
@@ -29,7 +29,6 @@ import java.util.ArrayList;
29
29
  import java.util.List;
30
30
 
31
31
  public class BeidouAidlHelper {
32
-
33
32
  @Nullable
34
33
  private final ReactApplicationContext reactContext;
35
34
  @Nullable
@@ -73,17 +72,13 @@ public class BeidouAidlHelper {
73
72
  if (beidouService != null) {
74
73
  try {
75
74
  beidouService.setCallback(beidouServiceCallback);
76
- if (beidouServicePromise != null) {
77
- beidouServicePromise.resolve(true);
78
- beidouServicePromise = null;
79
- }
75
+ resolvePendingBindPromise(true);
80
76
  } catch (Exception e) {
81
77
  Log.e("BeiDouService", "设置北斗服务回调失败: " + e.getMessage(), e);
82
- if (beidouServicePromise != null) {
83
- beidouServicePromise.reject("BIND_ERROR", "绑定北斗服务失败: " + e.getMessage(), e);
84
- beidouServicePromise = null;
85
- }
78
+ rejectPendingBindPromise("BIND_ERROR", "绑定北斗服务失败: " + e.getMessage(), e);
86
79
  }
80
+ } else {
81
+ rejectPendingBindPromise("BIND_ERROR", "绑定北斗服务失败: service is null", null);
87
82
  }
88
83
  }
89
84
 
@@ -92,6 +87,7 @@ public class BeidouAidlHelper {
92
87
  beidouService = null;
93
88
  isBeidouServiceBound = false;
94
89
  Log.d("BeiDouService", "北斗服务连接断开");
90
+ rejectPendingBindPromise("SERVICE_DISCONNECTED", "北斗服务连接已断开", null);
95
91
  rejectAllPendingPromises("SERVICE_DISCONNECTED", "北斗服务连接已断开");
96
92
  }
97
93
  };
@@ -100,16 +96,30 @@ public class BeidouAidlHelper {
100
96
  this.reactContext = reactContext;
101
97
  }
102
98
  private Promise beidouServicePromise;
99
+
103
100
  public void bindService(String packageName, String actionName, Promise promise) {
104
101
  if (reactContext == null) {
105
102
  promise.reject("CONTEXT_NULL", "React上下文不可用");
106
103
  return;
107
104
  }
105
+ if (isBeidouServiceBound && beidouService != null) {
106
+ promise.resolve(true);
107
+ return;
108
+ }
108
109
  try {
110
+ if (beidouServicePromise != null) {
111
+ Promise old = beidouServicePromise;
112
+ beidouServicePromise = null;
113
+ old.reject("REQUEST_REPLACED", "存在未完成的绑定请求已被新的请求覆盖");
114
+ }
109
115
  beidouServicePromise = promise;
110
- bindBeidouService(packageName, actionName);
111
- // promise.resolve(true);
116
+ boolean bindRequested = bindBeidouService(packageName, actionName);
117
+ if (!bindRequested) {
118
+ rejectPendingBindPromise("BIND_ERROR", "绑定北斗服务失败: bindService returned false", null);
119
+ return;
120
+ }
112
121
  } catch (Exception e) {
122
+ beidouServicePromise = null;
113
123
  promise.reject("BIND_ERROR", "绑定北斗服务失败: " + e.getMessage(), e);
114
124
  }
115
125
  }
@@ -121,6 +131,7 @@ public class BeidouAidlHelper {
121
131
  }
122
132
 
123
133
  try {
134
+ rejectPendingBindPromise("SERVICE_UNBOUND", "北斗服务已解绑", null);
124
135
  unbindBeidouService();
125
136
  promise.resolve(true);
126
137
  } catch (Exception e) {
@@ -407,13 +418,15 @@ public class BeidouAidlHelper {
407
418
  }
408
419
  }
409
420
 
410
- private void bindBeidouService(String packageName, String actionName) {
421
+ private boolean bindBeidouService(String packageName, String actionName) {
411
422
  if (!isBeidouServiceBound && reactContext != null) {
412
423
  Intent intent = new Intent();
413
424
  intent.setComponent(new ComponentName(packageName, actionName));
414
425
  boolean result = reactContext.bindService(intent, beidouServiceConnection, Context.BIND_AUTO_CREATE);
415
426
  Log.d("BeiDouService", "绑定北斗服务结果: " + result + ", 包名: " + packageName + ", 类名: " + actionName);
427
+ return result;
416
428
  }
429
+ return true;
417
430
  }
418
431
 
419
432
  private void unbindBeidouService() {
@@ -624,6 +637,26 @@ public class BeidouAidlHelper {
624
637
  }
625
638
  }
626
639
 
640
+ private void resolvePendingBindPromise(boolean value) {
641
+ Promise pending = beidouServicePromise;
642
+ beidouServicePromise = null;
643
+ if (pending != null) {
644
+ pending.resolve(value);
645
+ }
646
+ }
647
+
648
+ private void rejectPendingBindPromise(String code, String message, @Nullable Throwable throwable) {
649
+ Promise pending = beidouServicePromise;
650
+ beidouServicePromise = null;
651
+ if (pending != null) {
652
+ if (throwable != null) {
653
+ pending.reject(code, message, throwable);
654
+ } else {
655
+ pending.reject(code, message);
656
+ }
657
+ }
658
+ }
659
+
627
660
  private void clearAuthPromise(Promise expected) {
628
661
  synchronized (authLock) {
629
662
  if (pendingAuthPromise == expected) {
@@ -648,4 +681,3 @@ public class BeidouAidlHelper {
648
681
  }
649
682
  }
650
683
  }
651
-
@@ -0,0 +1,301 @@
1
+ package com.fxzs.rnbeidou;
2
+
3
+ import android.os.Handler;
4
+ import android.os.Looper;
5
+
6
+ import androidx.annotation.NonNull;
7
+ import androidx.annotation.Nullable;
8
+
9
+ import com.beidou.bluetooth.supersim.SuperSimManager;
10
+ import com.cmcc.bdmsgsecure.model.BDMsgGetUserInfoTerminalResponse;
11
+ import com.cmcc.bdmsgsecure.model.BDMsgMailSynchronizeTerminalResponse;
12
+ import com.cmcc.bdmsgserver.bdmsgauth.model.BDMsgMailReplyResponse;
13
+ import com.cmcc.bdmsgserver.bdmsgauth.model.BDMsgSMCryptResponse;
14
+ import com.cmft.gba.sdk.core.bean.Result;
15
+ import com.facebook.react.bridge.Promise;
16
+ import com.facebook.react.bridge.ReactApplicationContext;
17
+ import com.facebook.react.bridge.ReactContextBaseJavaModule;
18
+ import com.facebook.react.bridge.ReactMethod;
19
+ import com.facebook.react.bridge.ReadableArray;
20
+ import com.facebook.react.bridge.WritableArray;
21
+ import com.facebook.react.bridge.WritableMap;
22
+ import com.facebook.react.bridge.WritableNativeArray;
23
+ import com.facebook.react.bridge.WritableNativeMap;
24
+
25
+ import java.util.LinkedList;
26
+ import java.util.List;
27
+ import java.util.Map;
28
+ import java.util.concurrent.Callable;
29
+ import java.util.concurrent.ExecutorService;
30
+ import java.util.concurrent.Executors;
31
+ import java.lang.reflect.Array;
32
+ import java.lang.reflect.Method;
33
+
34
+ public class SuperSimModule extends ReactContextBaseJavaModule {
35
+ public static final String NAME = "SuperSimModule";
36
+
37
+ private final ReactApplicationContext reactContext;
38
+ private final SuperSimManager superSimManager;
39
+ private final ExecutorService worker = Executors.newSingleThreadExecutor();
40
+ private final Handler mainHandler = new Handler(Looper.getMainLooper());
41
+
42
+ public SuperSimModule(ReactApplicationContext reactContext) {
43
+ super(reactContext);
44
+ this.reactContext = reactContext;
45
+ this.superSimManager = SuperSimManager.getInstance(reactContext);
46
+ }
47
+
48
+ @NonNull
49
+ @Override
50
+ public String getName() {
51
+ return NAME;
52
+ }
53
+
54
+ @ReactMethod
55
+ public void getSimType(double slotId, Promise promise) {
56
+ runOnWorker(() -> superSimManager.getSimType((int) slotId), promise);
57
+ }
58
+
59
+ @ReactMethod
60
+ public void getKsKeyAndAuthResult(double slotId, Promise promise) {
61
+ runOnWorker(() -> {
62
+ Result<String> result = superSimManager.getKsKeyAndAuthResult((int) slotId);
63
+ return objectToWritable(result, 3);
64
+ }, promise);
65
+ }
66
+
67
+ @ReactMethod
68
+ public void checkKeyIsExistAndValidate(double slotId, Promise promise) {
69
+ runOnWorker(() -> superSimManager.checkKeyIsExistAndValidate((int) slotId), promise);
70
+ }
71
+
72
+ @ReactMethod
73
+ public void commonMessageEncryptBDMsg(double slotId, @Nullable ReadableArray recipients, String message, Promise promise) {
74
+ runOnWorker(() -> {
75
+ LinkedList<String> list = readableArrayToStringList(recipients);
76
+ BDMsgSMCryptResponse resp = superSimManager.commonMessageEncryptBDMsg((int) slotId, list, message);
77
+ return objectToWritable(resp, 3);
78
+ }, promise);
79
+ }
80
+
81
+ @ReactMethod
82
+ public void positionReportEncryptBDMsg(double slotId, @Nullable ReadableArray recipients, String message, double longitude, double latitude, Promise promise) {
83
+ runOnWorker(() -> {
84
+ LinkedList<String> list = readableArrayToStringList(recipients);
85
+ BDMsgSMCryptResponse resp = superSimManager.positionReportEncryptBDMsg((int) slotId, list, message, longitude, latitude);
86
+ return objectToWritable(resp, 3);
87
+ }, promise);
88
+ }
89
+
90
+ @ReactMethod
91
+ public void mailboxQueryEncryptBDMsg(double slotId, Promise promise) {
92
+ runOnWorker(() -> {
93
+ BDMsgSMCryptResponse resp = superSimManager.mailboxQueryEncryptBDMsg((int) slotId);
94
+ return objectToWritable(resp, 3);
95
+ }, promise);
96
+ }
97
+
98
+ @ReactMethod
99
+ public void mailboxReplyDecryptBDMsg(double slotId, @Nullable ReadableArray data, double dataLength, Promise promise) {
100
+ runOnWorker(() -> {
101
+ byte[] bytes = readableArrayToByteArray(data);
102
+ BDMsgMailReplyResponse resp = superSimManager.mailboxReplyDecryptBDMsg((int) slotId, bytes, (int) dataLength);
103
+ return objectToWritable(resp, 3);
104
+ }, promise);
105
+ }
106
+
107
+ @ReactMethod
108
+ public void getCurrentUserInfo(double slotId, Promise promise) {
109
+ runOnWorker(() -> {
110
+ BDMsgGetUserInfoTerminalResponse resp = superSimManager.getCurrentUserInfo((int) slotId);
111
+ return objectToWritable(resp, 3);
112
+ }, promise);
113
+ }
114
+
115
+ @ReactMethod
116
+ public void mailboxSynchronizeDecryptBDMsg(double slotId, Promise promise) {
117
+ runOnWorker(() -> {
118
+ BDMsgMailSynchronizeTerminalResponse resp = superSimManager.mailboxSynchronizeDecryptBDMsg((int) slotId);
119
+ return objectToWritable(resp, 3);
120
+ }, promise);
121
+ }
122
+
123
+ private <T> void runOnWorker(Callable<T> task, Promise promise) {
124
+ worker.execute(() -> {
125
+ try {
126
+ T result = task.call();
127
+ mainHandler.post(() -> promise.resolve(result));
128
+ } catch (Exception e) {
129
+ mainHandler.post(() -> promise.reject("SUPER_SIM_ERROR", e.getMessage(), e));
130
+ }
131
+ });
132
+ }
133
+
134
+ private LinkedList<String> readableArrayToStringList(@Nullable ReadableArray readableArray) {
135
+ LinkedList<String> list = new LinkedList<>();
136
+ if (readableArray == null) {
137
+ return list;
138
+ }
139
+ for (int i = 0; i < readableArray.size(); i++) {
140
+ list.add(readableArray.getString(i));
141
+ }
142
+ return list;
143
+ }
144
+
145
+ private byte[] readableArrayToByteArray(@Nullable ReadableArray readableArray) {
146
+ if (readableArray == null) {
147
+ return new byte[0];
148
+ }
149
+ byte[] bytes = new byte[readableArray.size()];
150
+ for (int i = 0; i < readableArray.size(); i++) {
151
+ bytes[i] = (byte) readableArray.getInt(i);
152
+ }
153
+ return bytes;
154
+ }
155
+
156
+ private Object objectToWritable(@Nullable Object value, int depth) {
157
+ if (value == null) {
158
+ return null;
159
+ }
160
+ if (depth <= 0) {
161
+ return String.valueOf(value);
162
+ }
163
+ if (value instanceof String || value instanceof Number || value instanceof Boolean) {
164
+ return value;
165
+ }
166
+ if (value instanceof byte[]) {
167
+ return byteArrayToWritableArray((byte[]) value);
168
+ }
169
+ if (value.getClass().isArray()) {
170
+ return arrayToWritableArray(value, depth - 1);
171
+ }
172
+ if (value instanceof List) {
173
+ return listToWritableArray((List<?>) value, depth - 1);
174
+ }
175
+ if (value instanceof Map) {
176
+ return mapToWritableMap((Map<?, ?>) value, depth - 1);
177
+ }
178
+ return objectToWritableMapByGetters(value, depth - 1);
179
+ }
180
+
181
+ private WritableArray byteArrayToWritableArray(byte[] bytes) {
182
+ WritableArray array = new WritableNativeArray();
183
+ for (byte b : bytes) {
184
+ array.pushInt(b & 0xFF);
185
+ }
186
+ return array;
187
+ }
188
+
189
+ private WritableArray arrayToWritableArray(Object arrayObj, int depth) {
190
+ int length = Array.getLength(arrayObj);
191
+ WritableArray array = new WritableNativeArray();
192
+ for (int i = 0; i < length; i++) {
193
+ Object item = Array.get(arrayObj, i);
194
+ Object converted = objectToWritable(item, depth);
195
+ pushToArray(array, converted);
196
+ }
197
+ return array;
198
+ }
199
+
200
+ private WritableArray listToWritableArray(List<?> list, int depth) {
201
+ WritableArray array = new WritableNativeArray();
202
+ for (Object item : list) {
203
+ Object converted = objectToWritable(item, depth);
204
+ pushToArray(array, converted);
205
+ }
206
+ return array;
207
+ }
208
+
209
+ private WritableMap mapToWritableMap(Map<?, ?> map, int depth) {
210
+ WritableMap result = new WritableNativeMap();
211
+ for (Map.Entry<?, ?> entry : map.entrySet()) {
212
+ String key = String.valueOf(entry.getKey());
213
+ Object converted = objectToWritable(entry.getValue(), depth);
214
+ putToMap(result, key, converted);
215
+ }
216
+ return result;
217
+ }
218
+
219
+ private WritableMap objectToWritableMapByGetters(Object obj, int depth) {
220
+ WritableMap map = new WritableNativeMap();
221
+ Method[] methods = obj.getClass().getMethods();
222
+ for (Method method : methods) {
223
+ String name = method.getName();
224
+ if (method.getParameterTypes().length != 0) {
225
+ continue;
226
+ }
227
+ if ("getClass".equals(name)) {
228
+ continue;
229
+ }
230
+ if (name.startsWith("get") && name.length() > 3) {
231
+ String key = Character.toLowerCase(name.charAt(3)) + name.substring(4);
232
+ try {
233
+ Object value = method.invoke(obj);
234
+ Object converted = objectToWritable(value, depth);
235
+ putToMap(map, key, converted);
236
+ } catch (Exception ignore) {
237
+ }
238
+ } else if (name.startsWith("is") && name.length() > 2) {
239
+ String key = Character.toLowerCase(name.charAt(2)) + name.substring(3);
240
+ try {
241
+ Object value = method.invoke(obj);
242
+ Object converted = objectToWritable(value, depth);
243
+ putToMap(map, key, converted);
244
+ } catch (Exception ignore) {
245
+ }
246
+ }
247
+ }
248
+ if (map.toString().equals("{}")) {
249
+ map.putString("value", String.valueOf(obj));
250
+ }
251
+ return map;
252
+ }
253
+
254
+ private void putToMap(WritableMap map, String key, Object value) {
255
+ if (value == null) {
256
+ map.putNull(key);
257
+ } else if (value instanceof String) {
258
+ map.putString(key, (String) value);
259
+ } else if (value instanceof Integer) {
260
+ map.putInt(key, (Integer) value);
261
+ } else if (value instanceof Double) {
262
+ map.putDouble(key, (Double) value);
263
+ } else if (value instanceof Float) {
264
+ map.putDouble(key, ((Float) value).doubleValue());
265
+ } else if (value instanceof Long) {
266
+ map.putDouble(key, ((Long) value).doubleValue());
267
+ } else if (value instanceof Boolean) {
268
+ map.putBoolean(key, (Boolean) value);
269
+ } else if (value instanceof WritableMap) {
270
+ map.putMap(key, (WritableMap) value);
271
+ } else if (value instanceof WritableArray) {
272
+ map.putArray(key, (WritableArray) value);
273
+ } else {
274
+ map.putString(key, String.valueOf(value));
275
+ }
276
+ }
277
+
278
+ private void pushToArray(WritableArray array, Object value) {
279
+ if (value == null) {
280
+ array.pushNull();
281
+ } else if (value instanceof String) {
282
+ array.pushString((String) value);
283
+ } else if (value instanceof Integer) {
284
+ array.pushInt((Integer) value);
285
+ } else if (value instanceof Double) {
286
+ array.pushDouble((Double) value);
287
+ } else if (value instanceof Float) {
288
+ array.pushDouble(((Float) value).doubleValue());
289
+ } else if (value instanceof Long) {
290
+ array.pushDouble(((Long) value).doubleValue());
291
+ } else if (value instanceof Boolean) {
292
+ array.pushBoolean((Boolean) value);
293
+ } else if (value instanceof WritableMap) {
294
+ array.pushMap((WritableMap) value);
295
+ } else if (value instanceof WritableArray) {
296
+ array.pushArray((WritableArray) value);
297
+ } else {
298
+ array.pushString(String.valueOf(value));
299
+ }
300
+ }
301
+ }
@@ -1,23 +1,15 @@
1
1
  package com.fxzs.rnbeidou.view;
2
2
 
3
- import android.view.View;
4
-
5
3
  import androidx.annotation.NonNull;
6
4
 
7
- import com.facebook.react.bridge.ReactApplicationContext;
8
- import com.facebook.react.bridge.ReactContext;
5
+ import com.facebook.react.common.MapBuilder;
9
6
  import com.facebook.react.uimanager.SimpleViewManager;
10
7
  import com.facebook.react.uimanager.ThemedReactContext;
11
- import com.facebook.react.uimanager.annotations.ReactProp;
12
- import com.facebook.react.modules.core.DeviceEventManagerModule;
8
+ import java.util.Map;
13
9
 
14
10
  public class CompassManager extends SimpleViewManager<CompassView> {
15
11
  public static final String REACT_CLASS = "CompassView";
16
12
 
17
- private CompassView compassView;
18
-
19
- public CompassManager(ReactApplicationContext reactContext) {}
20
-
21
13
  @NonNull
22
14
  @Override
23
15
  public String getName() {
@@ -27,15 +19,23 @@ public class CompassManager extends SimpleViewManager<CompassView> {
27
19
  @NonNull
28
20
  @Override
29
21
  protected CompassView createViewInstance(@NonNull ThemedReactContext reactContext) {
30
- compassView = new CompassView(reactContext, null);
31
- return compassView;
22
+ return new CompassView(reactContext, null);
23
+ }
24
+
25
+ @Override
26
+ public Map<String, Object> getExportedCustomBubblingEventTypeConstants() {
27
+ return MapBuilder.of(
28
+ "onHeadingChange",
29
+ MapBuilder.of(
30
+ "phasedRegistrationNames",
31
+ MapBuilder.of("bubbled", "onHeadingChange")
32
+ )
33
+ );
32
34
  }
33
35
 
34
36
  @Override
35
37
  public void onDropViewInstance(@NonNull CompassView view) {
36
38
  super.onDropViewInstance(view);
37
- if (compassView != null) {
38
- compassView.stop();
39
- }
39
+ view.stop();
40
40
  }
41
41
  }
@@ -14,8 +14,10 @@ import android.util.Log;
14
14
  import android.view.HapticFeedbackConstants;
15
15
  import android.view.View;
16
16
 
17
+ import com.facebook.react.bridge.Arguments;
17
18
  import com.facebook.react.bridge.ReactContext;
18
- import com.facebook.react.modules.core.DeviceEventManagerModule;
19
+ import com.facebook.react.bridge.WritableMap;
20
+ import com.facebook.react.uimanager.events.RCTEventEmitter;
19
21
 
20
22
  public class CompassView extends View implements SensorEventListener {
21
23
  private static final String TAG = "OptimizedCompassView";
@@ -244,9 +246,13 @@ public class CompassView extends View implements SensorEventListener {
244
246
 
245
247
  private void sendDirectionUpdate(float azimuth) {
246
248
  if (getContext() instanceof ReactContext) {
247
- ((ReactContext) getContext())
248
- .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
249
- .emit("onCompassUpdate", azimuth);
249
+ ReactContext reactContext = (ReactContext) getContext();
250
+ WritableMap event = Arguments.createMap();
251
+ event.putDouble("degrees", azimuth);
252
+ event.putDouble("radians", -Math.toRadians(azimuth));
253
+ reactContext
254
+ .getJSModule(RCTEventEmitter.class)
255
+ .receiveEvent(getId(), "onHeadingChange", event);
250
256
  }
251
257
  }
252
258
  public void start() {