Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/react-native/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 反应本色纸黑色主题_Javascript_React Native_React Native Paper - Fatal编程技术网

Javascript 反应本色纸黑色主题

Javascript 反应本色纸黑色主题,javascript,react-native,react-native-paper,Javascript,React Native,React Native Paper,如何在本地纸张中将主题设置为暗主题?在我所有的屏幕中,所有的仍然有白色背景 const theme = { ...DarkTheme, colors: { ...DarkTheme.colors, primary: '#2d3436', accent: '#1C1C1C', background : '#636e72' } }; render() { return( &

如何在本地纸张中将主题设置为暗主题?在我所有的屏幕中,所有的
仍然有白色背景

const theme = {
      ...DarkTheme,
      colors: {
        ...DarkTheme.colors,
        primary: '#2d3436',
        accent: '#1C1C1C',
        background : '#636e72'
      }
    };

render() {
   return(
      <PaperProvider theme={theme}>
         <App />
      </PaperProvider>
  );
}
const主题={
…黑暗的主题,
颜色:{
…暗色调,
主要:“#2d3436”,
重音:“#1c1c”,
背景:“#636e72”
}
};
render(){
返回(
);
}

应用主题和提供程序级别不会更改所有视图。 导出时必须使用“withTheme”,这将提供可用于访问颜色的主题道具

import { withTheme } from 'react-native-paper';
const Test = ({ theme,children }) => {
  const { colors } = theme;
  return (
    <View style={{ backgroundColor: colors.background }}>
     {children}
    </View>
  );
};

export default withTheme(Test);
从“react native paper”导入{withTheme};
常量测试=({theme,children})=>{
const{colors}=主题;
返回(
{儿童}
);
};
导出带有主题的默认值(测试);

如果要对所有视图使用相同的主题,请创建一个自定义包装器组件,该组件将设置如上所述的颜色

是否有方法从样式表文件访问主题?我的组件通常有单独的样式表文件,能够直接在样式表中访问我在主题中设置的颜色将非常有用。正如我所知,主题是通过上下文传递的,因此您需要通过组件访问。看起来我可以做到这一点:
。我通过这样做来访问颜色:
const{colors}=theme