Przeglądaj źródła

[RN] Drop react-native-locale-detector dependency

The upstream package has been unmaintained for 2 years now, and making the litle
changes needed as React Native needs them is getting old. The actual
funcionality is a couple of one-liners plus tons of boliterplate, which gets
reduced by quite a bit if we just embed it. So here it goes.
j8
Saúl Ibarra Corretgé 6 lat temu
rodzic
commit
26ba974757

+ 0
- 1
android/sdk/build.gradle Wyświetl plik

@@ -40,7 +40,6 @@ dependencies {
40 40
     implementation project(':react-native-immersive')
41 41
     implementation project(':react-native-keep-awake')
42 42
     implementation project(':react-native-linear-gradient')
43
-    implementation project(':react-native-locale-detector')
44 43
     implementation project(':react-native-sound')
45 44
     implementation project(':react-native-vector-icons')
46 45
     implementation project(':react-native-webrtc')

+ 58
- 0
android/sdk/src/main/java/org/jitsi/meet/sdk/LocaleDetector.java Wyświetl plik

@@ -0,0 +1,58 @@
1
+/*
2
+ * Copyright @ 2018-present 8x8, Inc.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ *     http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+/*
18
+ * Based on https://github.com/DylanVann/react-native-locale-detector
19
+ */
20
+
21
+package org.jitsi.meet.sdk;
22
+
23
+import android.content.Context;
24
+
25
+import com.facebook.react.bridge.ReactApplicationContext;
26
+import com.facebook.react.bridge.ReactContextBaseJavaModule;
27
+
28
+import java.util.HashMap;
29
+import java.util.Map;
30
+
31
+/**
32
+ * Module which provides information about the system locale.
33
+ */
34
+class LocaleDetector extends ReactContextBaseJavaModule {
35
+
36
+    public LocaleDetector(ReactApplicationContext reactContext) {
37
+        super(reactContext);
38
+    }
39
+
40
+    /**
41
+     * Gets a {@code Map} of constants this module exports to JS. Supports JSON
42
+     * types.
43
+     *
44
+     * @return a {@link Map} of constants this module exports to JS
45
+     */
46
+    @Override
47
+    public Map<String, Object> getConstants() {
48
+        Context context = getReactApplicationContext();
49
+        HashMap<String,Object> constants = new HashMap<>();
50
+        constants.put("locale", context.getResources().getConfiguration().locale.toString());
51
+        return constants;
52
+    }
53
+
54
+    @Override
55
+    public String getName() {
56
+        return "LocaleDetector";
57
+    }
58
+}

+ 1
- 1
android/sdk/src/main/java/org/jitsi/meet/sdk/ReactInstanceManagerHolder.java Wyświetl plik

@@ -42,6 +42,7 @@ class ReactInstanceManagerHolder {
42 42
             new AppInfoModule(reactContext),
43 43
             new AudioModeModule(reactContext),
44 44
             new ExternalAPIModule(reactContext),
45
+            new LocaleDetector(reactContext),
45 46
             new PictureInPictureModule(reactContext),
46 47
             new ProximityModule(reactContext),
47 48
             new WiFiStatsModule(reactContext),
@@ -126,7 +127,6 @@ class ReactInstanceManagerHolder {
126 127
                 .addPackage(new com.corbt.keepawake.KCKeepAwakePackage())
127 128
                 .addPackage(new com.dylanvann.fastimage.FastImageViewPackage())
128 129
                 .addPackage(new com.facebook.react.shell.MainReactPackage())
129
-                .addPackage(new com.i18n.reactnativei18n.ReactNativeI18n())
130 130
                 .addPackage(new com.oblador.vectoricons.VectorIconsPackage())
131 131
                 .addPackage(new com.ocetnik.timer.BackgroundTimerPackage())
132 132
                 .addPackage(new com.oney.WebRTCModule.WebRTCModulePackage())

+ 0
- 2
android/settings.gradle Wyświetl plik

@@ -13,8 +13,6 @@ include ':react-native-keep-awake'
13 13
 project(':react-native-keep-awake').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-keep-awake/android')
14 14
 include ':react-native-linear-gradient'
15 15
 project(':react-native-linear-gradient').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-linear-gradient/android')
16
-include ':react-native-locale-detector'
17
-project(':react-native-locale-detector').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-locale-detector/android')
18 16
 include ':react-native-sound'
19 17
 project(':react-native-sound').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-sound/android')
20 18
 include ':react-native-vector-icons'

+ 0
- 2
ios/Podfile Wyświetl plik

@@ -34,8 +34,6 @@ target 'JitsiMeet' do
34 34
     :path => '../node_modules/react-native-fast-image'
35 35
   pod 'react-native-keep-awake',
36 36
     :path => '../node_modules/react-native-keep-awake'
37
-  pod 'react-native-locale-detector',
38
-    :path => '../node_modules/react-native-locale-detector'
39 37
   pod 'react-native-webrtc', :path => '../node_modules/react-native-webrtc'
40 38
   pod 'RNGoogleSignin',
41 39
     :path => '../node_modules/react-native-google-signin'

+ 1
- 7
ios/Podfile.lock Wyświetl plik

@@ -41,8 +41,6 @@ PODS:
41 41
     - SDWebImage/GIF
42 42
   - react-native-keep-awake (2.0.6):
43 43
     - React
44
-  - react-native-locale-detector (1.0.0):
45
-    - React
46 44
   - react-native-webrtc (1.67.1):
47 45
     - React
48 46
   - React/Core (0.57.6):
@@ -109,7 +107,6 @@ DEPENDENCIES:
109 107
   - react-native-calendar-events (from `../node_modules/react-native-calendar-events`)
110 108
   - react-native-fast-image (from `../node_modules/react-native-fast-image`)
111 109
   - react-native-keep-awake (from `../node_modules/react-native-keep-awake`)
112
-  - react-native-locale-detector (from `../node_modules/react-native-locale-detector`)
113 110
   - react-native-webrtc (from `../node_modules/react-native-webrtc`)
114 111
   - React/Core (from `../node_modules/react-native`)
115 112
   - React/CxxBridge (from `../node_modules/react-native`)
@@ -154,8 +151,6 @@ EXTERNAL SOURCES:
154 151
     :path: "../node_modules/react-native-fast-image"
155 152
   react-native-keep-awake:
156 153
     :path: "../node_modules/react-native-keep-awake"
157
-  react-native-locale-detector:
158
-    :path: "../node_modules/react-native-locale-detector"
159 154
   react-native-webrtc:
160 155
     :path: "../node_modules/react-native-webrtc"
161 156
   RNGoogleSignin:
@@ -183,7 +178,6 @@ SPEC CHECKSUMS:
183 178
   react-native-calendar-events: fe6fbc8ed337a7423c98f2c9012b25f20444de09
184 179
   react-native-fast-image: cba3d9bf9c2cf8ddb643d887a686c53a5dd90a2c
185 180
   react-native-keep-awake: 0de4bd66de0c23178107dce0c2fcc3354b2a8e94
186
-  react-native-locale-detector: d1b2c6fe5abb56e3a1efb6c2d6f308c05c4251f1
187 181
   react-native-webrtc: 31b6d3f1e3e2ce373aa43fd682b04367250f807d
188 182
   RNGoogleSignin: 44debd8c359a662c0e2d585952e88b985bf78008
189 183
   RNSound: b360b3862d3118ed1c74bb9825696b5957686ac4
@@ -191,6 +185,6 @@ SPEC CHECKSUMS:
191 185
   SDWebImage: 624d6e296c69b244bcede364c72ae0430ac14681
192 186
   yoga: b1ce48b6cf950b98deae82838f5173ea7cf89e85
193 187
 
194
-PODFILE CHECKSUM: cf8276ba4b0933b24c6082a25a5f4eabe0ba4ea6
188
+PODFILE CHECKSUM: 9b67ed66d62ca004caa7952c3bbfe2693c115333
195 189
 
196 190
 COCOAPODS: 1.5.3

+ 4
- 0
ios/sdk/sdk.xcodeproj/project.pbxproj Wyświetl plik

@@ -49,6 +49,7 @@
49 49
 		C6A34261204EF76800E062DD /* DragGestureController.swift in Sources */ = {isa = PBXBuildFile; fileRef = C6A3425E204EF76800E062DD /* DragGestureController.swift */; };
50 50
 		C6CC49AF207412CF000DFA42 /* PiPViewCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = C6CC49AE207412CF000DFA42 /* PiPViewCoordinator.swift */; };
51 51
 		C6F99C15204DB63E0001F710 /* JitsiMeetView+Private.h in Headers */ = {isa = PBXBuildFile; fileRef = C6F99C13204DB63D0001F710 /* JitsiMeetView+Private.h */; };
52
+		DEFC743F21B178FA00E4DD96 /* LocaleDetector.m in Sources */ = {isa = PBXBuildFile; fileRef = DEFC743D21B178FA00E4DD96 /* LocaleDetector.m */; };
52 53
 /* End PBXBuildFile section */
53 54
 
54 55
 /* Begin PBXFileReference section */
@@ -104,6 +105,7 @@
104 105
 		C6A3425E204EF76800E062DD /* DragGestureController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DragGestureController.swift; sourceTree = "<group>"; };
105 106
 		C6CC49AE207412CF000DFA42 /* PiPViewCoordinator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PiPViewCoordinator.swift; sourceTree = "<group>"; };
106 107
 		C6F99C13204DB63D0001F710 /* JitsiMeetView+Private.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "JitsiMeetView+Private.h"; sourceTree = "<group>"; };
108
+		DEFC743D21B178FA00E4DD96 /* LocaleDetector.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = LocaleDetector.m; sourceTree = "<group>"; };
107 109
 /* End PBXFileReference section */
108 110
 
109 111
 /* Begin PBXFrameworksBuildPhase section */
@@ -173,6 +175,7 @@
173 175
 				C6F99C13204DB63D0001F710 /* JitsiMeetView+Private.h */,
174 176
 				0B412F1B1EDEC80100B1A0A6 /* JitsiMeetViewDelegate.h */,
175 177
 				0B7C2CFC200F51D60060D076 /* LaunchOptions.m */,
178
+				DEFC743D21B178FA00E4DD96 /* LocaleDetector.m */,
176 179
 				0B44A0181F902126009D1D64 /* MPVolumeViewManager.m */,
177 180
 				C6A3426B204F127900E062DD /* picture-in-picture */,
178 181
 				0BCA495D1EC4B6C600B793EE /* POSIX.m */,
@@ -465,6 +468,7 @@
465 468
 				0B7C2CFD200F51D60060D076 /* LaunchOptions.m in Sources */,
466 469
 				C6CC49AF207412CF000DFA42 /* PiPViewCoordinator.swift in Sources */,
467 470
 				B386B85720981A75000DEF7A /* InviteController.m in Sources */,
471
+				DEFC743F21B178FA00E4DD96 /* LocaleDetector.m in Sources */,
468 472
 				B386B85820981A75000DEF7A /* AddPeopleController.m in Sources */,
469 473
 				0BCA495F1EC4B6C600B793EE /* AudioMode.m in Sources */,
470 474
 				0B44A0191F902126009D1D64 /* MPVolumeViewManager.m in Sources */,

+ 40
- 0
ios/sdk/src/LocaleDetector.m Wyświetl plik

@@ -0,0 +1,40 @@
1
+/*
2
+ * Copyright @ 2018-present 8x8, Inc.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ *     http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+/*
18
+ * Based on https://github.com/DylanVann/react-native-locale-detector
19
+ */
20
+
21
+#import <Foundation/Foundation.h>
22
+
23
+#import <React/RCTBridgeModule.h>
24
+
25
+@interface LocaleDetector : NSObject <RCTBridgeModule>
26
+@end
27
+
28
+@implementation LocaleDetector
29
+
30
+RCT_EXPORT_MODULE();
31
+
32
++ (BOOL)requiresMainQueueSetup {
33
+    return NO;
34
+}
35
+
36
+- (NSDictionary *)constantsToExport {
37
+    return @{ @"locale": [[NSLocale preferredLanguages] objectAtIndex:0] };
38
+}
39
+
40
+@end

+ 0
- 4
package-lock.json Wyświetl plik

@@ -11225,10 +11225,6 @@
11225 11225
         "prop-types": "^15.5.10"
11226 11226
       }
11227 11227
     },
11228
-    "react-native-locale-detector": {
11229
-      "version": "github:jitsi/react-native-locale-detector#845281e9fd4af756f6d0f64afe5cce08c63e5ee9",
11230
-      "from": "github:jitsi/react-native-locale-detector#845281e9fd4af756f6d0f64afe5cce08c63e5ee9"
11231
-    },
11232 11228
     "react-native-prompt": {
11233 11229
       "version": "1.0.0",
11234 11230
       "resolved": "https://registry.npmjs.org/react-native-prompt/-/react-native-prompt-1.0.0.tgz",

+ 0
- 1
package.json Wyświetl plik

@@ -69,7 +69,6 @@
69 69
     "react-native-immersive": "1.1.0",
70 70
     "react-native-keep-awake": "2.0.6",
71 71
     "react-native-linear-gradient": "2.4.0",
72
-    "react-native-locale-detector": "github:jitsi/react-native-locale-detector#845281e9fd4af756f6d0f64afe5cce08c63e5ee9",
73 72
     "react-native-prompt": "1.0.0",
74 73
     "react-native-sound": "0.10.9",
75 74
     "react-native-swipeout": "2.3.6",

+ 5
- 3
react/features/base/i18n/languageDetector.native.js Wyświetl plik

@@ -1,6 +1,6 @@
1
-/* @flow */
1
+// @flow
2 2
 
3
-import locale from 'react-native-locale-detector';
3
+import { NativeModules } from 'react-native';
4 4
 
5 5
 /**
6 6
  * The singleton language detector for React Native which uses the system-wide
@@ -15,7 +15,9 @@ export default {
15 15
     cacheUserLanguage: Function.prototype,
16 16
 
17 17
     detect() {
18
-        return locale;
18
+        const { LocaleDetector } = NativeModules;
19
+
20
+        return LocaleDetector.locale.replace(/_/, '-');
19 21
     },
20 22
 
21 23
     init: Function.prototype,

Ładowanie…
Anuluj
Zapisz