# 暗黑样式表动态值

DynamicValue、ThemeValue 配合 useDynamicStyleSheet 使用获得样式表动态色值

# Class 组件用法

import React, { Component } from 'react';
import { Text, TouchableOpacity } from 'react-native';
import { injectTheme, DynamicValue, DynamicStyleSheet } from '@ezviz/rntheme'
 
class DeviceButton extends Component {
  constructor() {
    super();
  }
 
  render() {
    const { text, useDynamicStyleSheet, rntheme } = this.props;
    const styles = rntheme.useDynamicStyleSheet(dynamicStyleSheet);
 
     return (
       <TouchableOpacity style={styles.button}>
         <Text>{text}</Text>
       </TouchableOpacity>
     );
  }
}
 
export default injectTheme(DeviceButton);
 
 //浅色模式色值:#FFF 暗黑模式色值:#000
const dynamicStyleSheet = new DynamicStyleSheet({
  button: {
    backgroundColor: new DynamicValue('#FFF', '#000')
  }
});

# Function 组件用法

import React from 'react';
import { Text, TouchableOpacity } from 'react-native';
import { DynamicValue, DynamicStyleSheet, useDynamicStyleSheet } from '@ezviz/rntheme'
 
export default props => {
  const styles = useDynamicStyleSheet(dynamicStyleSheet);
 
  return (
    <TouchableOpacity style={styles.button}>
      <Text>{props.text}</Text>
    </TouchableOpacity>
  );
}
 
 //浅色模式色值:#FFF 暗黑模式色值:#000
const dynamicStyleSheet = new DynamicStyleSheet({
  button: {
    backgroundColor: new DynamicValue('#FFF', '#000')
  }
});