关闭通过 Plaid SDK 打开的 UINavigationController

Dismissing UINavigationController opened via Plaid SDK

提问人:joel-stewart 提问时间:3/29/2021 最后编辑:joel-stewart 更新时间:4/1/2021 访问量:296

问:

我在将 Plaid SDK 集成到我们现有的 React Native 应用程序中遇到了障碍。

我们在 AppDelegate 中有一些较旧的代码,这些代码将 root 包装在 .当我们调用 Plaid SDK 时,这会导致一个问题,因为您无法正确关闭 Plaid 界面。UINavigationController

我试图弄清楚是否可以在使用 时通过 Plaid 关闭按钮关闭整个视图。UINavigationController

如果这很明显,我深表歉意,我仍在学习原生 iOS 和 Android 堆栈,并且花了一段时间寻找解决方案但没有成功。

这是我们方法端的一个片段:didFinishLaunchingWithOptionsAppDelegate.m

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
#ifdef FB_SONARKIT_ENABLED
  InitializeFlipper(application);
#endif

  RCTBridge *bridge = [[RCTBridge alloc] initWithDelegate:self launchOptions:launchOptions];
  RCTRootView *rootView = [[RCTRootView alloc] initWithBridge:bridge
                                                   moduleName:@"plaidRNDemo"
                                            initialProperties:nil];

  self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
  rootView.backgroundColor = [[UIColor alloc] initWithRed:1.0f green:1.0f blue:1.0f alpha:1];
  
  self.reactViewController = [UIViewController new];
  self.reactViewController.view = rootView;
  UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:self.reactViewController];
  navigationController.delegate = self;
  if (@available(iOS 13.0, *)) {
    self.window.overrideUserInterfaceStyle = UIUserInterfaceStyleLight;
    navigationController.navigationBar.barStyle = UIBarStyleDefault;
  }
  
  self.window.rootViewController = navigationController;
  [self.window makeKeyAndVisible];

  return YES;
}

点击此处的关闭按钮不会按预期关闭屏幕,而是最终进入下面屏幕截图右侧的状态,并显示空白屏幕(可能是空视图)。

错误状态:

enter image description here

以下是我们不用于创建正常工作的视图的相同代码片段,点击关闭按钮可关闭整个视图:AppDelegate.mUINavigationController

{
#ifdef FB_SONARKIT_ENABLED
  InitializeFlipper(application);
#endif

  RCTBridge *bridge = [[RCTBridge alloc] initWithDelegate:self launchOptions:launchOptions];
  RCTRootView *rootView = [[RCTRootView alloc] initWithBridge:bridge
                                                   moduleName:@"plaidRNDemo"
                                            initialProperties:nil];

  self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];

  UIViewController *rootViewController = [UIViewController new];
  rootViewController.view = rootView;
  self.window.rootViewController = rootViewController;
  [self.window makeKeyAndVisible];
  return YES;
}

点击此处的关闭按钮可成功关闭整个视图,并导致以下屏幕截图中右侧的状态。不幸的是,我确实需要将其与现有实现一起使用。我希望有一种简单的方法可以在点击 SDK 中的关闭按钮时触发整个视图的关闭。

成功状态:

enter image description here

如果有人能在这里提供任何帮助,我将不胜感激 🙏

触发 SDK 的 Javascipt 代码如下所示:

import React, { useEffect } from "react";
import { View } from "react-native";
import { PlaidLink, LinkSuccess, LinkExit } from "react-native-plaid-link-sdk";
import { useDispatch, useSelector } from "react-redux";

import {
  LoadingContainer,
  Button,
} from "sharedComponents";
import {
  getPlaidLinkToken,
  handlePlaidExit,
} from "app/orders/bankAccount/bankAccountActions";
import { getBankAccountLinkingToken } from "app/orders/bankAccount/bankAccountSelectors";

const AddBankAccountContainer = () => {
  const dispatch = useDispatch();
  const linkingToken: string = useSelector(getBankAccountLinkingToken) ?? "";
  const onSuccess = (success: LinkSuccess) =>
  dispatch(handlePlaidSuccess(success));
const onExit = (exit: LinkExit) => dispatch(handlePlaidExit(exit));

  useEffect(() => {
    dispatch(getPlaidLinkToken());
  }, [dispatch]);

  return (
    <LoadingContainer>
      ...
      <View style={[s.mt4, s.flx_i, s.jcfe, s.mb5]}>
        <PlaidLink
          tokenConfig={{
            token: linkingToken,
          }}
          onSuccess={onSuccess}
          onExit={onExit}
        >
          <Button I18nId={"bankAccount.addBank.cta"} />
        </PlaidLink>
      </View>
    </LoadingContainer>
  );
};

export default AddBankAccountContainer;

这个组件是通过 react-navigation 导航到的:

import { createStackNavigator } from "react-navigation-stack";

const bottomTabScreens = {
  profileTab: {
    path: "profile",
    screen: createStackNavigator(
      ...
      {
        addBankAccount: {
          path: "bankAccount/add",
          screen: AddBankAccountContainer,
        },
      },
   },
}

const MainNavigator = createStackNavigator(scenes, {
  mode: "modal",
  defaultNavigationOptions: () => ({
    animationEnabled: !isTest,
    cardStyleInterpolator: forFade,
    transitionSpec: modalTransitionSpec,
    headerShown: false,
  }),
});

const AppNavigator = createAppContainer(MainNavigator);

Objective-C UIAningController 反应原生-iOS Plaid

评论


答:

0赞 Aaron 4/1/2021 #1

使用 ,导航到您希望用户在 Link 退出后看到的页面。这可以通过添加到 和 处理程序来完成MainNavigatornavigation.pop();onSuccessonExitAddBankAccountContainer

评论

0赞 joel-stewart 4/1/2021
谢谢 Aaron,我实际上在 和 actions 中执行其他操作,但它并没有解决实际关闭 UINavigationController 视图的问题。我将根据此 repos 示例文件夹中的相同代码,在 react-native-plaid-link-sdk 存储库下创建一个具有简单可重现版本的问题。谢谢!handlePlaidSuccesshandlePlaidExit