From 7eb0a9e1e4eb407fe36e7ba2f1f00d7b5e2fa049 Mon Sep 17 00:00:00 2001 From: Dominic Go <18517029+dominicstop@users.noreply.github.com> Date: Fri, 6 Oct 2023 21:09:48 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=86=95=20Add:=20Init.=20Impl.=20for=20`RN?= =?UTF-8?q?IModalView`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ios/RNIModalView/RNIModalView.swift | 46 +++++++++++++++++++++++ ios/RNIModalView/RNIModalViewModule.swift | 18 +++++++++ src/RNIModalView/RNIModalView.ts | 5 +++ src/RNIModalView/RNIModalViewEvents.ts | 7 ++++ src/RNIModalView/RNIModalViewModule.ts | 11 ++++++ src/RNIModalView/RNIModalViewTypes.ts | 10 +++++ src/RNIModalView/index.ts | 4 ++ 7 files changed, 101 insertions(+) create mode 100644 ios/RNIModalView/RNIModalView.swift create mode 100644 ios/RNIModalView/RNIModalViewModule.swift create mode 100644 src/RNIModalView/RNIModalView.ts create mode 100644 src/RNIModalView/RNIModalViewEvents.ts create mode 100644 src/RNIModalView/RNIModalViewModule.ts create mode 100644 src/RNIModalView/RNIModalViewTypes.ts create mode 100644 src/RNIModalView/index.ts diff --git a/ios/RNIModalView/RNIModalView.swift b/ios/RNIModalView/RNIModalView.swift new file mode 100644 index 00000000..f74df6ef --- /dev/null +++ b/ios/RNIModalView/RNIModalView.swift @@ -0,0 +1,46 @@ +// +// RNIModalView.swift +// ReactNativeIosModal +// +// Created by Dominic Go on 10/6/23. +// + +import ExpoModulesCore + +public class RNIModalView: ExpoView { + + // MARK: Properties + // ---------------- + + public override var reactTag: NSNumber! { + didSet { + guard let newValue = self.reactTag, + newValue != oldValue + else { return }; + + self.onReactTagDidSetEvent.callAsFunction([ + "reactTag": newValue + ]); + } + }; + + // MARK: Properties - Prop - Events + // -------------------------------- + + let onReactTagDidSetEvent = EventDispatcher("onReactTagDidSet"); + + // MARK: Init + Lifecycle + // ---------------------- + + public required init(appContext: AppContext? = nil) { + super.init(appContext: appContext); + }; + + public override func layoutSubviews() { + super.layoutSubviews(); + }; + + public override func insertReactSubview(_ subview: UIView!, at atIndex: Int) { + super.insertReactSubview(subview, at: atIndex); + }; +}; diff --git a/ios/RNIModalView/RNIModalViewModule.swift b/ios/RNIModalView/RNIModalViewModule.swift new file mode 100644 index 00000000..a63ccbc5 --- /dev/null +++ b/ios/RNIModalView/RNIModalViewModule.swift @@ -0,0 +1,18 @@ +// +// RNIModalViewModule.swift +// ReactNativeIosModal +// +// Created by Dominic Go on 10/6/23. +// + +import ExpoModulesCore + +public class RNIModalViewModule: Module { + + public func definition() -> ModuleDefinition { + Name("RNIModalViewModule"); + + View(RNIModalView.self) { + }; + }; +}; diff --git a/src/RNIModalView/RNIModalView.ts b/src/RNIModalView/RNIModalView.ts new file mode 100644 index 00000000..7418c2d6 --- /dev/null +++ b/src/RNIModalView/RNIModalView.ts @@ -0,0 +1,5 @@ +import { requireNativeViewManager } from 'expo-modules-core'; +import type { RNIModalViewProps } from './RNIModalViewTypes'; + +export const RNIModalView: React.ComponentType = + requireNativeViewManager('RNIModalView'); \ No newline at end of file diff --git a/src/RNIModalView/RNIModalViewEvents.ts b/src/RNIModalView/RNIModalViewEvents.ts new file mode 100644 index 00000000..767d73c6 --- /dev/null +++ b/src/RNIModalView/RNIModalViewEvents.ts @@ -0,0 +1,7 @@ +export type OnModalViewReactTagDidSetEventPayload = { + reactTag?: number; +}; + +export type OnModalViewReactTagDidSetEvent = (event: { + nativeEvent: OnModalViewReactTagDidSetEventPayload +}) => void; \ No newline at end of file diff --git a/src/RNIModalView/RNIModalViewModule.ts b/src/RNIModalView/RNIModalViewModule.ts new file mode 100644 index 00000000..75249cf0 --- /dev/null +++ b/src/RNIModalView/RNIModalViewModule.ts @@ -0,0 +1,11 @@ +import { requireNativeModule } from 'expo-modules-core'; + +interface RNIModalViewModule { + notifyComponentWillUnmount( + reactTag: number, + isManuallyTriggered: boolean + ): void; +}; + +export const RNIModalViewModule: RNIModalViewModule = + requireNativeModule('RNIModalView'); \ No newline at end of file diff --git a/src/RNIModalView/RNIModalViewTypes.ts b/src/RNIModalView/RNIModalViewTypes.ts new file mode 100644 index 00000000..c45d16a3 --- /dev/null +++ b/src/RNIModalView/RNIModalViewTypes.ts @@ -0,0 +1,10 @@ +import { ViewProps } from 'react-native'; +import type { OnModalViewReactTagDidSetEvent } from './RNIModalViewEvents'; + +export type RNIModalViewBaseProps = { + shouldCleanupOnComponentWillUnmount: boolean; + onReactTagDidSet: OnModalViewReactTagDidSetEvent; +}; + +export type RNIModalViewProps = + RNIModalViewBaseProps & ViewProps; \ No newline at end of file diff --git a/src/RNIModalView/index.ts b/src/RNIModalView/index.ts new file mode 100644 index 00000000..bd48932b --- /dev/null +++ b/src/RNIModalView/index.ts @@ -0,0 +1,4 @@ + +export * from './RNIModalView'; +export * from './RNIModalViewTypes'; +export * from './RNIModalViewEvents'; \ No newline at end of file