From 9e427a125ce9dc76e6d1eac32bd5157c64bb727b Mon Sep 17 00:00:00 2001 From: Dominic Go <18517029+dominicstop@users.noreply.github.com> Date: Fri, 7 Jun 2024 14:24:45 +0800 Subject: [PATCH] =?UTF-8?q?=E2=AD=90=EF=B8=8F=20Impl:=20`RNIModalView`=20S?= =?UTF-8?q?caffolding?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ios/IosModalView.h | 17 --- ios/IosModalView.mm | 71 ------------ ios/IosModalViewManager.mm | 19 ---- ios/RNIModalView/RNIModalView.h | 27 +++++ ios/RNIModalView/RNIModalView.mm | 103 ++++++++++++++++++ .../RNIModalViewComponentDescriptor.h | 28 +++++ ios/RNIModalView/RNIModalViewDelegate.swift | 9 ++ ios/RNIModalView/RNIModalViewManager.m | 8 ++ ios/RNIModalView/RNIModalViewShadowNode.h | 45 ++++++++ ios/Swift.h | 28 +++++ src/IosModalViewNativeComponent.ts | 8 -- .../RNIModalView/RNIModalNativeView.ts | 14 +++ .../RNIModalViewNativeComponent.ts | 10 ++ src/native_components/RNIModalView/index.ts | 1 + 14 files changed, 273 insertions(+), 115 deletions(-) delete mode 100644 ios/IosModalView.h delete mode 100644 ios/IosModalView.mm delete mode 100644 ios/IosModalViewManager.mm create mode 100644 ios/RNIModalView/RNIModalView.h create mode 100644 ios/RNIModalView/RNIModalView.mm create mode 100644 ios/RNIModalView/RNIModalViewComponentDescriptor.h create mode 100644 ios/RNIModalView/RNIModalViewDelegate.swift create mode 100644 ios/RNIModalView/RNIModalViewManager.m create mode 100644 ios/RNIModalView/RNIModalViewShadowNode.h create mode 100644 ios/Swift.h delete mode 100644 src/IosModalViewNativeComponent.ts create mode 100644 src/native_components/RNIModalView/RNIModalNativeView.ts create mode 100644 src/native_components/RNIModalView/RNIModalViewNativeComponent.ts create mode 100644 src/native_components/RNIModalView/index.ts diff --git a/ios/IosModalView.h b/ios/IosModalView.h deleted file mode 100644 index 1e7a628e..00000000 --- a/ios/IosModalView.h +++ /dev/null @@ -1,17 +0,0 @@ -// This guard prevent this file to be compiled in the old architecture. -#ifdef RCT_NEW_ARCH_ENABLED -#import -#import - -#ifndef IosModalViewNativeComponent_h -#define IosModalViewNativeComponent_h - -NS_ASSUME_NONNULL_BEGIN - -@interface IosModalView : RCTViewComponentView -@end - -NS_ASSUME_NONNULL_END - -#endif /* IosModalViewNativeComponent_h */ -#endif /* RCT_NEW_ARCH_ENABLED */ diff --git a/ios/IosModalView.mm b/ios/IosModalView.mm deleted file mode 100644 index dd8ca166..00000000 --- a/ios/IosModalView.mm +++ /dev/null @@ -1,71 +0,0 @@ -#import "IosModalView.h" - -#import -#import -#import -#import - -#import "RCTFabricComponentsPlugins.h" - -using namespace facebook::react; - -@interface IosModalView () - -@end - -@implementation IosModalView { - UIView * _view; -} - -+ (ComponentDescriptorProvider)componentDescriptorProvider -{ - return concreteComponentDescriptorProvider(); -} - -- (instancetype)initWithFrame:(CGRect)frame -{ - if (self = [super initWithFrame:frame]) { - static const auto defaultProps = std::make_shared(); - _props = defaultProps; - - _view = [[UIView alloc] init]; - - self.contentView = _view; - } - - return self; -} - -- (void)updateProps:(Props::Shared const &)props oldProps:(Props::Shared const &)oldProps -{ - const auto &oldViewProps = *std::static_pointer_cast(_props); - const auto &newViewProps = *std::static_pointer_cast(props); - - if (oldViewProps.color != newViewProps.color) { - NSString * colorToConvert = [[NSString alloc] initWithUTF8String: newViewProps.color.c_str()]; - [_view setBackgroundColor:[self hexStringToColor:colorToConvert]]; - } - - [super updateProps:props oldProps:oldProps]; -} - -Class IosModalViewCls(void) -{ - return IosModalView.class; -} - -- hexStringToColor:(NSString *)stringToConvert -{ - NSString *noHashString = [stringToConvert stringByReplacingOccurrencesOfString:@"#" withString:@""]; - NSScanner *stringScanner = [NSScanner scannerWithString:noHashString]; - - unsigned hex; - if (![stringScanner scanHexInt:&hex]) return nil; - int r = (hex >> 16) & 0xFF; - int g = (hex >> 8) & 0xFF; - int b = (hex) & 0xFF; - - return [UIColor colorWithRed:r / 255.0f green:g / 255.0f blue:b / 255.0f alpha:1.0f]; -} - -@end diff --git a/ios/IosModalViewManager.mm b/ios/IosModalViewManager.mm deleted file mode 100644 index bad2a2c6..00000000 --- a/ios/IosModalViewManager.mm +++ /dev/null @@ -1,19 +0,0 @@ -#import -#import -#import "RCTBridge.h" - -@interface IosModalViewManager : RCTViewManager -@end - -@implementation IosModalViewManager - -RCT_EXPORT_MODULE(IosModalView) - -- (UIView *)view -{ - return [[UIView alloc] init]; -} - -RCT_EXPORT_VIEW_PROPERTY(color, NSString) - -@end diff --git a/ios/RNIModalView/RNIModalView.h b/ios/RNIModalView/RNIModalView.h new file mode 100644 index 00000000..b557e0ed --- /dev/null +++ b/ios/RNIModalView/RNIModalView.h @@ -0,0 +1,27 @@ +// +// RNIModalView.h +// react-native-ios-modal +// +// Created by Dominic Go on 6/6/24. +// + +#import + +#if RCT_NEW_ARCH_ENABLED +#import +#else +#import +#endif + +@protocol RNIContentViewParentDelegate; +@protocol RNIContentViewDelegate; + +@class RCTBridge; + +#if RCT_NEW_ARCH_ENABLED +namespace react = facebook::react; +#endif + +@interface RNIModalView : RNIBaseView + +@end diff --git a/ios/RNIModalView/RNIModalView.mm b/ios/RNIModalView/RNIModalView.mm new file mode 100644 index 00000000..68ad2325 --- /dev/null +++ b/ios/RNIModalView/RNIModalView.mm @@ -0,0 +1,103 @@ +// +// RNIModalView.mm +// react-native-ios-modal +// +// Created by Dominic Go on 6/6/24. +// + +#import "RNIModalView.h" + +#import "react-native-ios-modal/Swift.h" +#import +#import + +#import +#import + +#if RCT_NEW_ARCH_ENABLED +#include "RNIModalViewComponentDescriptor.h" + +#include +#include + +#import +#import +#import +#import + +#include +#include +#include +#include + +#import +#import +#else +#import +#import +#endif + +#ifdef RCT_NEW_ARCH_ENABLED +using namespace facebook::react; +#endif + + +@interface RNIModalView () < + RNIContentViewParentDelegate, +#ifdef RCT_NEW_ARCH_ENABLED + RCTRNIModalViewViewProtocol +#else + RCTInvalidating +#endif +> { + // TBA +} +@end + +@implementation RNIModalView { +} + +// MARK: - Init +// ------------ + +- (void)initCommon { + [super initCommon]; +} + +// MARK: - RNIBaseView +// ------------------- + ++ (Class)viewDelegateClass +{ + return nil; + //return [RNIDummyTestViewDelegate class]; +} + +// MARK: - Fabric +// -------------- + +#if RCT_NEW_ARCH_ENABLED ++ (ComponentDescriptorProvider)componentDescriptorProvider +{ + return concreteComponentDescriptorProvider(); +} + +Class RNIModalViewCls(void) +{ + return RNIModalView.class; +} +#else + +// MARK: - Paper +// ------------- + +- (void)invalidate +{ + // to be impl. +} + +#endif +@end + + + diff --git a/ios/RNIModalView/RNIModalViewComponentDescriptor.h b/ios/RNIModalView/RNIModalViewComponentDescriptor.h new file mode 100644 index 00000000..8833b49d --- /dev/null +++ b/ios/RNIModalView/RNIModalViewComponentDescriptor.h @@ -0,0 +1,28 @@ +// +// RNIModalViewComponentDescriptor.h +// react-native-ios-modal +// +// Created by Dominic Go on 6/6/24. +// + +#if __cplusplus +#pragma once + +#include "RNIModalViewShadowNode.h" +#include "RNIBaseViewComponentDescriptor.h" + +#include +#include + + +namespace facebook::react { + +class RNIModalViewComponentDescriptor final + : public RNIBaseViewComponentDescriptor { + +public: + using RNIBaseViewComponentDescriptor::RNIBaseViewComponentDescriptor; +}; + +} // namespace facebook::react +#endif diff --git a/ios/RNIModalView/RNIModalViewDelegate.swift b/ios/RNIModalView/RNIModalViewDelegate.swift new file mode 100644 index 00000000..e2746965 --- /dev/null +++ b/ios/RNIModalView/RNIModalViewDelegate.swift @@ -0,0 +1,9 @@ +// +// RNIModalViewDelegate.swift +// react-native-ios-modal +// +// Created by Dominic Go on 6/6/24. +// + +import react_native_ios_utilities + diff --git a/ios/RNIModalView/RNIModalViewManager.m b/ios/RNIModalView/RNIModalViewManager.m new file mode 100644 index 00000000..4a4fdaca --- /dev/null +++ b/ios/RNIModalView/RNIModalViewManager.m @@ -0,0 +1,8 @@ +// +// RNIModalViewManager.m +// react-native-ios-modal +// +// Created by Dominic Go on 6/6/24. +// + +#import diff --git a/ios/RNIModalView/RNIModalViewShadowNode.h b/ios/RNIModalView/RNIModalViewShadowNode.h new file mode 100644 index 00000000..904d617f --- /dev/null +++ b/ios/RNIModalView/RNIModalViewShadowNode.h @@ -0,0 +1,45 @@ +// +// RNIModalViewShadowNode.h +// react-native-ios-modal +// +// Created by Dominic Go on 6/6/24. +// + +#if __cplusplus +#pragma once + +#include +#include +#include + +#include +#include + +#include +#include + + +namespace facebook::react { + +JSI_EXPORT extern const char RNIModalViewComponentName[] = "RNIModalView"; + +class JSI_EXPORT RNIModalViewShadowNode final : public RNIBaseViewShadowNode< + RNIModalViewComponentName, + RNIBaseViewProps, + RNIBaseViewEventEmitter +> { + +public: + using RNIBaseViewShadowNode::RNIBaseViewShadowNode; + + static RNIBaseViewState initialStateData( + const Props::Shared&r , // props + const ShadowNodeFamily::Shared&, // family + const ComponentDescriptor& // componentDescriptor + ) { + return {}; + } +}; + +} // facebook::react +#endif diff --git a/ios/Swift.h b/ios/Swift.h new file mode 100644 index 00000000..3c46f15a --- /dev/null +++ b/ios/Swift.h @@ -0,0 +1,28 @@ +// +// Swift.h +// react-native-ios-modal +// +// Created by Dominic Go on 6/6/24. +// + +// When `use_frameworks!` is used, the generated Swift header is inside +// the module. +// Otherwise, it's available only locally with double-quoted imports. +#if __has_include() +#import "" +#else +#import "react_native_ios_modal-Swift.h" +#endif + + +// #import +// #import "" +// #import +// #import +// #import + + +//#import "react_native_ios_utilities-Swift.h" +// #import "react_native_ios_utilities/react_native_ios_utilities-Swift.h" +//#import +//#import diff --git a/src/IosModalViewNativeComponent.ts b/src/IosModalViewNativeComponent.ts deleted file mode 100644 index 79d20273..00000000 --- a/src/IosModalViewNativeComponent.ts +++ /dev/null @@ -1,8 +0,0 @@ -import codegenNativeComponent from 'react-native/Libraries/Utilities/codegenNativeComponent'; -import type { ViewProps } from 'react-native'; - -interface NativeProps extends ViewProps { - color?: string; -} - -export default codegenNativeComponent('IosModalView'); diff --git a/src/native_components/RNIModalView/RNIModalNativeView.ts b/src/native_components/RNIModalView/RNIModalNativeView.ts new file mode 100644 index 00000000..4172326f --- /dev/null +++ b/src/native_components/RNIModalView/RNIModalNativeView.ts @@ -0,0 +1,14 @@ +import type { HostComponent, ViewProps } from 'react-native'; + +import { default as RNIModalViewNativeComponent } from './RNIModalViewNativeComponent'; +import type { SharedViewEvents } from 'react-native-ios-utilities'; + +export interface RNIModalNativeViewBaseProps extends ViewProps { +}; + +export type RNIModalNativeViewProps = + SharedViewEvents + & RNIModalNativeViewBaseProps; + +export const RNIModalNativeView = + RNIModalViewNativeComponent as unknown as HostComponent; diff --git a/src/native_components/RNIModalView/RNIModalViewNativeComponent.ts b/src/native_components/RNIModalView/RNIModalViewNativeComponent.ts new file mode 100644 index 00000000..54d12d63 --- /dev/null +++ b/src/native_components/RNIModalView/RNIModalViewNativeComponent.ts @@ -0,0 +1,10 @@ +import codegenNativeComponent from 'react-native/Libraries/Utilities/codegenNativeComponent'; +import type { HostComponent, ViewProps } from 'react-native'; + +interface NativeProps extends ViewProps { +} + +export default codegenNativeComponent('RNIModalView', { + excludedPlatforms: ['android'], + interfaceOnly: true, +}) as HostComponent; diff --git a/src/native_components/RNIModalView/index.ts b/src/native_components/RNIModalView/index.ts new file mode 100644 index 00000000..8dfb91a8 --- /dev/null +++ b/src/native_components/RNIModalView/index.ts @@ -0,0 +1 @@ +export * from './RNIModalNativeView'; \ No newline at end of file