React native 在android的特定屏幕中请求权限

React native 在android的特定屏幕中请求权限,react-native,android-permissions,react-native-navigation-v2,React Native,Android Permissions,React Native Navigation V2,对于react本机应用程序导航,我使用react本机导航v2。在这里,我创建了带有底部选项卡的导航。这是导航处理程序 import { Navigation } from "react-native-navigation"; import { width, height } from "../utils/screenResolution"; import { bottomTabIcon, topBarOpts } from "../components"; const sideBarWidth

对于react本机应用程序导航,我使用react本机导航v2。在这里,我创建了带有底部选项卡的导航。这是导航处理程序

import { Navigation } from "react-native-navigation";
import { width, height } from "../utils/screenResolution";
import { bottomTabIcon, topBarOpts } from "../components";

const sideBarWidth = width * 0.65;

export const goToAuth = () =>
  Navigation.setRoot({
    root: {
      stack: {
        id: "AuthNav",
        children: [
          {
            component: {
              name: "SignInScreen",
              options: {
                topBar: { visible: false, height: 0 }
              }
            }
          }
        ]
      }
    }
  });

export const goHome = async () => {
  let icon1 = await bottomTabIcon("CollectionScreen", "Collection", "archive");
  let icon2 = await bottomTabIcon("MainScreen", "Home", "home");

  let icon3 = await bottomTabIcon("CaptureScreen", "Capture", "camera");
  Navigation.setRoot({
    root: {
      sideMenu: {
        right: {
          component: {
            name: "SideBar"
          }
        },
        center: {
          bottomTabs: {
            id: "AppNav",
            children: [icon1, icon2, icon3]
          }
        },
        options: {
          sideMenu: {
            right: {
              width: sideBarWidth
            }
          }
        }
      }
    }
  });
  Navigation.mergeOptions("MainScreen", {
    bottomTabs: {
      currentTabIndex: 1
    }
  });
};
使用此底部选项卡图标功能创建图标选项卡

import Icon from "react-native-vector-icons/FontAwesome";
import { topBarOpts } from "./";
import { PRIMARY, BOTTOM_TAB_BACKGROUND, TAB_ICON } from "../../assets/color";

let bottomTabIcon = async (name, text, iconName) => {
  let icon = {
     stack: {
       children: [
         {
    component: {
      name: name,
      id: name,
      options: {
        bottomTab: {
          text: text,
          fontSize: 12,
          selectedIconColor: PRIMARY,
          iconColor: TAB_ICON,
          icon: await Icon.getImageSource(iconName, 20)
        }
      }
    }
         }
      ]
    }
  };

  if (name === "CaptureScreen") {
    icon.stack.children[0].component.options.bottomTabs = {
      visible: false,
      drawBehind: true,
      animate: true
    };
    icon.stack.children[0].component.options.topBar = {
      visible: false,
      height: 0
    };
  } else {
    icon.stack.children[0].component.options.bottomTabs = {
      backgroundColor: BOTTOM_TAB_BACKGROUND
    };
    icon.stack.children[0].component.options.topBar = await topBarOpts("Example");
  }

  return icon;
};

export { bottomTabIcon };

问题是,当用户登录应用程序时,它会在主屏幕中请求权限(摄像头、音频等)。我想在特定屏幕中执行此操作,然后我发现底部选项卡中的所有屏幕都已安装。因此,如果我调用componentDidMount in CaptureScreen中的某项操作,它将在主屏幕中工作。我如何解决此问题?我是react native的新手,因此您可以在这段代码中发现一些奇怪的东西。感谢您的帮助和关注。

仅在特定屏幕的did装载中或在父屏幕或导航器中不需要权限的子屏幕中拥有权限调用


在您的情况下,通过在react导航中获取路由索引来调用它们。在子屏幕上或需要权限的位置添加权限代码,它们将开始工作。

感谢您的回答,问题来自导航,我的意思是,中的所有屏幕实际上都已安装,如果我现在在“Main Screen”中,并且如果我在componentDidMount中的“CaptureScreen”中运行某些功能,它将在Main Screen中工作。我已尝试按照您所说的做,并在“Main Screen”中请求权限,但我需要在“CaptureScreen”中使用它们