@amazon-devices/expo-system-ui允许与位于React树之外的系统用户界面元素进行交互。特别是与根视图背景颜色交互。
安装
-
在
package.json文件中添加JavaScript库依赖项。 -
使用
npm install命令重新安装依赖项。
Documentation Index
Fetch the complete documentation index at: /llms.txt
Use this file to discover all available pages before exploring further.
expo-system-ui 开放Beta测试文档 作为预发布开放Beta测试的一项内容,亚马逊提供了此技术文档。…
@amazon-devices/expo-system-ui允许与位于React树之外的系统用户界面元素进行交互。特别是与根视图背景颜色交互。
package.json文件中添加JavaScript库依赖项。
dependencies: {
...
"@amazon-devices/expo-system-ui": "~2.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="更改背景颜色"
onPress={() =>
changeBackgroundColor(
backgroundColor === '#0000ff' ? '#ff0000' : '#0000ff',
)
}
/>
</View>
);
};
const styles = StyleSheet.create({
container: {
flex: 1,
alignItems: 'center',
justifyContent: 'center',
},
});
| 方法 | 描述 |
|---|---|
getBackgroundColorAsync | 获取根视图背景颜色 |
setBackgroundColorAsync | 更改根视图背景颜色 |
| NPM程序包版本 | Vega SDK版本 | Vega OS版本 | React Native版本 |
|---|---|---|---|
| ~2.0.0 | 0.23及更早版本 | OS 1.1 (1401010009820)及更早版本 | 0.72 |
此页面对您有帮助吗?
