Skip to content

Commit

Permalink
feat: new architecture support - merge branch (#3038)
Browse files Browse the repository at this point in the history
feat: initial new architecture support by @j-piasecki  - see: #3022

Closes: #3022

Layers/Sources are not supported on Fabric yet. 
Also on android we're now using module for mapView methods like getZoom instead for command

---------

Co-authored-by: Jakub Piasecki <[email protected]>
Co-authored-by: Wojciech Lewicki <[email protected]>
  • Loading branch information
3 people authored Sep 13, 2023
1 parent 6cb49f4 commit d3b88bb
Show file tree
Hide file tree
Showing 96 changed files with 5,415 additions and 698 deletions.
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
24 changes: 1 addition & 23 deletions .github/workflows/on-push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,17 +76,6 @@ jobs:
MAPBOX_ACCESS_TOKEN: ${{ secrets.MAPBOX_ACCESS_TOKEN }}
MAPBOX_DOWNLOAD_TOKEN: ${{ secrets.MAPBOX_DOWNLOAD_TOKEN }}

call_maplibre_android_workflow:
name: "Android/MapLibre"
needs: lint_test_generate
uses: ./.github/workflows/android-actions.yml
with:
NVMRC: ${{ needs.lint_test_generate.outputs.NVMRC }}
MAP_IMPL: maplibre
secrets:
MAPBOX_ACCESS_TOKEN: ${{ secrets.MAPBOX_ACCESS_TOKEN }}
MAPBOX_DOWNLOAD_TOKEN: ${{ secrets.MAPBOX_DOWNLOAD_TOKEN }}

call_ios_workflow:
name: "iOS/Mapbox"
needs: [lint_test_generate,has_mapbox_token]
Expand All @@ -99,20 +88,9 @@ jobs:
MAPBOX_ACCESS_TOKEN: ${{ secrets.MAPBOX_ACCESS_TOKEN }}
MAPBOX_DOWNLOAD_TOKEN: ${{ secrets.MAPBOX_DOWNLOAD_TOKEN }}

call_maplibre_ios_workflow:
name: "iOS/MapLibre"
needs: lint_test_generate
uses: ./.github/workflows/ios-actions.yml
with:
NVMRC: ${{ needs.lint_test_generate.outputs.NVMRC }}
MAP_IMPL: maplibre
secrets:
MAPBOX_ACCESS_TOKEN: ${{ secrets.MAPBOX_ACCESS_TOKEN }}
MAPBOX_DOWNLOAD_TOKEN: ${{ secrets.MAPBOX_DOWNLOAD_TOKEN }}

publish:
if: startsWith(github.ref, 'refs/tags/') && (github.event_name == 'push')
needs: [lint_test_generate, call_maplibre_android_workflow, call_maplibre_ios_workflow]
needs: [lint_test_generate]
runs-on: ubuntu-latest

steps:
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'
}
}
}

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

0 comments on commit d3b88bb

Please sign in to comment.