Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new architecture support #3022

Closed
wants to merge 33 commits into from
Closed
Show file tree
Hide file tree
Changes from 32 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
212f67b
Setup fabricexample app
j-piasecki Aug 24, 2023
0e5b78b
Enable new architecture
j-piasecki Aug 24, 2023
d8e5ae1
Basic ios setup
j-piasecki Aug 24, 2023
f40bfa7
Some iOS progress:
j-piasecki Aug 25, 2023
0147706
Use one view manager?
j-piasecki Aug 28, 2023
5785b88
Update spec
j-piasecki Aug 28, 2023
09bb480
Start android
j-piasecki Aug 28, 2023
81130bf
Convert dynamic position to dict
j-piasecki Aug 28, 2023
08fceb5
Set iOS props
j-piasecki Aug 28, 2023
287c7e2
Update spec
j-piasecki Aug 29, 2023
a05160a
Update Android event emitter
j-piasecki Aug 29, 2023
585dbf4
iOS events shenanigans
j-piasecki Aug 29, 2023
e89206a
Use module instead of native commands on new arch
j-piasecki Aug 30, 2023
2ae8842
Implement all methods
j-piasecki Aug 30, 2023
d07804f
I've figured it out :)
j-piasecki Aug 30, 2023
329af5e
Begin android module
j-piasecki Aug 31, 2023
d02bdb1
Make android commands work
j-piasecki Sep 1, 2023
1bae7b1
Update Android module to resolve promises with data
j-piasecki Sep 1, 2023
b06a4b8
Remove command name from module calls
j-piasecki Sep 1, 2023
0a23822
Reject promises when error is present
j-piasecki Sep 1, 2023
2f8dcf4
I aimed a little to high in the code
j-piasecki Sep 1, 2023
7dd5fe7
Reject promise when map view cannot be found
j-piasecki Sep 1, 2023
6d9d8e0
feat: old arch also working
WoLewicki Sep 1, 2023
fc23bfd
Update gitignore
j-piasecki Sep 1, 2023
a95fe4f
Fixes after rebase
j-piasecki Sep 4, 2023
fb96e20
Add helper for decoding event payload
j-piasecki Sep 4, 2023
cf70036
Revert whitespace changes
j-piasecki Sep 4, 2023
1b3922f
Support for TextureMapView
j-piasecki Sep 4, 2023
55a11e8
Support old architecture on Android
j-piasecki Sep 4, 2023
174ebcc
feat: simpler new arch interoop
WoLewicki Sep 5, 2023
7808343
Clean up the simpler interop and make iOS compile
j-piasecki Sep 5, 2023
66e6ccd
Fix lint & tests
j-piasecki Sep 5, 2023
b1f77ed
fix: dispatch methods on uimanager queue
WoLewicki Sep 12, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ module.exports = {
project: [
'./tsconfig.json',
'./example/tsconfig.json',
'./fabricexample/tsconfig.json',
'./plugin/src/__tests__/tsconfig.eslint.json',
],
},
Expand Down
20 changes: 20 additions & 0 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ def safeExtGet(prop, fallback) {
rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
}

def isNewArchitectureEnabled() {
// To opt-in for the New Architecture, you can either:
// - Set `newArchEnabled` to true inside the `gradle.properties` file
// - Invoke gradle with `-newArchEnabled=true`
// - Set an environment variable `ORG_GRADLE_PROJECT_newArchEnabled=true`
return project.hasProperty("newArchEnabled") && project.newArchEnabled == "true"
}

// expo plugin
if (rootProject.ext.has('expoRNMapboxMapsImpl')) {
rootProject.ext.set('RNMapboxMapsImpl', rootProject.ext.get('expoRNMapboxMapsImpl'))
Expand All @@ -25,6 +33,9 @@ buildscript {
}
}

if (isNewArchitectureEnabled()) {
apply plugin: 'com.facebook.react'
}
apply plugin: 'com.android.library'

if (safeExtGet("RNMapboxMapsImpl", defaultMapboxMapsImpl) == "mapbox") {
Expand Down Expand Up @@ -68,6 +79,14 @@ android {
throw new GradleException(msg)
}

if (!isNewArchitectureEnabled()) {
sourceSets {
main {
java.srcDirs += 'src/main/old-arch'
Copy link
Contributor

@mfazekas mfazekas Sep 4, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't really use this right?
Sorry I've just realised we do use it....

}
}
}

compileSdkVersion safeExtGet("compileSdkVersion", 28)
buildToolsVersion safeExtGet("buildToolsVersion", '28.0.3')

Expand All @@ -76,6 +95,7 @@ android {
targetSdkVersion safeExtGet('targetSdkVersion', 26)
versionCode 1
versionName "1.0"
buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString()
}

compileOptions {
Expand Down
121 changes: 109 additions & 12 deletions android/src/main/java-v10/com/mapbox/rctmgl/RCTMGLPackage.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
package com.mapbox.rctmgl;

import androidx.annotation.Nullable;

import com.facebook.react.ReactPackage;
import com.facebook.react.TurboReactPackage;
import com.facebook.react.bridge.JavaScriptModule;
import com.facebook.react.bridge.NativeModule;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.module.model.ReactModuleInfo;
import com.facebook.react.module.model.ReactModuleInfoProvider;
import com.facebook.react.uimanager.ViewManager;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.mapbox.rctmgl.components.camera.RCTMGLCameraManager;

Expand All @@ -18,6 +25,7 @@
import com.mapbox.rctmgl.components.images.RCTMGLImageManager;
import com.mapbox.rctmgl.components.images.RCTMGLImagesManager;
import com.mapbox.rctmgl.components.location.RCTMGLNativeUserLocationManager;
import com.mapbox.rctmgl.components.mapview.NativeMapViewModule;
import com.mapbox.rctmgl.components.mapview.RCTMGLMapViewManager;
import com.mapbox.rctmgl.components.mapview.RCTMGLAndroidTextureMapViewManager;
import com.mapbox.rctmgl.components.styles.atmosphere.RCTMGLAtmosphereManager;
Expand Down Expand Up @@ -49,20 +57,27 @@
import com.mapbox.rctmgl.modules.RCTMGLModule;


public class RCTMGLPackage implements ReactPackage {
public class RCTMGLPackage extends TurboReactPackage {

@Nullable
@Override
public List<NativeModule> createNativeModules(ReactApplicationContext reactApplicationContext) {
List<NativeModule> modules = new ArrayList<>();
modules.add(new RCTMGLModule(reactApplicationContext));
modules.add(new RCTMGLLocationModule(reactApplicationContext));

modules.add(new RCTMGLOfflineModule(reactApplicationContext));
modules.add(new RCTMGLSnapshotModule(reactApplicationContext));

modules.add(new RCTMGLLogging(reactApplicationContext));

return modules;
public NativeModule getModule(String s, ReactApplicationContext reactApplicationContext) {
switch (s) {
case RCTMGLModule.REACT_CLASS:
return new RCTMGLModule(reactApplicationContext);
case RCTMGLLocationModule.REACT_CLASS:
return new RCTMGLLocationModule(reactApplicationContext);
case RCTMGLOfflineModule.REACT_CLASS:
return new RCTMGLOfflineModule(reactApplicationContext);
case RCTMGLSnapshotModule.REACT_CLASS:
return new RCTMGLSnapshotModule(reactApplicationContext);
case RCTMGLLogging.REACT_CLASS:
return new RCTMGLLogging(reactApplicationContext);
case NativeMapViewModule.NAME:
return new NativeMapViewModule(reactApplicationContext);
}

return null;
}

@Deprecated
Expand Down Expand Up @@ -115,4 +130,86 @@ public List<ViewManager> createViewManagers(ReactApplicationContext reactApplica

return managers;
}

@Override
public ReactModuleInfoProvider getReactModuleInfoProvider() {
return () -> {
final Map<String, ReactModuleInfo> moduleInfos = new HashMap<>();
boolean isTurboModule = BuildConfig.IS_NEW_ARCHITECTURE_ENABLED;

moduleInfos.put(
RCTMGLModule.REACT_CLASS,
new ReactModuleInfo(
RCTMGLModule.REACT_CLASS,
RCTMGLModule.REACT_CLASS,
false, // canOverrideExistingModule
false, // needsEagerInit
true, // hasConstants
false, // isCxxModule
false // isTurboModule
));

moduleInfos.put(
RCTMGLLocationModule.REACT_CLASS,
new ReactModuleInfo(
RCTMGLLocationModule.REACT_CLASS,
RCTMGLLocationModule.REACT_CLASS,
false, // canOverrideExistingModule
false, // needsEagerInit
true, // hasConstants
false, // isCxxModule
false // isTurboModule
));

moduleInfos.put(
RCTMGLOfflineModule.REACT_CLASS,
new ReactModuleInfo(
RCTMGLOfflineModule.REACT_CLASS,
RCTMGLOfflineModule.REACT_CLASS,
false, // canOverrideExistingModule
false, // needsEagerInit
true, // hasConstants
false, // isCxxModule
false // isTurboModule
));

moduleInfos.put(
RCTMGLSnapshotModule.REACT_CLASS,
new ReactModuleInfo(
RCTMGLSnapshotModule.REACT_CLASS,
RCTMGLSnapshotModule.REACT_CLASS,
false, // canOverrideExistingModule
false, // needsEagerInit
true, // hasConstants
false, // isCxxModule
false // isTurboModule
));

moduleInfos.put(
RCTMGLLogging.REACT_CLASS,
new ReactModuleInfo(
RCTMGLLogging.REACT_CLASS,
RCTMGLLogging.REACT_CLASS,
false, // canOverrideExistingModule
false, // needsEagerInit
true, // hasConstants
false, // isCxxModule
false // isTurboModule
));

moduleInfos.put(
NativeMapViewModule.NAME,
new ReactModuleInfo(
NativeMapViewModule.NAME,
NativeMapViewModule.NAME,
false, // canOverrideExistingModule
false, // needsEagerInit
false, // hasConstants
false, // isCxxModule
isTurboModule // isTurboModule
));

return moduleInfos;
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@ import android.view.ViewGroup
import com.facebook.react.bridge.ReactApplicationContext
import com.facebook.react.common.MapBuilder
import com.facebook.react.uimanager.ThemedReactContext
import com.facebook.react.uimanager.UIManagerModule
import com.facebook.react.uimanager.UIManagerHelper
import com.facebook.react.uimanager.ViewGroupManager
import com.facebook.react.uimanager.events.EventDispatcher
import com.mapbox.rctmgl.events.IEvent
import javax.annotation.Nonnull

/**
* Created by nickitaliano on 8/23/17.
Expand Down Expand Up @@ -47,7 +46,7 @@ abstract class AbstractEventEmitter<T : ViewGroup?>(reactApplicationContext: Rea
}

override fun addEventEmitters(context: ThemedReactContext, view: T) {
mEventDispatcher = context.getNativeModule(UIManagerModule::class.java)!!.eventDispatcher
mEventDispatcher = UIManagerHelper.getEventDispatcherForReactTag(context, view!!.id)
}

override fun getExportedCustomDirectEventTypeConstants(): Map<String, Any>? {
Expand Down
Loading
Loading