Skip to content

Commit

Permalink
💫 Update: RNIModalView Scaffolding
Browse files Browse the repository at this point in the history
  • Loading branch information
dominicstop committed Jun 7, 2024
1 parent dfe7c56 commit 1e23d7b
Show file tree
Hide file tree
Showing 10 changed files with 293 additions and 17 deletions.
10 changes: 7 additions & 3 deletions example/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
import * as React from 'react';

import { StyleSheet, View } from 'react-native';
import { IosModalView } from 'react-native-ios-modal';
import { StyleSheet, View, Text } from 'react-native';
import { RNIModalView } from 'react-native-ios-modal';

export default function App() {
return (
<View style={styles.container}>
<IosModalView color="#32a852" style={styles.box} />
<RNIModalView style={{backgroundColor: 'red'}}>
<View>
<Text>Hello World</Text>
</View>
</RNIModalView>
</View>
);
}
Expand Down
5 changes: 3 additions & 2 deletions ios/RNIModalView/RNIModalView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@

#import "react-native-ios-modal/Swift.h"
#import <react-native-ios-utilities/RNIBaseView.h>

#import <react-native-ios-utilities/RNIContentViewParentDelegate.h>


#import <react-native-ios-utilities/UIApplication+RNIHelpers.h>
#import <react-native-ios-utilities/RNIObjcUtils.h>

Expand Down Expand Up @@ -69,8 +71,7 @@ - (void)initCommon {

+ (Class)viewDelegateClass
{
return nil;
//return [RNIDummyTestViewDelegate class];
return [RNIModalViewDelegate class];
}

// MARK: - Fabric
Expand Down
171 changes: 171 additions & 0 deletions ios/RNIModalView/RNIModalViewDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,176 @@
// Created by Dominic Go on 6/6/24.
//

import UIKit
import react_native_ios_utilities
import DGSwiftUtilities

@objc(RNIModalViewDelegate)
public final class RNIModalViewDelegate: UIView, RNIContentView {

public static var propKeyPathMap: Dictionary<String, PartialKeyPath<RNIModalViewDelegate>> {
return [:];
};

public enum Events: String, CaseIterable {
case placeholderEvent;
}

// MARK: Properties
// ----------------

var _didSendEvents = false;

// MARK: - Properties - RNIContentViewDelegate
// -------------------------------------------

public weak var parentReactView: RNIContentViewParentDelegate?;

// MARK: Properties - Props
// ------------------------

public var reactProps: NSDictionary = [:];

// TBA

// MARK: Init
// ----------

public override init(frame: CGRect) {
super.init(frame: frame);
};

required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented");
}

// MARK: Functions
// ---------------

public override func didMoveToWindow() {
guard self.window != nil,
let parentReactView = self.parentReactView
else { return };

DispatchQueue.main.asyncAfter(deadline: .now() + 10){
parentReactView.setSize(.init(width: 300, height: 300));
};
};

func _setupContent(){
self.backgroundColor = .systemPink;

let label = UILabel();
label.text = "Fabric View (sort of) in Swift";

label.translatesAutoresizingMaskIntoConstraints = false;
self.addSubview(label);

NSLayoutConstraint.activate([
label.centerXAnchor.constraint(
equalTo: self.centerXAnchor
),
label.centerYAnchor.constraint(
equalTo: self.centerYAnchor
),
]);
};
};

extension RNIModalViewDelegate: RNIContentViewDelegate {

public typealias KeyPathRoot = RNIModalViewDelegate;

// MARK: Paper + Fabric
// --------------------

public func notifyOnInit(sender: RNIContentViewParentDelegate) {
self._setupContent();
};

public func notifyOnMountChildComponentView(
sender: RNIContentViewParentDelegate,
childComponentView: UIView,
index: NSInteger,
superBlock: () -> Void
) {
#if !RCT_NEW_ARCH_ENABLED
superBlock();
#endif

// Note: Window might not be available yet
self.addSubview(childComponentView);
};

public func notifyOnUnmountChildComponentView(
sender: RNIContentViewParentDelegate,
childComponentView: UIView,
index: NSInteger,
superBlock: () -> Void
) {
#if !RCT_NEW_ARCH_ENABLED
superBlock();
#endif

}

public func notifyDidSetProps(sender: RNIContentViewParentDelegate) {
// no-op
};

public func notifyOnUpdateLayoutMetrics(
sender: RNIContentViewParentDelegate,
oldLayoutMetrics: RNILayoutMetrics,
newLayoutMetrics: RNILayoutMetrics
) {
// no-op
};

public func notifyOnViewCommandRequest(
sender: RNIContentViewParentDelegate,
forCommandName commandName: String,
withCommandArguments commandArguments: NSDictionary,
resolve resolveBlock: (NSDictionary) -> Void,
reject rejectBlock: (String) -> Void
) {
// no-op
};

// MARK: Fabric Only
// -----------------

#if RCT_NEW_ARCH_ENABLED
public func notifyOnUpdateProps(
sender: RNIContentViewParentDelegate,
oldProps: NSDictionary,
newProps: NSDictionary
) {
// no-op
};

public func notifyOnUpdateState(
sender: RNIContentViewParentDelegate,
oldState: NSDictionary?,
newState: NSDictionary
) {
// no-op
};

public func notifyOnFinalizeUpdates(
sender: RNIContentViewParentDelegate,
updateMaskRaw: Int,
updateMask: RNIComponentViewUpdateMask
) {
// no-op
};

public func notifyOnPrepareForReuse(sender: RNIContentViewParentDelegate) {
// no-op
};
#else

// MARK: - Paper Only
// ------------------

#endif
};
8 changes: 0 additions & 8 deletions ios/RNIModalView/RNIModalViewManager.m

This file was deleted.

33 changes: 33 additions & 0 deletions ios/RNIModalView/RNIModalViewManager.mm
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
//
// RNIModalViewManager.m
// react-native-ios-modal
//
// Created by Dominic Go on 6/6/24.
//

#import "RNIModalView.h"
#import <objc/runtime.h>

#import "react-native-ios-utilities/RNIBaseViewUtils.h"

#import "RCTBridge.h"
#import <React/RCTViewManager.h>
#import <React/RCTUIManager.h>


@interface RNIModalViewManager : RCTViewManager
@end

@implementation RNIModalViewManager

RCT_EXPORT_MODULE(RNIModalView)

#ifndef RCT_NEW_ARCH_ENABLED
- (UIView *)view
{
return [[RNIModalView new] initWithBridge:self.bridge];
}
#endif

@end

4 changes: 2 additions & 2 deletions src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export { default as IosModalView } from './IosModalViewNativeComponent';
export * from './IosModalViewNativeComponent';
// TEMP
export * from './native_components/RNIModalView';
41 changes: 41 additions & 0 deletions src/native_components/RNIModalView/RNIModalView.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import * as React from 'react';

import { RNIModalNativeView } from './RNIModalNativeView';

import type {
RNIContextMenuViewProps,
RNIModalViewRef,
StateReactTag,
StateViewID
} from './RNIModalViewTypes';

export const RNIModalView = React.forwardRef<
RNIModalViewRef,
RNIContextMenuViewProps
>((props, ref) => {

const [viewID, setViewID] = React.useState<StateViewID>();
const [reactTag, setReactTag] = React.useState<StateReactTag>();

React.useImperativeHandle(ref, () => ({
getReactTag: () => {
return reactTag;
},
getViewID: () => {
return viewID;
},
}));

return (
<RNIModalNativeView
{...props}
onDidSetViewID={(event) => {
setViewID(event.nativeEvent.viewID);
setReactTag(event.nativeEvent.reactTag);
props.onDidSetViewID?.(event);
}}
>
{props.children}
</RNIModalNativeView>
);
});
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import codegenNativeComponent from 'react-native/Libraries/Utilities/codegenNati
import type { HostComponent, ViewProps } from 'react-native';

interface NativeProps extends ViewProps {
}
};

export default codegenNativeComponent<NativeProps>('RNIModalView', {
excludedPlatforms: ['android'],
Expand Down
33 changes: 33 additions & 0 deletions src/native_components/RNIModalView/RNIModalViewTypes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import type { PropsWithChildren } from "react";
import type { ViewProps } from "react-native";

import type { OnDidSetViewIDEventPayload } from "react-native-ios-utilities";
import type { RNIModalNativeViewProps } from "./RNIModalNativeView";

export type StateViewID = OnDidSetViewIDEventPayload['viewID'] | undefined;
export type StateReactTag = OnDidSetViewIDEventPayload['reactTag'] | undefined;

export type RNIModalViewRef = {
getViewID: () => StateViewID;
getReactTag: () => StateReactTag;
};

export type RNIModalViewInheritedOptionalProps = Partial<Pick<RNIModalNativeViewProps,
| 'onDidSetViewID'
>>;

export type RNIModalViewInheritedRequiredProps = {};

export type RNIModalViewInheritedProps =
RNIModalViewInheritedOptionalProps
& RNIModalViewInheritedRequiredProps;

export type RNIModalViewBaseProps = {
// TBA
};

export type RNIContextMenuViewProps = PropsWithChildren<
RNIModalViewInheritedProps
& RNIModalViewBaseProps
& ViewProps
>;
3 changes: 2 additions & 1 deletion src/native_components/RNIModalView/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from './RNIModalNativeView';
export * from './RNIModalView';
export * from './RNIModalViewTypes';

0 comments on commit 1e23d7b

Please sign in to comment.