Skip to content

Commit

Permalink
feat(android): add bridgeless support (#4985)
Browse files Browse the repository at this point in the history
  • Loading branch information
lukmccall committed Mar 10, 2024
1 parent eaa4661 commit 3ad0265
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
6 changes: 6 additions & 0 deletions android/build.gradle
Expand Up @@ -19,6 +19,10 @@ buildscript {

apply plugin: 'com.android.library'

def isNewArchitectureEnabled() {
return project.hasProperty("newArchEnabled") && project.newArchEnabled == "true"
}

android {
def agpVersion = com.android.Version.ANDROID_GRADLE_PLUGIN_VERSION
if (agpVersion.tokenize('.')[0].toInteger() >= 7) {
Expand All @@ -30,6 +34,8 @@ android {
defaultConfig {
minSdkVersion safeExtGet('minSdkVersion', 21)
targetSdkVersion safeExtGet('targetSdkVersion', 34)

buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString()
}
}

Expand Down
6 changes: 4 additions & 2 deletions android/src/main/java/com/rnmaps/maps/MapManager.java
Expand Up @@ -450,8 +450,10 @@ public void updateExtraData(MapView view, Object extraData) {
}

void pushEvent(ThemedReactContext context, View view, String name, WritableMap data) {
context.getJSModule(RCTEventEmitter.class)
.receiveEvent(view.getId(), name, data);
context
.getReactApplicationContext()
.getJSModule(RCTEventEmitter.class)
.receiveEvent(view.getId(), name, data);
}

@Override
Expand Down
11 changes: 10 additions & 1 deletion android/src/main/java/com/rnmaps/maps/MapView.java
Expand Up @@ -30,7 +30,9 @@
import com.facebook.react.bridge.WritableNativeMap;
import com.facebook.react.bridge.Arguments;
import com.facebook.react.uimanager.ThemedReactContext;
import com.facebook.react.uimanager.UIManagerHelper;
import com.facebook.react.uimanager.UIManagerModule;
import com.facebook.react.uimanager.common.UIManagerType;
import com.facebook.react.uimanager.events.EventDispatcher;
import com.google.android.gms.maps.CameraUpdate;
import com.google.android.gms.maps.CameraUpdateFactory;
Expand Down Expand Up @@ -208,7 +210,14 @@ public boolean onDoubleTap(MotionEvent ev) {
}
});

eventDispatcher = reactContext.getNativeModule(UIManagerModule.class).getEventDispatcher();
int uiManagerType = UIManagerType.DEFAULT;
if (BuildConfig.IS_NEW_ARCHITECTURE_ENABLED) {
uiManagerType = UIManagerType.FABRIC;
}

eventDispatcher = UIManagerHelper
.getUIManager(reactContext, uiManagerType)
.getEventDispatcher();

// Set up a parent view for triggering visibility in subviews that depend on it.
// Mainly ReactImageView depends on Fresco which depends on onVisibilityChanged() event
Expand Down

0 comments on commit 3ad0265

Please sign in to comment.