辅助按钮 负责 Telegram 迷你应用程序二级按钮的💠组件。 检查支持要检查当前 Telegram 迷你应用程序版本是否支持辅助按钮,请使用 isSupported 方法: Variable : - import { secondaryButton } from '@telegram-apps/sdk';. G/ |* o0 |( V v' z+ U
- 5 `0 d" a$ E7 s( {( T6 Z5 h$ ?# Z
- secondaryButton.isSupported(); // boolean
复制代码Functions : - import { isSecondaryButtonSupported } from '@telegram-apps/sdk';
- X: S- B/ @( }0 a
1 W% W. F- S# _" e- x2 z4 i- isSecondaryButtonSupported(); // boolean
复制代码 安装在使用该组件之前,有必要将其安装到配置正确的 属性中。 为此,请使用 mount 方法。 它将更新 isMounted 信号属性。 Variable : - import { secondaryButton } from '@telegram-apps/sdk';
) R2 N' w D* ~: J1 A - ( q5 w, X$ C" L( K9 t* p; Y
- secondaryButton.mount();
; c8 N) _0 V8 P! d: k2 f. f6 { - secondaryButton.isMounted(); // true
复制代码Functions : - import {
% ?( B) U; D& } I0 N5 }3 b - mountSecondaryButton,
2 _4 ?; h; B; \/ ~. l. F - isSecondaryButtonMounted,
" B% X$ m. T8 E - } from '@telegram-apps/sdk';5 D$ U& h! w9 A- F* N7 M$ Z
) \5 ? ]8 W1 v) L5 ^) \1 U' A- mountSecondaryButton();
! f' T( P6 q( [% A2 L+ \ - isSecondaryButtonMounted(); // true
复制代码 E$ Z/ S/ _& g+ F5 v, C
要卸载,请使用 unmount 方法: Variable : - secondaryButton.unmount();8 a% U8 i# g2 s( ~' U! F ]
- secondaryButton.isMounted(); // false
复制代码Functions : - import {
5 `1 t( S7 d) \0 T - unmountSecondaryButton,3 H/ Q3 s. h2 s0 M
- isSecondaryButtonMounted,7 S2 D0 t; j2 w9 G& j
- } from '@telegram-apps/sdk';
/ O2 Q* F) A2 W$ x0 w, x7 X+ E- A
9 |2 U4 z% X) a/ G, O- }, ~- unmountSecondaryButton();
% f4 Q/ b' t4 W1 c9 D- G, o3 t - isSecondaryButtonMounted(); // false
复制代码WARNING 该组件的属性取决于 Mini App 和 Theme Params 组件的值。 具体来说,二级按钮使用 Mini App 的 bottomBarBgColor 和一些主题参数颜色。 在使用辅助按钮之前,请确保将这些组件安装到 。 设置属性要更新按钮属性,请使用 setParams 方法。 它接受一个带有可选 属性的对象,每个属性负责各自的按钮特性。 反过来,调用该方法会更新 ,如 backgroundColor, hasShineEffect, isVisible, isEnabled, isLoaderVisible, position, state, textColor 和 text。 Variable : - secondaryButton.setParams({
7 Q4 U) ~" E& [* ?# I: j" r9 j1 a - backgroundColor: '#000000',
" D# g/ ?8 }) V7 n8 h U* c - hasShineEffect: true,
2 Z& f. r3 q, Z: J+ ] - isEnabled: true,7 h0 }7 C( ]& s
- isLoaderVisible: true,7 T- d% s2 k( R0 u* L+ Z" B
- isVisible: true,( {) z' B2 X/ n% b: ^
- position: 'top', S8 a% X0 D& P- q& H( h
- text: 'My text',
U* `( H# K3 V3 A- E( V - textColor: '#ffffff'0 E% L2 d6 x; m% A: T
- });
; X" _6 [1 j+ P. q - secondaryButton.backgroundColor(); // '#000000'' o4 }4 t/ G+ K$ L0 ?8 C7 X
- secondaryButton.hasShineEffect(); // true
2 u* R9 R* q, [1 s6 t( V3 v - secondaryButton.isEnabled(); // true
9 O/ a5 Y- Q. }3 G b+ s+ ?) A- H - secondaryButton.isLoaderVisible(); // true
* n8 C; s# K: a" [: v7 U - secondaryButton.isVisible(); // true
& Z3 `, }/ z2 i# o; p* N - secondaryButton.position(); // 'top'$ I9 C( I# x" g) u; d* Z
- secondaryButton.text(); // 'My text'
3 v* x$ _9 Q L- u6 L9 `, n$ ? - secondaryButton.textColor(); // '#ffffff'
; p. y' p8 g5 ?' N: O' c( e' l
& P! y# i! U9 s) T U( P, Q- secondaryButton.state();% P r) m5 H1 L, |7 X: ]
- // {; {' j6 l/ f/ T1 i
- // backgroundColor: '#000000',
+ o4 r5 c; M+ N- U2 k - // hasShineEffect: true," b/ E2 V* @/ ?0 ?
- // isActive: true,
! D" D& u& ^4 {. [& Z U" x - // isLoaderVisible: true,& ~% s: R3 n" ]$ I- B* e
- // isVisible: true, d; d1 Y1 T8 m6 x6 h$ r& |
- // position: 'top',8 t+ r+ w4 y+ \ t
- // text: 'My text',
+ {0 h2 p" Q0 G0 m6 V8 d% Q9 Y8 e! F9 d - // textColor: '#ffffff'% s2 U" q, H6 B# |4 _: u. p
- // }
复制代码Functions : - import {
7 G" y( H4 I* K1 c - setSecondaryButtonParams,
9 P! v( u- o: i - secondaryButtonBackgroundColor,6 |6 i) r( s% P( i
- secondaryButtonHasShineEffect,
' c U) }+ C# P5 H2 f - isSecondaryButtonVisible,3 J$ J* T" b+ o' [
- isSecondaryButtonEnabled, d& h' h3 ` p# e; }! e4 B
- isSecondaryButtonLoaderVisible,* ?# w2 C1 F- @% [6 d P
- secondaryButtonState,
, i0 \) V) G9 H, n" }6 j - secondaryButtonTextColor,2 M: ]0 k9 `* c+ z& [# ]' Q |
- secondaryButtonText,
9 K/ j" f! R1 V9 ~, t - secondaryButtonPosition,3 H# R+ i' M+ O. @( D, l4 S9 q
- } from '@telegram-apps/sdk';" U ]( p" E1 d& g/ ~: R% l
* U* [& E& s- \% x- y% I- setSecondaryButtonParams({
' [8 u& u: d5 [; X - backgroundColor: '#000000',7 J% {. a- @% u" Z+ ]' g: b# s
- hasShineEffect: true,/ E3 s5 I% H- a+ _7 l* A8 G
- isEnabled: true,( ], ?" K- R4 H8 {
- isLoaderVisible: true,
& Z; P* I+ m% A: S) g0 }0 B9 { - isVisible: true,# n% W. \8 K; J) ^9 c/ c0 Z/ c
- position: 'top',
7 d& K2 d! m2 {6 l - text: 'My text',
( Z+ e( W f! c6 J9 n - textColor: '#ffffff' v$ D0 @8 E2 ?' T( p- U
- });" m! S/ z3 p) J7 n9 `
- secondaryButtonBackgroundColor(); // '#000000'7 `: M; I6 H ?. U5 a( Q c
- secondaryButtonHasShineEffect(); // true
; q8 E0 n- o2 q0 f - isSecondaryButtonEnabled(); // true' g6 J: r+ r" u% B: T4 b* R6 J
- isSecondaryButtonLoaderVisible(); // true
8 ] n" _4 l$ h; B- e - isSecondaryButtonVisible(); // true
6 Q1 {. k6 E% D! C2 U - secondaryButtonPosition(); // 'top'
4 z, T6 x# J3 S8 L - secondaryButtonText(); // 'My text'
; J! @3 s8 P, v! S - secondaryButtonTextColor(); // '#ffffff'$ l5 U- w: S! { A; ^$ P# d" G
- 7 t( T4 k: s% s, _
- secondaryButtonState();
% O$ G% F( q* A, L* G5 o' d$ a - // {
( h; n& [9 `! z- |. j - // backgroundColor: '#000000',; r6 Z: R* \2 b* [6 P
- // hasShineEffect: true,. J4 @. H7 Y/ p4 b+ ? g% M
- // isActive: true,
) J5 q2 U! o! E" K2 T3 \5 ^; ]& A - // isLoaderVisible: true,
) o- M; X, X; |9 n - // isVisible: true,$ X) ? @6 H7 C: F
- // position: 'top',
, W1 q) ^, W7 s7 V- V' Q - // text: 'My text',
# ~! V; H$ ]' o8 j5 `# M4 y - // textColor: '#ffffff'
+ u2 k& O$ g1 n! t$ A - // }
复制代码 跟踪点击要添加按钮点击监听器,请使用 onClick 方法。 它返回一个函数,用于移除绑定的 监听器。 或者,您也可以使用 offClick 方法。 Variable : - function listener() {% p: P. p8 k1 w# A W; R
- console.log('Clicked!');) f; U) B& S6 C, U/ ~( }
- }
4 @5 `5 ?0 P6 f
; \, D, v, j7 I- const offClick = secondaryButton.onClick(listener);; G" A7 | D" l' o2 b' H
- offClick();
4 n5 Y3 e T/ F* T- d3 i7 q( s- t - // or/ S) K; e$ `% X
- secondaryButton.onClick(listener);5 d2 M/ k. Z. O) \% V2 f
- secondaryButton.offClick(listener);
复制代码Functions : - import {+ T; e( U8 D( B1 S; T5 L, c' C( U: q
- onSecondaryButtonClick, K! F1 i% t/ V5 o$ y# g
- offSecondaryButtonClick,0 d: p3 W' {3 U+ T4 `6 x
- } from '@telegram-apps/sdk';
9 Y0 e2 T: \3 h* R/ Y+ I/ v* z
: e7 ?" e- ], s4 T' U1 p8 v- function listener() {
3 U* N q" ^" H( d5 n5 {8 Q5 s4 v+ H - console.log('Clicked!');2 e4 O) y) i) i c
- }
. A5 u: j! \$ t - 0 W& N5 @' ?! E) f0 b
- const offClick = onSecondaryButtonClick(listener);- c$ z) E6 d. R4 j
- offClick();
" m- U# B" E. z" ] g - // or. k+ ~* Y$ |& y+ y6 \7 _+ x7 G
- onSecondaryButtonClick(listener);5 g6 g* @4 I% {& q- v
- offSecondaryButtonClick(listener);
复制代码
' ]7 ` I. @/ o6 v2 v! ^
- R% d* d2 z, T' O) q |