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

feat: migrate Atmosphere to new arch #3091

Merged
merged 2 commits into from
Oct 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
@@ -1,11 +1,25 @@
package com.rnmapbox.rnmbx.components.styles.atmosphere

import com.facebook.react.bridge.ReadableMap
import com.facebook.react.bridge.Dynamic
import com.facebook.react.uimanager.ThemedReactContext
import com.facebook.react.uimanager.ViewGroupManager
import com.facebook.react.uimanager.ViewManagerDelegate
import com.facebook.react.uimanager.annotations.ReactProp
import com.facebook.react.viewmanagers.RNMBXAtmosphereManagerDelegate
import com.facebook.react.viewmanagers.RNMBXAtmosphereManagerInterface

class RNMBXAtmosphereManager : ViewGroupManager<RNMBXAtmosphere>(), RNMBXAtmosphereManagerInterface<RNMBXAtmosphere> {

private val mDelegate: ViewManagerDelegate<RNMBXAtmosphere>

init {
mDelegate = RNMBXAtmosphereManagerDelegate(this)
}

override fun getDelegate(): ViewManagerDelegate<RNMBXAtmosphere> {
return mDelegate
}

class RNMBXAtmosphereManager : ViewGroupManager<RNMBXAtmosphere>() {
override fun getName(): String {
return REACT_CLASS
}
Expand All @@ -20,8 +34,8 @@ class RNMBXAtmosphereManager : ViewGroupManager<RNMBXAtmosphere>() {
}

@ReactProp(name = "reactStyle")
fun setReactStyle(atmosphere: RNMBXAtmosphere, reactStyle: ReadableMap?) {
atmosphere.setReactStyle(reactStyle)
override fun setReactStyle(atmosphere: RNMBXAtmosphere, reactStyle: Dynamic) {
atmosphere.setReactStyle(reactStyle.asMap())
}

companion object {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/**
* This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
*
* Do not edit this file as changes may cause incorrect behavior and will be lost
* once the code is regenerated.
*
* @generated by codegen project: GeneratePropsJavaDelegate.js
*/

package com.facebook.react.viewmanagers;

import android.view.View;
import androidx.annotation.Nullable;
import com.facebook.react.bridge.DynamicFromObject;
import com.facebook.react.uimanager.BaseViewManagerDelegate;
import com.facebook.react.uimanager.BaseViewManagerInterface;

public class RNMBXAtmosphereManagerDelegate<T extends View, U extends BaseViewManagerInterface<T> & RNMBXAtmosphereManagerInterface<T>> extends BaseViewManagerDelegate<T, U> {
public RNMBXAtmosphereManagerDelegate(U viewManager) {
super(viewManager);
}
@Override
public void setProperty(T view, String propName, @Nullable Object value) {
switch (propName) {
case "reactStyle":
mViewManager.setReactStyle(view, new DynamicFromObject(value));
break;
default:
super.setProperty(view, propName, value);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/**
* This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
*
* Do not edit this file as changes may cause incorrect behavior and will be lost
* once the code is regenerated.
*
* @generated by codegen project: GeneratePropsJavaInterface.js
*/

package com.facebook.react.viewmanagers;

import android.view.View;
import com.facebook.react.bridge.Dynamic;

public interface RNMBXAtmosphereManagerInterface<T extends View> {
void setReactStyle(T view, Dynamic value);
}
2 changes: 1 addition & 1 deletion fabricexample/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1359,7 +1359,7 @@ SPEC CHECKSUMS:
React-perflogger: 496a1a3dc6737f964107cb3ddae7f9e265ddda58
React-RCTActionSheet: 02904b932b50e680f4e26e7a686b33ebf7ef3c00
React-RCTAnimation: 88feaf0a85648fb8fd497ce749829774910276d6
React-RCTAppDelegate: dfcb76b0c4f146c5f87d2f95d39520fbb34c19ca
React-RCTAppDelegate: 4e2c0b7fe4d62807c8613a9f162c16964aa3bb21
React-RCTBlob: 0dbc9e2a13d241b37d46b53e54630cbad1f0e141
React-RCTFabric: 0d443ab3cc3f0af82442ec95747d503cee955f26
React-RCTImage: b111645ab901f8e59fc68fbe31f5731bdbeef087
Expand Down
2 changes: 1 addition & 1 deletion ios/RNMBX/RNMBXAtmosphere.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ typealias Style = StyleManager
#endif

@objc(RNMBXAtmosphere)
class RNMBXAtmosphere : RNMBXSingletonLayer, RNMBXMapComponent, RNMBXSourceConsumer {
public class RNMBXAtmosphere : RNMBXSingletonLayer, RNMBXMapComponent, RNMBXSourceConsumer {
var atmosphere : Atmosphere? = nil

func makeAtmosphere() -> Atmosphere {
Expand Down
15 changes: 15 additions & 0 deletions ios/RNMBX/RNMBXAtmosphereComponentView.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#ifdef RCT_NEW_ARCH_ENABLED

#import <UIKit/UIKit.h>

#import <React/RCTUIManager.h>
#import <React/RCTViewComponentView.h>

NS_ASSUME_NONNULL_BEGIN

@interface RNMBXAtmosphereComponentView : RCTViewComponentView
@end

NS_ASSUME_NONNULL_END

#endif // RCT_NEW_ARCH_ENABLED
82 changes: 82 additions & 0 deletions ios/RNMBX/RNMBXAtmosphereComponentView.mm
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
#ifdef RCT_NEW_ARCH_ENABLED

#import "RNMBXAtmosphereComponentView.h"
#import "RNMBXFabricHelpers.h"

#import <React/RCTConversions.h>
#import <React/RCTFabricComponentsPlugins.h>

#import <react/renderer/components/rnmapbox_maps_specs/ComponentDescriptors.h>
#import <react/renderer/components/rnmapbox_maps_specs/EventEmitters.h>
#import <react/renderer/components/rnmapbox_maps_specs/Props.h>
#import <react/renderer/components/rnmapbox_maps_specs/RCTComponentViewHelpers.h>
// needed for compilation for some reason
#import <CoreFoundation/CoreFoundation.h>
#import <CoreLocation/CoreLocation.h>

@interface MapView : UIView
@end

#import <rnmapbox_maps-Swift.h>

using namespace facebook::react;

@interface RNMBXAtmosphereComponentView () <RCTRNMBXAtmosphereViewProtocol>
@end

@implementation RNMBXAtmosphereComponentView {
RNMBXAtmosphere *_view;
}

- (instancetype)initWithFrame:(CGRect)frame
{
if (self = [super initWithFrame:frame]) {
static const auto defaultProps = std::make_shared<const RNMBXAtmosphereProps>();
_props = defaultProps;
[self prepareView];
}

return self;
}

- (void)prepareView
{
_view = [[RNMBXAtmosphere alloc] init];

self.contentView = _view;
}

#pragma mark - RCTComponentViewProtocol

+ (ComponentDescriptorProvider)componentDescriptorProvider
{
return concreteComponentDescriptorProvider<RNMBXAtmosphereComponentDescriptor>();
}


- (void)updateProps:(const Props::Shared &)props oldProps:(const Props::Shared &)oldProps
{
const auto &newProps = *std::static_pointer_cast<const RNMBXAtmosphereProps>(props);
id reactStyle = RNMBXConvertFollyDynamicToId(newProps.reactStyle);
if (reactStyle != nil) {
_view.reactStyle = reactStyle;
}

[super updateProps:props oldProps:oldProps];
}

- (void)prepareForRecycle
{
[super prepareForRecycle];
[self prepareView];
}


@end

Class<RCTComponentViewProtocol> RNMBXAtmosphereCls(void)
{
return RNMBXAtmosphereComponentView.class;
}

#endif // RCT_NEW_ARCH_ENABLED
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#import <React/RCTBridgeModule.h>
#import <React/RCTViewManager.h>

@interface RCT_EXTERN_MODULE(RNMBXAtmosphereManager, RCTViewManager)
@interface RCT_EXTERN_REMAP_MODULE(RNMBXAtmosphere, RNMBXAtmosphereViewManager, RCTViewManager)

RCT_EXPORT_VIEW_PROPERTY(reactStyle, NSDictionary);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
@objc(RNMBXAtmosphereManager)
class RNMBXAtmosphereManager: RCTViewManager {
@objc(RNMBXAtmosphereViewManager)
class RNMBXAtmosphereViewManager: RCTViewManager {
@objc
override static func requiresMainQueueSetup() -> Bool {
return true
Expand Down
4 changes: 2 additions & 2 deletions ios/RNMBX/RNMBXSingletonLayer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ import MapboxMaps

/// RNMBXSingletonLayer is absract superclass for Light, Atmosphere, Terrain
@objc
class RNMBXSingletonLayer : UIView {
public class RNMBXSingletonLayer : UIView {
weak var bridge : RCTBridge? = nil
weak var map : RNMBXMapView? = nil
var style: Style? = nil

var oldReactStyle: [String:Any]?
@objc var reactStyle : Dictionary<String, Any>? = nil {
@objc public var reactStyle : Dictionary<String, Any>? = nil {
willSet {
oldReactStyle = reactStyle
}
Expand Down
15 changes: 3 additions & 12 deletions src/components/Atmosphere.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import React, { memo, useMemo } from 'react';
import { requireNativeComponent } from 'react-native';

import type { AtmosphereLayerStyleProps } from '../utils/MapboxStyles';
import { StyleValue, transformStyle } from '../utils/StyleValue';
import { transformStyle } from '../utils/StyleValue';
import type { BaseProps } from '../types/BaseProps';

export const NATIVE_MODULE_NAME = 'RNMBXAtmosphere';
import RNMBXAtmosphereNativeComponent from '../specs/RNMBXAtmosphereNativeComponent';

type Props = BaseProps & {
style: AtmosphereLayerStyleProps;
Expand All @@ -20,12 +18,5 @@ export const Atmosphere = memo((props: Props) => {
};
}, [props]);

return <RNMBXAtmosphere {...baseProps} />;
return <RNMBXAtmosphereNativeComponent {...baseProps} />;
});

type NativeProps = {
reactStyle?: { [key: string]: StyleValue };
style?: undefined;
};

const RNMBXAtmosphere = requireNativeComponent<NativeProps>(NATIVE_MODULE_NAME);
12 changes: 12 additions & 0 deletions src/specs/RNMBXAtmosphereNativeComponent.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import type { HostComponent, ViewProps } from 'react-native';
import codegenNativeComponent from 'react-native/Libraries/Utilities/codegenNativeComponent';

import type { UnsafeMixed } from './codegenUtils';

export interface NativeProps extends ViewProps {
reactStyle: UnsafeMixed<any>;
}

export default codegenNativeComponent<NativeProps>(
'RNMBXAtmosphere',
) as HostComponent<NativeProps>;
Loading