主题参数 该组件包含 Telegram 应用程序当前使用的 主题 信息。 初始化要初始化组件,请使用 initThemeParams 函数: - import { initThemeParams } from '@telegram-apps/sdk';
" }8 g( t0 S0 W' l; |9 H$ r e - : ]+ Y5 U8 M# I! T3 r
- const [themeParams] = initThemeParams();
复制代码 索取实际数据要获取实际的主题参数信息,开发人员可以使用 requestThemeParams 函数: - import { requestThemeParams } from '@telegram-apps/sdk';
/ E# \/ B" }/ Q! |3 T - 0 V; S n* W2 x% \% X4 ~
- requestThemeParams.then(console.log);( A1 R( A K7 M" g, G- S1 K
- - d1 \- Z: \" _1 N: T
- // Output:
5 o$ }! d! U: \! j - // { bgColor: '#ffaabb', ... }
复制代码 颜色开发人员可以使用 get 方法获取主题颜色: - themeParams.get('bgColor');
5 Q: w7 @* e5 v7 V - themeParams.get('packageUnknownColor');
复制代码 要通过一个对象获取所有颜色,请使用 getState 方法:- themeParams.getState();
: o3 N7 ^7 K, |; G6 C/ Z - // Output:, m& g8 y, k, {" K8 g
- // {
* T9 i! [' M: ?9 G( P0 t! W$ \4 ^1 c( N - // accentTextColor: '#aa1399',8 K: |9 U& Y& G6 {
- // bgColor: '#baac12',4 D& A% v5 a7 X) E) R: n
- // linkColor: '#887722'
1 |- |$ x# [: W: ~( f - // packageUnknownColor: '#676767,
# r& `/ T# d$ {' [ - // }
复制代码ThemeParams 组件可直接访问颜色列表: - accentTextColor: RGB | undefined
- bgColor: RGB | undefined
- buttonColor: RGB | undefined
- buttonTextColor: RGB | undefined
- destructiveTextColor: RGB | undefined
- headerBgColor: RGB | undefined
- hintColor: RGB | undefined
- linkColor: RGB | undefined
- secondaryBgColor: RGB | undefined
- sectionBgColor: RGB | undefined
- sectionHeaderTextColor: RGB | undefined
- subtitleTextColor: RGB | undefined
- textColor: RGB | undefined
4 x, m3 R" P, T! U9 q1 S2 ^% H4 p. b / y( k) A) b& k" L
例如3 Q( T. ~& h7 R6 h, s! F3 r
- themeParams.accentTextColor; // '#aa1399'
复制代码 + y+ P4 X; W4 c/ t" P
; p; g1 b$ `! P$ g' n V
事件可被 跟踪 的事件列表:
W1 \0 a5 ]; m& M事件 | 监听器 | 触发条件 | change | () => void | 组件中的某些部分发生了变化 | change:{theme_key} | (value: RGB) => void | 更改指定键的颜色 | ' S$ X2 M6 e7 B5 ]6 V* e
|