【问题标题】:Is the NativeBase default theme dark mode-compatible?NativeBase 默认主题暗模式兼容吗?
【发布时间】:2022-07-19 00:58:24
【问题描述】:

NativeBase docs say:

默认情况下,大多数组件都兼容暗模式。

但我没有看到这个。

比如这个<Input />:

import {FormControl, Input, ScrollView} from 'native-base';

function Form(): JSX.Element {
  return (
    <ScrollView>
      <FormControl.Label>Description</FormControl.Label>
      <Input placeholder="Placeholder" />
    </ScrollView>
  );
}

在亮模式和暗模式下看起来都一样:

(我用NativebaseProvider包裹了我的树。)

【问题讨论】:

    标签: native-base


    【解决方案1】:

    为了让 NativeBase 使用系统颜色模式,在撰写本文时 (v3.4.1),您必须将 useSystemColorMode 设置为 true

    const customTheme = extendTheme({
      config: {
          useSystemColorMode: true,
      },
    });
    

    并将自定义主题传递给NativeBaseProvider(默认情况下,useSystemColorModefalse)。否则你可以自己设置initialColorMode:

    const customTheme = extendTheme({
      config: {
          initialColorMode: 'light',
      },
    });
    

    并与Appearance#addChangeListener()useColorScheme() 手动保持同步。

    【讨论】:

      猜你喜欢
      • 2021-12-09
      • 1970-01-01
      • 1970-01-01
      • 2014-04-18
      • 1970-01-01
      • 1970-01-01
      • 2013-09-29
      • 1970-01-01
      • 2021-02-16
      相关资源
      最近更新 更多