-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: use proper classes for bridgeless (#5997)
## Summary Thanks to @lukmccall we discovered that on bridgeless mode invoking `getReactInstanceManager` creates another instance of application. This PR makes it behave correctly there. ## Test plan Run application and see that without this code, on bridgeless, there is no additional button in dev menu since it is created and the button is added in another instance.
- Loading branch information
Showing
4 changed files
with
61 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
android/src/reactNativeVersionPatch/ReactHost/72/com/swmansion/reanimated/DevMenuUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.swmansion.reanimated; | ||
|
||
public class DevMenuUtils { | ||
|
||
private void addDevMenuOption(ReactApplicationContext context, DevOptionHandler handler) { | ||
// In Expo, `ApplicationContext` is not an instance of `ReactApplication` | ||
if (context.getApplicationContext() instanceof ReactApplication) { | ||
final DevSupportManager devSupportManager = | ||
((ReactApplication) context.getApplicationContext()) | ||
.getReactNativeHost() | ||
.getReactInstanceManager() | ||
.getDevSupportManager(); | ||
|
||
devSupportManager.addCustomDevOption( | ||
"Toggle slow animations (Reanimated)", handler); | ||
} | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
...d/src/reactNativeVersionPatch/ReactHost/latest/com/swmansion/reanimated/DevMenuUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package com.swmansion.reanimated; | ||
|
||
import com.facebook.react.ReactApplication; | ||
import com.facebook.react.bridge.ReactApplicationContext; | ||
import com.facebook.react.devsupport.interfaces.DevOptionHandler; | ||
import com.facebook.react.devsupport.interfaces.DevSupportManager; | ||
|
||
public class DevMenuUtils { | ||
|
||
public static void addDevMenuOption(ReactApplicationContext context, DevOptionHandler handler) { | ||
// In Expo, `ApplicationContext` is not an instance of `ReactApplication` | ||
if (context.getApplicationContext() instanceof ReactApplication) { | ||
DevSupportManager devSupportManager; | ||
if (context.isBridgeless()) { | ||
devSupportManager = | ||
((ReactApplication) context.getApplicationContext()) | ||
.getReactHost().getDevSupportManager(); | ||
} else { | ||
devSupportManager = | ||
((ReactApplication) context.getApplicationContext()) | ||
.getReactNativeHost() | ||
.getReactInstanceManager() | ||
.getDevSupportManager(); | ||
} | ||
|
||
if (devSupportManager != null) { | ||
devSupportManager.addCustomDevOption( | ||
"Toggle slow animations (Reanimated)", handler); | ||
} else { | ||
throw new RuntimeException("[Reanimated] DevSupportManager is not available"); | ||
} | ||
} | ||
} | ||
} |