@amazon-devices/expo-system-ui允许与位于React树之外的系统用户界面元素进行交互。特别是与根视图背景颜色交互。
安装
- 在
package.json文件中添加JavaScript库依赖项。选择适用于您的React Native版本的选项卡。
- React Native 0.72
- React Native 0.83
- 使用
npm install命令重新安装依赖项。
Documentation Index
Fetch the complete documentation index at: /llms.txt
Use this file to discover all available pages before exploring further.
@amazon-devices/expo-system-ui允许与位于React树之外的系统用户界面元素进行交互。
@amazon-devices/expo-system-ui允许与位于React树之外的系统用户界面元素进行交互。特别是与根视图背景颜色交互。
package.json文件中添加JavaScript库依赖项。选择适用于您的React Native版本的选项卡。dependencies: {
...
"@amazon-devices/expo-system-ui": "~2.0.0",
"@amazon-devices/keplerscript-turbomodule-api": "~1.0.0",
}
dependencies: {
...
"@amazon-devices/expo-system-ui": "~3.0.0",
"@amazon-devices/keplerscript-turbomodule-api": "~1.0.0",
}
npm install命令重新安装依赖项。import React, {useState} from 'react';
import {StyleSheet, View, Button} from 'react-native';
import * as SystemUI from '@amazon-devices/expo-system-ui';
import {ColorValue} from 'react-native';
export const App = () => {
const [backgroundColor, setBackgroundColor] = useState<ColorValue | null>(
'#0000ff',
);
const changeBackgroundColor = async (color: string | null) => {
console.log(backgroundColor);
await SystemUI.setBackgroundColorAsync(color);
setBackgroundColor(await SystemUI.getBackgroundColorAsync());
};
return (
<View style={[styles.container, backgroundColor ? {backgroundColor} : {}]}>
<Button
title="Change background color"
onPress={() =>
changeBackgroundColor(
backgroundColor === '#0000ff' ? '#ff0000' : '#0000ff',
)
}
/>
</View>
);
};
const styles = StyleSheet.create({
container: {
flex: 1,
alignItems: 'center',
justifyContent: 'center',
},
});
| 方法 | 描述 |
|---|---|
getBackgroundColorAsync | 获取根视图背景颜色 |
setBackgroundColorAsync | 更改根视图背景颜色 |
此页面对您有帮助吗?
