Skip to content

Commit

Permalink
🛠 Refactor - Replace RCT Prefix with RNI
Browse files Browse the repository at this point in the history
  • Loading branch information
dominicstop committed Mar 12, 2022
1 parent 5b05515 commit 7bec052
Show file tree
Hide file tree
Showing 10 changed files with 34 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@

import Foundation

enum RCTPopoverSize {
enum RNIPopoverSize {
case INHERIT;
case STRETCH;
case CUSTOM(width: CGFloat, height: CGFloat);

static let stringMap: [String: RCTPopoverSize] = [
static let stringMap: [String: RNIPopoverSize] = [
"INHERIT": .INHERIT,
"STRETCH": .STRETCH,
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import UIKit;

typealias Completion = ((_ success: Bool, _ message: String?) -> ());

class RCTPopoverView: UIView {
class RNIPopoverView: UIView {

// ----------------
// MARK: Properties
Expand All @@ -22,13 +22,13 @@ class RCTPopoverView: UIView {
var reactPopoverView: UIView?;

/// the view controller that holds/manages the popover content
private var _popoverController: RCTPopoverViewControlller?;
private var _popoverController: RNIPopoverViewController?;

/// returns the current popover vc instance (or init. it first if it's nil)
var popoverController: RCTPopoverViewControlller {
var popoverController: RNIPopoverViewController {
// get popover vc, or init it first if its nil
let popoverVC = self._popoverController ?? {
let vc = RCTPopoverViewControlller();
let vc = RNIPopoverViewController();

// setup popover vc
vc.reactPopoverView = self.reactPopoverView;
Expand Down Expand Up @@ -90,7 +90,7 @@ class RCTPopoverView: UIView {
// MARK: RN Exported Props
// -----------------------

private var _popoverSize: RCTPopoverSize = .INHERIT;
private var _popoverSize: RNIPopoverSize = .INHERIT;
@objc var popoverSize: NSDictionary? {
didSet {
guard let dictionary = self.popoverSize,
Expand Down Expand Up @@ -204,7 +204,7 @@ class RCTPopoverView: UIView {
// MARK:- Private Functions
// ------------------------

fileprivate extension RCTPopoverView {
fileprivate extension RNIPopoverView {
func popoverViewNotifyForBoundsChange(_ newBounds: CGRect){
guard let bridge = self.bridge,
let reactView = self.reactPopoverView
Expand All @@ -226,7 +226,7 @@ fileprivate extension RCTPopoverView {
// MARK:- Functions for View Manager/Module
// ----------------------------------------

extension RCTPopoverView {
extension RNIPopoverView {
/// show or hide the popover
func setVisibility(_ visibility: Bool, completion: Completion? = nil) {
guard self.isPopoverVisible != visibility,
Expand Down Expand Up @@ -271,7 +271,7 @@ extension RCTPopoverView {
// MARK:- UIPopoverPresentationControllerDelegate
// ----------------------------------------------

extension RCTPopoverView: UIPopoverPresentationControllerDelegate {
extension RNIPopoverView: UIPopoverPresentationControllerDelegate {

func adaptivePresentationStyle(for controller: UIPresentationController) -> UIModalPresentationStyle {
// force to use popover on iPhone
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@

import UIKit;

class RCTPopoverViewControlller: UIViewController {
class RNIPopoverViewController: UIViewController {

/// the content to show in the popover
var reactPopoverView: UIView?;

/// called whenever the popover view's bound changes
var boundsDidChangeBlock: ((CGRect) -> Void)?;

var popoverSize: RCTPopoverSize = .INHERIT {
var popoverSize: RNIPopoverSize = .INHERIT {
didSet {
self.setPopoverSize();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#import <React/RCTViewManager.h>


@interface RCT_EXTERN_MODULE(RCTPopoverViewManager, RCTViewManager)
@interface RCT_EXTERN_MODULE(RNIPopoverViewManager, RCTViewManager)

// ---------------------------
// MARK: Export Props - Events
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@

import Foundation

@objc(RCTPopoverViewManager)
class RCTPopoverViewManager: RCTViewManager {
@objc(RNIPopoverViewManager)
class RNIPopoverViewManager: RCTViewManager {

static var sharedBridge: RCTBridge? {
didSet {
#if DEBUG
print("RCTPopoverView, sharedBridge: didSet");
NotificationCenter.default.addObserver(RCTPopoverViewManager.self,
NotificationCenter.default.addObserver(RNIPopoverViewManager.self,
selector: #selector(Self.resetSharedBridge),
name: NSNotification.Name(rawValue: "RCTBridgeWillReloadNotification"),
object: nil
Expand All @@ -41,13 +41,13 @@ class RCTPopoverViewManager: RCTViewManager {
Self.sharedBridge = self.bridge;
};

return RCTPopoverView(bridge: self.bridge);
return RNIPopoverView(bridge: self.bridge);
};

@objc func setVisibility(_ node: NSNumber, visibility: Bool){
DispatchQueue.main.async {
guard let view = self.bridge.uiManager.view(forReactTag: node),
let popoverView = view as? RCTPopoverView
let popoverView = view as? RNIPopoverView
else { return };

popoverView.setVisibility(visibility);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

#import "React/RCTBridgeModule.h"

@interface RCT_EXTERN_REMAP_MODULE(PopoverModule, RCTPopoverViewModule, NSObject)
@interface RCT_EXTERN_MODULE(RNIPopoverViewModule, NSObject)

RCT_EXTERN_METHOD(setVisibility: (nonnull NSNumber *)node
visibility : (nonnull BOOL *)visibility
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

import Foundation

@objc(RCTPopoverViewModule)
class RCTPopoverViewModule: NSObject {
@objc(RNIPopoverViewModule)
class RNIPopoverViewModule: NSObject {

@objc static func requiresMainQueueSetup() -> Bool {
return false;
Expand All @@ -22,12 +22,12 @@ class RCTPopoverViewModule: NSObject {
) {

DispatchQueue.main.async {
guard let bridge = RCTPopoverViewManager.sharedBridge,
guard let bridge = RNIPopoverViewManager.sharedBridge,
let view = bridge.uiManager?.view(forReactTag: node),
let popoverView = view as? RCTPopoverView
let popoverView = view as? RNIPopoverView
else {
let errorMessage = (
"RCTPopoverViewModule: setVisibility(\(visibility))"
"RNIPopoverViewModule: setVisibility(\(visibility))"
+ " - guard check failed"
+ " - could not get `popoverView` instance"
);
Expand All @@ -39,15 +39,15 @@ class RCTPopoverViewModule: NSObject {

popoverView.setVisibility(visibility) { success, message in
#if DEBUG
print("RCTPopoverViewModule, setVisibility: \(visibility)");
print("RNIPopoverViewModule, setVisibility: \(visibility)");
#endif

if success {
resolve([:]);

} else {
let errorMessage = (
"RCTPopoverViewModule: setVisibility(\(visibility))"
"RNIPopoverViewModule: setVisibility(\(visibility))"
+ " - failed: \(message ?? "N/A")"
);

Expand All @@ -65,12 +65,12 @@ class RCTPopoverViewModule: NSObject {
) {

DispatchQueue.main.async {
guard let bridge = RCTPopoverViewManager.sharedBridge,
guard let bridge = RNIPopoverViewManager.sharedBridge,
let view = bridge.uiManager?.view(forReactTag: node),
let popoverView = view as? RCTPopoverView
let popoverView = view as? RNIPopoverView
else {
let errorMessage = (
"RCTPopoverViewModule: getVisibility()"
"RNIPopoverViewModule: getVisibility()"
+ " - guard check failed"
+ " - could not get `popoverView` instance"
);
Expand All @@ -81,7 +81,7 @@ class RCTPopoverViewModule: NSObject {
};

#if DEBUG
print("RCTPopoverViewModule, getVisibility: \(popoverView.isPopoverVisible)");
print("RNIPopoverViewModule, getVisibility: \(popoverView.isPopoverVisible)");
#endif

resolve(popoverView.isPopoverVisible);
Expand Down
2 changes: 1 addition & 1 deletion src/components/PopoverView/PopoverView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react';
import { StyleSheet, findNodeHandle, View, processColor } from 'react-native';

import { RNIPopoverView } from '../../native_components/RNIPopoverView';
import { RNIPopoverViewModule } from '../../native_modules/PopoverViewModule';
import { RNIPopoverViewModule } from '../../native_modules/RNIPopoverViewModule';

import type { PopoverViewProps, PopoverViewState } from './PopoverViewTypes';
import type { OnPopoverDidHideEvent } from '../../types/PopoverViewEvents';
Expand Down
2 changes: 1 addition & 1 deletion src/native_components/RNIPopoverView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export type RNIPopoverViewProps = ViewProps & {
onPopoverDidAttemptToDismiss?: OnPopoverDidAttemptToDismissEvent;
};

const viewName = 'RCTPopoverView';
const viewName = 'RNIPopoverView';

/**
* Do not use `RNIContextMenuView` if platform is not iOS.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ interface RNIPopoverViewModule {
getVisibility(node: number): Promise<boolean>;
};

const MODULE_NAME = "PopoverModule";
const MODULE_NAME = "RNIPopoverViewModule";

export const RNIPopoverViewModule: RNIPopoverViewModule =
NativeModules[MODULE_NAME];

0 comments on commit 7bec052

Please sign in to comment.