提交 24d38d80 编写于 作者: DCloud-yyl's avatar DCloud-yyl

Update theme.md

上级 ab31f253
......@@ -30,90 +30,94 @@ uni.setAppTheme({
<!-- UTSAPIJSON.setAppTheme.tutorial -->
## uni.onOsThemeChange(callback) @onosthemechange
## uni.onAppThemeChange(callback) @onappthemechange
<!-- UTSAPIJSON.onOsThemeChange.description -->
<!-- UTSAPIJSON.onAppThemeChange.description -->
<!-- UTSAPIJSON.onOsThemeChange.compatibility -->
**注意**
- HBuilderX4.18版本为 [uni.setAppTheme](#setapptheme) 设置的 theme 值变化时触发监听回调,回调参数中的 appTheme 值可能是"light" | "dark" | "auto"。在 app 平台设置应用的 theme 值为 auto 后,需同时使用 [uni.onOsThemeChange](#onOsThemeChange) 监听系统主题变化来计算应用使用的主题。
- HBuilderX4.19版本调整为 应用实际计算后使用的主题值发生变化时才触发监听回调,回调参数中的 appTheme 值只可能是"light" | "dark"。 在 app 平台设置应用的 theme 值为 auto 后,当系统主题发生变化时会自动计算决定是否触发回调,也就是说无需使用 [uni.onOsThemeChange](#onOsThemeChange) 监听系统主题变化。
<!-- UTSAPIJSON.onOsThemeChange.param -->
<!-- UTSAPIJSON.onAppThemeChange.compatibility -->
<!-- UTSAPIJSON.onOsThemeChange.returnValue -->
<!-- UTSAPIJSON.onAppThemeChange.param -->
<!-- UTSAPIJSON.onAppThemeChange.returnValue -->
```uts
//callbackId 用于注销监听
val callbackId = uni.onOsThemeChange((res: OsThemeChangeResult)=> {
console.log("onOsThemeChange---", res.osTheme)
val callbackId = uni.onAppThemeChange((res: AppThemeChangeResult) => {
console.log("onAppThemeChange", res.appTheme)
})
```
<!-- UTSAPIJSON.onOsThemeChange.tutorial -->
**注意:**
+ android 10、iOS 13 才开始支持深色模式主题 `dark`,更低版本无法获取、监听OS的主题。
<!-- UTSAPIJSON.onAppThemeChange.tutorial -->
## uni.offOsThemeChange(id) @offosthemechange
## uni.offAppThemeChange(id) @offappthemechange
<!-- UTSAPIJSON.offOsThemeChange.description -->
<!-- UTSAPIJSON.offAppThemeChange.description -->
<!-- UTSAPIJSON.offOsThemeChange.compatibility -->
<!-- UTSAPIJSON.offAppThemeChange.compatibility -->
<!-- UTSAPIJSON.offOsThemeChange.param -->
<!-- UTSAPIJSON.offAppThemeChange.param -->
<!-- UTSAPIJSON.offOsThemeChange.returnValue -->
<!-- UTSAPIJSON.offAppThemeChange.returnValue -->
```uts
val callbackId = uni.onOsThemeChange((res: OsThemeChangeResult)=> {
console.log("onOsThemeChange---", res.osTheme)
val callbackId = uni.onAppThemeChange((res: AppThemeChangeResult) => {
console.log("onAppThemeChange", res.appTheme)
})
...
...
//...
//...
//注销监听
uni.offOsThemeChange(callbackId)
uni.offAppThemeChange(this.appThemeChangeId)
```
<!-- UTSAPIJSON.offOsThemeChange.tutorial -->
<!-- UTSAPIJSON.offAppThemeChange.tutorial -->
## uni.onAppThemeChange(callback) @onappthemechange
## uni.onOsThemeChange(callback) @onosthemechange
<!-- UTSAPIJSON.onAppThemeChange.description -->
<!-- UTSAPIJSON.onOsThemeChange.description -->
<!-- UTSAPIJSON.onAppThemeChange.compatibility -->
<!-- UTSAPIJSON.onOsThemeChange.compatibility -->
<!-- UTSAPIJSON.onAppThemeChange.param -->
<!-- UTSAPIJSON.onOsThemeChange.param -->
<!-- UTSAPIJSON.onAppThemeChange.returnValue -->
<!-- UTSAPIJSON.onOsThemeChange.returnValue -->
```uts
//callbackId 用于注销监听
val callbackId = uni.onAppThemeChange((res: AppThemeChangeResult) => {
console.log("onAppThemeChange", res.appTheme)
val callbackId = uni.onOsThemeChange((res: OsThemeChangeResult)=> {
console.log("onOsThemeChange---", res.osTheme)
})
```
<!-- UTSAPIJSON.onAppThemeChange.tutorial -->
<!-- UTSAPIJSON.onOsThemeChange.tutorial -->
## uni.offAppThemeChange(id) @offappthemechange
**注意:**
+ android 10、iOS 13 才开始支持深色模式主题 `dark`,更低版本无法获取、监听OS的主题。
<!-- UTSAPIJSON.offAppThemeChange.description -->
## uni.offOsThemeChange(id) @offosthemechange
<!-- UTSAPIJSON.offAppThemeChange.compatibility -->
<!-- UTSAPIJSON.offOsThemeChange.description -->
<!-- UTSAPIJSON.offAppThemeChange.param -->
<!-- UTSAPIJSON.offOsThemeChange.compatibility -->
<!-- UTSAPIJSON.offAppThemeChange.returnValue -->
<!-- UTSAPIJSON.offOsThemeChange.param -->
<!-- UTSAPIJSON.offOsThemeChange.returnValue -->
```uts
val callbackId = uni.onAppThemeChange((res: AppThemeChangeResult) => {
console.log("onAppThemeChange", res.appTheme)
val callbackId = uni.onOsThemeChange((res: OsThemeChangeResult)=> {
console.log("onOsThemeChange---", res.osTheme)
})
...
...
//注销监听
uni.offAppThemeChange(this.appThemeChangeId)
uni.offOsThemeChange(callbackId)
```
<!-- UTSAPIJSON.offAppThemeChange.tutorial -->
<!-- UTSAPIJSON.offOsThemeChange.tutorial -->
<!-- UTSAPIJSON.general_type.name -->
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册