|
12 | 12 |
|
13 | 13 | import com.facebook.react.ReactDelegate; |
14 | 14 | import com.facebook.react.ReactHost; |
15 | | -import com.facebook.react.ReactInstanceManager; |
16 | 15 | import com.facebook.react.ReactActivity; |
17 | 16 | import com.facebook.react.ReactRootView; |
18 | 17 | import com.facebook.react.bridge.Arguments; |
@@ -140,9 +139,16 @@ private void setJSBundle(String latestJSBundleFile) throws IllegalAccessExceptio |
140 | 139 |
|
141 | 140 | @OptIn(markerClass = UnstableReactNativeAPI.class) |
142 | 141 | private void setJSBundleLoaderBridgeless(ReactHost reactHost, JSBundleLoader latestJSBundleLoader) throws NoSuchFieldException, IllegalAccessException { |
143 | | - Field mReactHostDelegateField = reactHost.getClass().getDeclaredField("mReactHostDelegate"); |
144 | | - mReactHostDelegateField.setAccessible(true); |
145 | | - ReactHostDelegate reactHostDelegate = (ReactHostDelegate) mReactHostDelegateField.get(reactHost); |
| 142 | + Field reactHostDelegateField; |
| 143 | + try { |
| 144 | + // RN < 0.81 |
| 145 | + reactHostDelegateField = reactHost.getClass().getDeclaredField("mReactHostDelegate"); |
| 146 | + } catch (NoSuchFieldException e) { |
| 147 | + // RN >= 0.81 |
| 148 | + reactHostDelegateField = reactHost.getClass().getDeclaredField("reactHostDelegate"); |
| 149 | + } |
| 150 | + reactHostDelegateField.setAccessible(true); |
| 151 | + ReactHostDelegate reactHostDelegate = (ReactHostDelegate) reactHostDelegateField.get(reactHost); |
146 | 152 | assert reactHostDelegate != null; |
147 | 153 | Field jsBundleLoaderField = reactHostDelegate.getClass().getDeclaredField("jsBundleLoader"); |
148 | 154 | jsBundleLoaderField.setAccessible(true); |
@@ -220,7 +226,14 @@ private ReactHost resolveReactHost() { |
220 | 226 | } |
221 | 227 |
|
222 | 228 | try { |
223 | | - Field reactHostField = reactDelegate.getClass().getDeclaredField("mReactHost"); |
| 229 | + Field reactHostField; |
| 230 | + try { |
| 231 | + // RN < 0.81 |
| 232 | + reactHostField = reactDelegate.getClass().getDeclaredField("mReactHost"); |
| 233 | + } catch (NoSuchFieldException e) { |
| 234 | + // RN >= 0.81 |
| 235 | + reactHostField = reactDelegate.getClass().getDeclaredField("reactHost"); |
| 236 | + } |
224 | 237 | reactHostField.setAccessible(true); |
225 | 238 | return (ReactHost) reactHostField.get(reactDelegate); |
226 | 239 | } catch (Exception e) { |
|
0 commit comments