react-native - 无法使用自定义主题覆盖默认的 Amplify withAuthenticator 样式
问题描述
我正在尝试在我的 React Native 应用程序中自定义 AWS WithAuthenticator HOC 的样式。我一步一步地遵循了 Amplify文档。但是,应用程序会继续呈现默认样式(橙色按钮),而不是预期的自定义颜色。
import React from 'react';
import { StyleSheet, Text, View } from 'react-native';
import Amplify from '@aws-amplify/core';
import config from './aws-exports';
import { withAuthenticator } from 'aws-amplify-react-native';
import { AmplifyTheme } from 'aws-amplify-react-native';
// custom colors for components
const Mybutton = Object.assign({}, AmplifyTheme.button, { backgroundColor: '#000', });
//console.log('My own design: ', Mybutton)
const MyTheme = Object.assign({}, AmplifyTheme, { button: Mybutton });
class App extends React.Component {
render() {
return (
<View style={styles.container}>
<Text>You are now signed in!</Text>
</View>
);
}
}
export default withAuthenticator(App, { includeGreetings: true }, false, [], null, MyTheme)
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
alignItems: 'center',
justifyContent: 'center',
},
});
谁能指出我做错了什么?
解决方案
您需要像这样传递 withAuthenticator 调用:
export default withAuthenticator(App, {includeGreetings: true, theme: MyTheme});
然后它将起作用。
推荐阅读
- javascript - 在客户端之间共享状态的服务器上的单个 JS 对象中可以存储多少数据?
- r - 如何分隔单元格中的多个数值数据值并查找每列的总数?
- azure-cosmosdb - 当 CosmosDb 说 10 毫秒写入延迟时,是否包括写入请求到达 cosmosdb 服务器所需的时间?
- android - 如何在 kapt 中设置包 ID
- python - 如何使用 Python Apache Beam 解压缩 beam.Map 中的字典值
- android - 更新flutter sdk和所有包后出错
- typescript - 尝试将 Typescript 类型用于第 3 方 Javascript 库时出现错误 TS2307
- firebase - React Native - 警告:无法从不同组件的函数体内更新组件
- vue.js - 路由器链接动态 vueJS
- c# - 在 C# LINQ ASP.NET 中更新数据库表时遇到问题