diff --git a/android/src/main/java/com/rnmapbox/rnmbx/components/styles/atmosphere/RNMBXAtmosphereManager.kt b/android/src/main/java/com/rnmapbox/rnmbx/components/styles/atmosphere/RNMBXAtmosphereManager.kt index c5cd18762..98f9109d2 100644 --- a/android/src/main/java/com/rnmapbox/rnmbx/components/styles/atmosphere/RNMBXAtmosphereManager.kt +++ b/android/src/main/java/com/rnmapbox/rnmbx/components/styles/atmosphere/RNMBXAtmosphereManager.kt @@ -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(), RNMBXAtmosphereManagerInterface { + + private val mDelegate: ViewManagerDelegate + + init { + mDelegate = RNMBXAtmosphereManagerDelegate(this) + } + + override fun getDelegate(): ViewManagerDelegate { + return mDelegate + } -class RNMBXAtmosphereManager : ViewGroupManager() { override fun getName(): String { return REACT_CLASS } @@ -20,8 +34,8 @@ class RNMBXAtmosphereManager : ViewGroupManager() { } @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 { diff --git a/android/src/main/old-arch/com/facebook/react/viewmanagers/RNMBXAtmosphereManagerDelegate.java b/android/src/main/old-arch/com/facebook/react/viewmanagers/RNMBXAtmosphereManagerDelegate.java new file mode 100644 index 000000000..5a06406f7 --- /dev/null +++ b/android/src/main/old-arch/com/facebook/react/viewmanagers/RNMBXAtmosphereManagerDelegate.java @@ -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 & RNMBXAtmosphereManagerInterface> extends BaseViewManagerDelegate { + 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); + } + } +} diff --git a/android/src/main/old-arch/com/facebook/react/viewmanagers/RNMBXAtmosphereManagerInterface.java b/android/src/main/old-arch/com/facebook/react/viewmanagers/RNMBXAtmosphereManagerInterface.java new file mode 100644 index 000000000..633366a57 --- /dev/null +++ b/android/src/main/old-arch/com/facebook/react/viewmanagers/RNMBXAtmosphereManagerInterface.java @@ -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 { + void setReactStyle(T view, Dynamic value); +} diff --git a/fabricexample/ios/Podfile.lock b/fabricexample/ios/Podfile.lock index 4086dce73..26be5ba9e 100644 --- a/fabricexample/ios/Podfile.lock +++ b/fabricexample/ios/Podfile.lock @@ -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 diff --git a/ios/RNMBX/RNMBXAtmosphere.swift b/ios/RNMBX/RNMBXAtmosphere.swift index 0ce201d02..4a5c03253 100644 --- a/ios/RNMBX/RNMBXAtmosphere.swift +++ b/ios/RNMBX/RNMBXAtmosphere.swift @@ -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 { diff --git a/ios/RNMBX/RNMBXAtmosphereComponentView.h b/ios/RNMBX/RNMBXAtmosphereComponentView.h new file mode 100644 index 000000000..588575069 --- /dev/null +++ b/ios/RNMBX/RNMBXAtmosphereComponentView.h @@ -0,0 +1,15 @@ +#ifdef RCT_NEW_ARCH_ENABLED + +#import + +#import +#import + +NS_ASSUME_NONNULL_BEGIN + +@interface RNMBXAtmosphereComponentView : RCTViewComponentView +@end + +NS_ASSUME_NONNULL_END + +#endif // RCT_NEW_ARCH_ENABLED diff --git a/ios/RNMBX/RNMBXAtmosphereComponentView.mm b/ios/RNMBX/RNMBXAtmosphereComponentView.mm new file mode 100644 index 000000000..79d7c0122 --- /dev/null +++ b/ios/RNMBX/RNMBXAtmosphereComponentView.mm @@ -0,0 +1,82 @@ +#ifdef RCT_NEW_ARCH_ENABLED + +#import "RNMBXAtmosphereComponentView.h" +#import "RNMBXFabricHelpers.h" + +#import +#import + +#import +#import +#import +#import +// needed for compilation for some reason +#import +#import + +@interface MapView : UIView +@end + +#import + +using namespace facebook::react; + +@interface RNMBXAtmosphereComponentView () +@end + +@implementation RNMBXAtmosphereComponentView { + RNMBXAtmosphere *_view; +} + +- (instancetype)initWithFrame:(CGRect)frame +{ + if (self = [super initWithFrame:frame]) { + static const auto defaultProps = std::make_shared(); + _props = defaultProps; + [self prepareView]; + } + + return self; +} + +- (void)prepareView +{ + _view = [[RNMBXAtmosphere alloc] init]; + + self.contentView = _view; +} + +#pragma mark - RCTComponentViewProtocol + ++ (ComponentDescriptorProvider)componentDescriptorProvider +{ + return concreteComponentDescriptorProvider(); +} + + +- (void)updateProps:(const Props::Shared &)props oldProps:(const Props::Shared &)oldProps +{ + const auto &newProps = *std::static_pointer_cast(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 RNMBXAtmosphereCls(void) +{ + return RNMBXAtmosphereComponentView.class; +} + +#endif // RCT_NEW_ARCH_ENABLED diff --git a/ios/RNMBX/RNMBXAtmosphereManager.m b/ios/RNMBX/RNMBXAtmosphereViewManager.m similarity index 56% rename from ios/RNMBX/RNMBXAtmosphereManager.m rename to ios/RNMBX/RNMBXAtmosphereViewManager.m index 159b362df..3965eb7c4 100644 --- a/ios/RNMBX/RNMBXAtmosphereManager.m +++ b/ios/RNMBX/RNMBXAtmosphereViewManager.m @@ -1,7 +1,7 @@ #import #import -@interface RCT_EXTERN_MODULE(RNMBXAtmosphereManager, RCTViewManager) +@interface RCT_EXTERN_REMAP_MODULE(RNMBXAtmosphere, RNMBXAtmosphereViewManager, RCTViewManager) RCT_EXPORT_VIEW_PROPERTY(reactStyle, NSDictionary); diff --git a/ios/RNMBX/RNMBXAtmosphereManager.swift b/ios/RNMBX/RNMBXAtmosphereViewManager.swift similarity index 74% rename from ios/RNMBX/RNMBXAtmosphereManager.swift rename to ios/RNMBX/RNMBXAtmosphereViewManager.swift index 3a1c0170e..7921a65df 100644 --- a/ios/RNMBX/RNMBXAtmosphereManager.swift +++ b/ios/RNMBX/RNMBXAtmosphereViewManager.swift @@ -1,5 +1,5 @@ -@objc(RNMBXAtmosphereManager) -class RNMBXAtmosphereManager: RCTViewManager { +@objc(RNMBXAtmosphereViewManager) +class RNMBXAtmosphereViewManager: RCTViewManager { @objc override static func requiresMainQueueSetup() -> Bool { return true diff --git a/ios/RNMBX/RNMBXSingletonLayer.swift b/ios/RNMBX/RNMBXSingletonLayer.swift index 76a77e718..61103adc4 100644 --- a/ios/RNMBX/RNMBXSingletonLayer.swift +++ b/ios/RNMBX/RNMBXSingletonLayer.swift @@ -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? = nil { + @objc public var reactStyle : Dictionary? = nil { willSet { oldReactStyle = reactStyle } diff --git a/src/components/Atmosphere.tsx b/src/components/Atmosphere.tsx index 2a57f9d39..663289a60 100644 --- a/src/components/Atmosphere.tsx +++ b/src/components/Atmosphere.tsx @@ -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; @@ -20,12 +18,5 @@ export const Atmosphere = memo((props: Props) => { }; }, [props]); - return ; + return ; }); - -type NativeProps = { - reactStyle?: { [key: string]: StyleValue }; - style?: undefined; -}; - -const RNMBXAtmosphere = requireNativeComponent(NATIVE_MODULE_NAME); diff --git a/src/specs/RNMBXAtmosphereNativeComponent.ts b/src/specs/RNMBXAtmosphereNativeComponent.ts new file mode 100644 index 000000000..f20079fed --- /dev/null +++ b/src/specs/RNMBXAtmosphereNativeComponent.ts @@ -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; +} + +export default codegenNativeComponent( + 'RNMBXAtmosphere', +) as HostComponent;