Skip to content

Commit

Permalink
🛠 Refactor: Remove View Manager Commands
Browse files Browse the repository at this point in the history
Summary: Remove view manager commands usage from `RNIModalView` and `ModalView`.
  • Loading branch information
dominicstop committed Jan 6, 2023
1 parent bc36ea5 commit 52f6afe
Show file tree
Hide file tree
Showing 6 changed files with 1 addition and 126 deletions.
48 changes: 0 additions & 48 deletions ios/src_library/React Native/RNIModalView/RNIModalView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -472,54 +472,6 @@ extension RNIModalView {
completion?(true, nil);
self.onRequestResult?(params);
};

// --------------------------------------
// MARK: Public Functions for ViewManager
// --------------------------------------

// called by RNIModalViewManager
// set isModalInPresentation for this modal from RN
public func requestModalPresentation(
_ requestID : NSNumber,
_ visibility: Bool ,
completion: CompletionHandler? = nil
){
var params: Dictionary<AnyHashable, Any> = [
"requestID" : requestID ,
"visibility": visibility,
];

self.createModalNativeEventDict().forEach { (key, value) in
params[key] = value
};

let modalAction = visibility
? self.presentModal
: self.dismissModal

modalAction(){ (success, error) in
params["success"] = success;
if let errorCode = error {
params["errorCode" ] = errorCode.rawValue;
params["errorMessage"] = RNIModalViewError.getErrorMessage(for: errorCode);
};

completion?(success, error);
self.onRequestResult?(params);
};
};

public func requestModalInfo(
_ requestID : NSNumber,
completion: CompletionHandler? = nil
){
var params = self.createModalNativeEventDict();
params["success" ] = true;
params["requestID"] = requestID;

completion?(true, nil);
self.onRequestResult?(params);
};
};

// MARK: - Internal Functions
Expand Down
15 changes: 0 additions & 15 deletions ios/src_library/React Native/RNIModalView/RNIModalViewManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -36,20 +36,5 @@ @interface RCT_EXTERN_MODULE(RNIModalViewManager, RCTViewManager)
RCT_EXPORT_VIEW_PROPERTY(modalBGBlurEffectStyle, NSString);
RCT_EXPORT_VIEW_PROPERTY(modalPresentationStyle, NSString);

// ---------------------------
// MARK: View Manager Commands
// ---------------------------

RCT_EXTERN_METHOD(requestModalPresentation
: (nonnull NSNumber *)node
requestID : (nonnull NSNumber *)requestID
visibility: (nonnull BOOL *)visibility
);

RCT_EXTERN_METHOD(requestModalInfo
: (nonnull NSNumber *)node
requestID : (nonnull NSNumber *)requestID
);

@end

Original file line number Diff line number Diff line change
Expand Up @@ -52,53 +52,6 @@ class RNIModalViewManager: RCTViewManager {
.availableStyles.map { $0.stringDescription() },
];
};

@objc func requestModalPresentation(_ node: NSNumber, requestID: NSNumber, visibility: Bool){
DispatchQueue.main.async {
guard
let component = self.bridge.uiManager.view(forReactTag: node),
let modalView = component as? RNIModalView
else {
#if DEBUG
print("RNIModalViewManager, requestModalOpen failed");
#endif
return;
};

#if DEBUG
print(
"RNIModalViewManager, requestModalOpen Received - "
+ "prevVisibility: \(modalView.isPresented) and nextVisibility: \(visibility) - "
+ "For node: \(node) and requestID: \(requestID)"
);
#endif

modalView.requestModalPresentation(requestID, visibility);
};
};

@objc func requestModalInfo(_ node: NSNumber, requestID: NSNumber){
DispatchQueue.main.async {
guard
let component = self.bridge.uiManager.view(forReactTag: node),
let modalView = component as? RNIModalView
else {
#if DEBUG
print("RNIModalViewManager, requestModalInfo failed");
#endif
return;
};

#if DEBUG
print(
"RNIModalViewManager, requestModalInfo Received - "
+ "For node: \(node) and requestID: \(requestID)"
);
#endif

modalView.requestModalInfo(requestID);
};
};
};

// ---------------------------------
Expand Down
2 changes: 0 additions & 2 deletions src/ModalView.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import React from 'react';
import Proptypes from 'prop-types';

import {
UIManager,
findNodeHandle,
StyleSheet,
View,
Expand All @@ -19,7 +18,6 @@ import { ModalContext } from './context/ModalContext';

import {
RNIModalView,
RNIModalViewCommands,
} from './native_components/RNIModalView';

import { RNIModalViewModule } from './native_modules/RNIModalViewModule';
Expand Down
4 changes: 0 additions & 4 deletions src/native_components/RNIModalView/RNIModalView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
} from 'react-native';

import type {
RNIModalViewCommandMap,
RNIModalViewConstantMap,
RNIModalViewProps,
} from './RNIModalViewTypes';
Expand All @@ -22,9 +21,6 @@ export const RNIModalView: HostComponent<RNIModalViewProps> = Platform.select({
default: () => View,
})();

export const RNIModalViewCommands = UIManager[nativeViewName]
?.Commands as RNIModalViewCommandMap;

export const RNIModalViewConstants = UIManager[nativeViewName]
?.Constants as RNIModalViewConstantMap;

Expand Down
11 changes: 1 addition & 10 deletions src/native_components/RNIModalView/RNIModalViewTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@ import type {
UIModalTransitionStyle,
} from 'src/types/UIModalTypes';

import type {
ViewManagerCommandMap,
ViewManagerConstantMap,
} from 'src/types/ViewModuleRelatedTypes';
import type { ViewManagerConstantMap } from 'src/types/ViewModuleRelatedTypes';

import type {
OnModalShowEvent,
Expand Down Expand Up @@ -58,12 +55,6 @@ export type RNIModalViewProps = ViewProps & {
onModalAttemptDismiss: OnModalAttemptDismissEvent;
};

// prettier-ignore
export type RNIModalViewCommandMap = ViewManagerCommandMap<
| 'requestModalInfo'
| 'requestModalPresentation'
>;

export type RNIModalViewConstantMap = ViewManagerConstantMap<{
availableBlurEffectStyles: UIBlurEffectStyles[];
availablePresentationStyles: UIModalPresentationStyle[];
Expand Down

0 comments on commit 52f6afe

Please sign in to comment.