NativeBase 自定义主题不适用

问题描述 投票:0回答:0

我是 React Native 的新手,我目前正在使用 nativebase,我使用 extendTheme 制作的自定义主题不适用,这里是相关的代码片段

App.tsx

import React from 'react';
import theme from './src/constants/ThemeFile';
import {NativeBaseProvider} from 'native-base';
import {Component1} from './src/views/Screen1';

function App(): JSX.Element {
  return (
    <NativeBaseProvider theme={theme}>
      <Screen1 />
    </NativeBaseProvider>
  );
}

export default App;

Themefile.tsx

import {extendTheme} from 'native-base';

const theme = extendTheme({
  colors: {
    backgroundColor: '#000000',
    brand: {
      500: '#d53235',
    },
  },
  fonts: {
    heading: 'mark-pro--bold',
    body: 'mark-pro--bold',
    mono: 'mark-pro--bold',
  },
  config: {
    initialColorMode: 'dark',
  },
});

export default theme;

Component1.tsx

import {Box, Heading} from 'native-base';
import React from 'react';

export function Component1(): JSX.Element {
  return (
    <Box
      bg="primary.400"
      height="25%"
      alignItems="center"
      justifyContent="center">
      <Heading textAlign="center" size="2xl">
        Just a Heading
      </Heading>
    </Box>
  );
}

(bg=primary.400 仅用于调试目的,因为字体已更改为白色,但背景颜色也保持白色,我已使用正常的反应本机文本验证字体已正确设置)

预期行为: 整个屏幕的背景颜色为黑色,仅使用 mark pro 字体呈现标题

当前行为:

android react-native native-base
© www.soinside.com 2019 - 2024. All rights reserved.