javascript - 如何通过组件反应原生的样式传递道具?
问题描述
我正在尝试在本机反应中制作一个深色主题按钮主题,因此我需要通过主题提供程序通过 BackgroundImage 更改图像,但是当我尝试将道具向前移动时它不起作用。
index.js
import { Background } from "./styles";
<Background source={props.backgroundImage} />
样式.js
export const Background = styled.ImageBackground.attrs(
require(props => props.theme.backgroundImage))``;
我的 app.js:
import React from "react";
import themes from './src/themes';
<ThemeProvider theme={themes.light}>
<NavigationContainer>
<MainStacks />
</NavigationContainer>
</ThemeProvider>
我的 light.js:
export default {backgroundImage: "../../../assets/background.png"}
它返回错误:Error: Cannot find module 'function (props) { return props.theme.backgroundImage; } '
解决方案
推荐阅读
- postgresql - 如何在 PostgreSQL 中一次创建数千或数百万个表?
- c - 在 Linux 中递归计算目录的最快的 C 代码(无文件)
- html - 单选按钮不会检查纯 HTML
- c# - C# 实体框架多个结果
- sql - 当 Oracle ACID 不完全遵守“隔离”属性时,它如何兼容?
- c++ - 堆栈后修复解析
- mule - Mulesoft 4,如何仅从 xml 文件中获取标签的值
- r - 将因子转换为日期时间,
2018 年 10 月 25 日(M、D、Y) - c++ - 如何让 GCC/Clang 警告未初始化成员的使用?
- shell - 如何修复已取消编辑,shell 中未进行任何更改