AppTheme
此 API 以前允许响应亮/暗模式,但此功能已被移除,取而代之的是 react-native 的
Appearance
API。我们希望在未来的react-native-windows
版本中协调高级 API。
AppTheme
允许您检测应用程序何时处于高对比度模式,以及在此模式下应使用的颜色。
import { useEffect, useState } from 'react';
import { Text } from 'react-native';
import { AppTheme } from 'react-native-windows';
const SampleComponent = () => {
const [isHighContrast, setHighContrast] = useState(AppTheme.isHighContrast);
useEffect(() => {
const subscription = AppTheme.addListener('highContrastChanged', () => {
setHighContrast(AppTheme.isHighContrast);
});
return () => subscription.remove();
});
if (isHighContrast) {
return <Text>High Contrast Enabled</Text>;
} else {
return <Text>High Contrast Disabled</Text>;
}
};
export default SampleComponent;
参考
事件
highContrastChanged
当用户的应用程序更改为高对比度主题时触发的事件。
属性
isHighContrast
bool isHighContrast
当用户将系统设置为高对比度模式时为 true
。否则为 false
。
currentHighContrastColors
IHighContrastColors currentHighContrastColors
在高对比度模式下使用的颜色列表。