iOS navite 框架 View 推送不适用于 react-native 应用程序

标签 ios objective-c react-native react-native-ios ios-frameworks

我无法让 react native 应用程序从 iOS native 框架推送新 Controller 。我试图将它包装到一个 react native 库中,并且我设法显示了基本 View ,但是当我与它交互时,不会推送新屏幕。是否可以在位于 native 框架中的 native 屏幕之间导航?

我使用 react-native-create-library 成功地将框架包装到 react-native 库中。我能够显示基本 View ,并且当单击在同一屏幕上显示 View 的按钮(例如日期选择器)时,它工作正常。但是当我点击一个应该推送新 View Controller 的按钮时,它不会使用react。

我正在将它测试成一个虚拟的全新 react-native 应用程序,并将 AppDelegate.m 更改为使用 UINaVigationController 而不是默认的 UIViewController,如下:

UIViewController *rootViewController = [UIViewController new];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:rootViewController];

[[RNHellLib sharedInstance] configureSDK: navigationController];

然后在我的图书馆里我这样做:

- (dispatch_queue_t)methodQueue
{
    return dispatch_get_main_queue();
}

RCT_EXPORT_MODULE(RNSearchBox)
RCT_EXPORT_VIEW_PROPERTY(rootController, UIViewController)

SearchBox *mySearchBox;

- (UIView *)view {
    return mySearchBox;
}

+ (instancetype)sharedInstance {
    static RNHellLib *sharedInstance = nil;
    static dispatch_once_t onceToken = 0;
    dispatch_once(&onceToken, ^{
        sharedInstance = [[RNHellLib alloc] init];

    });
    return sharedInstance;
}

- (void) configureSDK: (UINavigationController *)rootController {
    mySearchBox = [[SearchBox alloc] init];
    mySearchBox.rootController = rootController;
}

在 SDK 方面,我正在使用 viewController.show(viewControllerToBePushed, sender) 推送新的 View Controller ,并且还尝试使用 viewController.present(viewControllerToBePushed, animation: true),但屏幕不会发生任何变化。

我读过大量文档和教程,它们使用 react 导航或类似库在 react native 屏幕之间以及在构建到同一应用程序中的现有(和已知)快速 View 之间导航。但这意味着 reat-native 端必须提前知道我们在与元素交互时显示的 View ,而不是让框架自己作为一个“黑盒子”工作。

这可能吗?它能否像在其他 native 应用程序中一样作为“黑匣子”工作?或者我需要强制公开所有 View Controller 并从 JSX 手动触发它们?

最佳答案

我还没有自己实现它,但它在以下库中对我来说工作正常 https://github.com/troublediehard/react-native-braintree-xplat

不久

// RCTBraintree.h

@interface RCTBraintree : UIViewController <RCTBridgeModule, ...>

@property (nonatomic, strong) UIViewController *reactRoot;
...

@end


//  RCTBraintree.m

#import "RCTBraintree.h"

@implementation RCTBraintree

...


RCT_EXPORT_METHOD(showApplePayViewController:(NSDictionary *)options callback:(RCTResponseSenderBlock)callback)
{
    dispatch_async(dispatch_get_main_queue(), ^{
        ...

        PKPaymentAuthorizationViewController *viewController = [[PKPaymentAuthorizationViewController alloc] initWithPaymentRequest:paymentRequest];
        viewController.delegate = self;

        [self.reactRoot presentViewController:viewController animated:YES completion:nil];
    });
}

...

- (UIViewController*)reactRoot {
    UIViewController *root  = [UIApplication sharedApplication].keyWindow.rootViewController;
    UIViewController *maybeModal = root.presentedViewController;

    UIViewController *modalRoot = root;

    if (maybeModal != nil) {
        modalRoot = maybeModal;
    }

    return modalRoot;
}

...

@end

关于iOS navite 框架 View 推送不适用于 react-native 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57554169/

相关文章:

javascript - react 导航 goBack 不起作用

javascript - react native 抽屉菜单: can`t find variable styles

android - React Native - 带有新项目的意外标识符 'str'

ios - 在 swift 2 : cannot trigger calloutAccessoryControlTapped for clicks on map annotation

ios - Swift:重构 viewController 以将数据传递到另一个 Controller

objective-c - 复制自定义对象

ios - NSFetchedResultsController创建objc_exception_throw时崩溃

objective-c - 阻止 UIPopover 自动关闭第二部分

ios - 合并两个xcode项目并根据条件运行

ios - 使用 SDK 7.1.0 版测试 AdMob 广告出现在 iOS 模拟器上