当前位置: 首页 > wzjs >正文

做高仿包的能做网站吗优化公司网站排名

做高仿包的能做网站吗,优化公司网站排名,ps做网站效果图制作过程,app制作软件企业React Native 动态切换主题 创建主题配置和上下文创建主题化高阶组件主应用组件主屏幕组件(类组件形式) 创建主题配置和上下文 // ThemeContext.jsimport React, { Component, createContext } from react;import { Appearance, AsyncStorage } from rea…

React Native 动态切换主题

  • 创建主题配置和上下文
  • 创建主题化高阶组件
  • 主应用组件
  • 主屏幕组件(类组件形式)

创建主题配置和上下文

				// ThemeContext.jsimport React, { Component, createContext } from 'react';import { Appearance, AsyncStorage } from 'react-native';// 主题配置const themes = {light: {mode: 'light',primary: '#3498db',secondary: '#f39c12',background: '#ffffff',cardBackground: '#f8f9fa',text: '#333333',textSecondary: '#666666',border: '#e0e0e0',},dark: {mode: 'dark',primary: '#2ecc71',secondary: '#e74c3c',background: '#121212',cardBackground: '#1e1e1e',text: '#ffffff',textSecondary: '#bbbbbb',border: '#333333',},blue: {mode: 'blue',primary: '#2980b9',secondary: '#3498db',background: '#ecf0f1',cardBackground: '#bdc3c7',text: '#2c3e50',textSecondary: '#7f8c8d',border: '#95a5a6',}};export const ThemeContext = createContext();export class ThemeProvider extends Component {state = {theme: themes.light // 默认主题};async componentDidMount() {// 尝试加载保存的主题try {const savedTheme = await AsyncStorage.getItem('userTheme');if (savedTheme && themes[savedTheme]) {this.setState({ theme: themes[savedTheme] });} else {// 没有保存的主题则使用系统主题const systemTheme = Appearance.getColorScheme() === 'dark' ? themes.dark : themes.light;this.setState({ theme: systemTheme });}} catch (error) {console.error('加载主题失败:', error);}// 监听系统主题变化this.appearanceListener = Appearance.addChangeListener(({ colorScheme }) => {if (!this.state.userSelectedTheme) { // 如果用户没有手动选择主题this.setState({theme: colorScheme === 'dark' ? themes.dark : themes.light});}});}componentWillUnmount() {if (this.appearanceListener) {this.appearanceListener.remove();}}toggleTheme = () => {const newTheme = this.state.theme.mode === 'light' ? themes.dark : themes.light;this.setTheme(newTheme.mode);};setTheme = async (themeName) => {if (themes[themeName]) {this.setState({ theme: themes[themeName],userSelectedTheme: true });try {await AsyncStorage.setItem('userTheme', themeName);} catch (error) {console.error('保存主题失败:', error);}}};render() {return (<ThemeContext.Providervalue={{theme: this.state.theme,toggleTheme: this.toggleTheme,setTheme: this.setTheme,themes: Object.keys(themes) // 所有可用主题列表}}>{this.props.children}</ThemeContext.Provider>);}}

创建主题化高阶组件

// withTheme.js
import React from 'react';
import { ThemeContext } from './ThemeContext';export function withTheme(Component) {return function ThemedComponent(props) {return (<ThemeContext.Consumer>{context => <Component {...props} {...context} />}</ThemeContext.Consumer>);};
}

主应用组件

// App.js
import React from 'react';
import { ThemeProvider } from './ThemeContext';
import MainScreen from './MainScreen';export default class App extends React.Component {render() {return (<ThemeProvider><MainScreen /></ThemeProvider>);}
}

主屏幕组件(类组件形式)

// MainScreen.js
import React from 'react';
import { View, Text, StyleSheet, TouchableOpacity } from 'react-native';
import { withTheme } from './withTheme';class MainScreen extends React.Component {render() {const { theme, toggleTheme, setTheme, themes } = this.props;return (<View style={[styles.container, { backgroundColor: theme.background }]}><Text style={[styles.title, { color: theme.text }]}>当前主题: {theme.mode}</Text><TouchableOpacity style={[styles.button, { backgroundColor: theme.primary }]}onPress={toggleTheme}><Text style={styles.buttonText}>切换主题</Text></TouchableOpacity><View style={styles.themeOptions}>{themes.map(themeName => (<TouchableOpacity key={themeName}style={[styles.themeButton, { backgroundColor: themes[themeName].primary,marginBottom: 10}]}onPress={() => setTheme(themeName)}><Text style={styles.buttonText}>{themeName}</Text></TouchableOpacity>))}</View><View style={[styles.card, { backgroundColor: theme.cardBackground }]}><Text style={{ color: theme.text }}>这是一个卡片示例</Text><Text style={{ color: theme.textSecondary }}>次要文本颜色</Text><View style={[styles.divider, { backgroundColor: theme.border }]} /><Text style={{ color: theme.text }}>边框颜色示例</Text></View></View>);}
}const styles = StyleSheet.create({container: {flex: 1,justifyContent: 'center',alignItems: 'center',padding: 20,},title: {fontSize: 24,marginBottom: 30,fontWeight: 'bold',},button: {padding: 15,borderRadius: 8,marginBottom: 20,width: 200,alignItems: 'center',},themeButton: {padding: 12,borderRadius: 6,marginHorizontal: 5,width: 100,alignItems: 'center',},buttonText: {color: 'white',fontWeight: 'bold',},themeOptions: {flexDirection: 'row',flexWrap: 'wrap',justifyContent: 'center',marginTop: 20,marginBottom: 30,},card: {width: '90%',padding: 20,borderRadius: 10,marginTop: 20,},divider: {height: 1,width: '100%',marginVertical: 15,}
});export default withTheme(MainScreen);
http://www.dtcms.com/wzjs/465877.html

相关文章:

  • 课工场网站建设培训域名备案查询官网
  • 网站公司 模板聊城网站开发
  • 公司做网站费会计科目关键词优化怎么写
  • 怎么建设网站让国外看学前端去哪个培训机构
  • 律师行业做网站的必要性百度怎么联系客服
  • 网站插入银行支付怎么做seo方案
  • 昆明网站词排名优化百度推广方案
  • wordpress个人博客建站公司网络推广该怎么做
  • 给企业做网站推广好么黄山seo
  • aspx网站架设搜索引擎优化概述
  • 科技酒店建站优化推广
  • 网站优化关键词seo推广教程seo高级教程
  • wordpress营销模板下载上海seo优化外包公司
  • 免费注册网页的网站推荐友情链接
  • 东莞建设网站企业百度指数的各项功能
  • 闵行网站制作公司优化公司怎么优化网站的
  • 佛山外贸网站建设平台厦门seo搜索引擎优化
  • 东莞市网络优化推广服务机构泽成杭州seo网站推广排名
  • 手机怎么做3d短视频网站全国疫情最新报告
  • 做影视网站怎么样不犯法同城推广有什么平台
  • 网站标题字体大小互动营销案例
  • 做网站空间重要还是程序重要如何制作网站教程
  • wordpress媒体库文件打不开seo关键词排名系统
  • 汕头seo代理商seo发帖工具
  • 国家企业信息公示系统官网河南seo培训学什么
  • 一个网站如何做推广方案设计湖南网站设计外包服务
  • 品牌网站开发策划书快速网站搭建
  • 沈阳企业网站制作推广网页
  • 山西自助建站费用低重庆网站制作公司哪家好
  • 毕业设计开发网站要怎么做百度关键词热度排名