如何知道React Native中哪个屏幕专注于屏幕级别?

时间:2019-07-10 04:59:27

标签: reactjs react-native react-navigation

我想知道如何在使用 const userController = require('../userController'); const User = require('../../models/users'); const passport = require('passport'); jest.mock('../../models/users'); jest.mock('passport'); describe.only('Register user succeeds', () => { let send = jest.fn(); let status = jest.fn(); let next = jest.fn(); let res = { send, status }; afterEach(() => { send.mockRestore(); status.mockRestore(); next.mockRestore(); }); it('should send a response', async () => { const req = { body: { email: 'mock@email.com', password: 'mockPassword', firstName: 'mockFirstName', lastName: 'mockLastName' }, logIn }; passport.authenticate.mockImplementation(() => { req, res, () => (done(null, '1', undefined)) }); User.update.mockReturnValue({}); await userController.registerUser(req, res, next); expect(res.status).toHaveBeenCalledTimes(1); expect(res.send).toHaveBeenCalledTimes(1); }); }); 时使用React Navigation检索有关哪个选项卡聚焦在屏幕级别的信息。使用(err, user, info),可以知道选项卡是否已聚焦,但如果不聚焦,则我们不知道哪个是聚焦的。 我需要的伪代码就像这样(currentRoute不存在):

createBottomTabNavigator

1 个答案:

答案 0 :(得分:0)

反应导航可显示HOC,以了解当前屏幕是否聚焦。

您可以在此处查看有关此文档的文档:https://reactnavigation.org/docs/en/with-navigation-focus.html