小编Mic*_*ger的帖子

React Native:如何正确输入嵌套导航器?

情况:

正如您可能知道的那样,我目前正在构建一个有声读物播放器(多么有创意)。这是我第一个针对反应原生和打字稿的更大项目,在正确输入导航方面我有点挣扎。首先:这是一个快速概述:

在此输入图像描述

疑问/问题:

  1. 感觉我使用了太多嵌套导航器,但由于我没有任何经验,所以很难判断。你怎么认为?如果我使用太多,我应该如何重组?(文档提到了组,但我不知道如何在这里实现)
  2. 如何正确键入我的组件?到目前为止我的做法如下(LibraryStack 自下而上的视角):
// 1. I created a type for the Screen routes (including the passed down props)
type LibraryRoutes = {
  Library: undefined;
  BookDetails: { album: Album };
  BookSettings: { album: Album };
};

// 2. A type for the different Routes (using NavigatorScreenParams, but I'm not sure I use them correctly)
// This then goes up the same way up to the root
type TabRoutes = {
  HomeStack: NavigatorScreenParams<HomeRoutes>;
  LibraryStack: NavigatorScreenParams<LibraryRoutes>;
  ...etc.
}; …
Run Code Online (Sandbox Code Playgroud)

typescript reactjs react-native typescript-typings react-navigation

8
推荐指数
1
解决办法
880
查看次数

TypeError: null 不是对象(正在评估 'TrackPlayer.RATING_HEART') &amp;&amp; Module AppRegistry 不是已注册的可调用模块

在过去 1.5 天左右的时间里,我试图让 React-native-track-player 工作,但我就是无法实现它。无论我尝试什么,我总是会遇到相同的错误块:

\n
ERROR  TypeError: null is not an object (evaluating \'TrackPlayer.RATING_HEART\')\nERROR  Invariant Violation: Module AppRegistry is not a registered callable module (calling runApplication). A frequent cause of the error is that the application entry file path is incorrect. \n      This can also happen when the JS bundle is corrupt or there is an early initialization error when loading React Native.\n
Run Code Online (Sandbox Code Playgroud)\n

我使用react-native expo和 “正常” react-native(根据react-native docu)设置它。对于我尝试过的所有变体:JSTS

\n
    \n
  • 删除/重新安装节点模块
  • \n …

android reactjs react-native react-native-track-player

2
推荐指数
1
解决办法
5005
查看次数

React Native - 提供全局主题的最佳方式是什么?

我最近开始使用 RN,并一直在对主题和/或暗光模式的实现进行一些研究。到目前为止,我大致了解两个主要选项:

  • 上下文:设置简单,可以通过需要它的组件内的钩子进行访问。我计算了像 React Navigation 主题这样的东西,因为本质上它的工作方式是相同的(?)
  • 样式化组件:本质上只是将组件替换为访问当前主题的自定义组件,然后可以根据需要进行设置以更改其切换属性。

我不喜欢上下文的是(按照我的理解)它不允许我在使用样式表时访问主题,因为它位于组件之外。另一方面,对于样式化组件,我不确定是否可以覆盖自定义组件中的所有选项,是否仍然需要在每个组件中添加某种钩子?

我还在考虑将当前主题保存到我的商店(在我的例子中是 Zustand),以及一个让我切换到黑暗模式的操作。但到目前为止,我还没有看到其他人这样做,这样做有什么缺点吗?

themes react-native

2
推荐指数
1
解决办法
2524
查看次数