辅助按钮 负责 Telegram 迷你应用程序二级按钮的💠组件。 检查支持要检查当前 Telegram 迷你应用程序版本是否支持辅助按钮,请使用 isSupported 方法: Variable : - import { secondaryButton } from '@telegram-apps/sdk';
/ r( }0 l" W9 Q1 d7 a4 w7 |
' K e. E. m' j0 O- secondaryButton.isSupported(); // boolean
复制代码Functions : - import { isSecondaryButtonSupported } from '@telegram-apps/sdk';8 j4 u% i+ J. x. l+ n! t$ w
) @! r4 p: S, ~6 k- isSecondaryButtonSupported(); // boolean
复制代码 安装在使用该组件之前,有必要将其安装到配置正确的 属性中。 为此,请使用 mount 方法。 它将更新 isMounted 信号属性。 Variable : - import { secondaryButton } from '@telegram-apps/sdk';& N3 ?8 w# [7 e+ P5 {/ E; k5 I
9 y* Z- B/ M2 N8 d' q- secondaryButton.mount();" w! Z) r) Y* U2 E& X
- secondaryButton.isMounted(); // true
复制代码Functions : - import {
9 i5 Q+ Y" t, v" H3 V - mountSecondaryButton,( i9 E9 Y4 Y& Z) u
- isSecondaryButtonMounted,
3 V3 e; B& m- b9 Y! _* q X/ U - } from '@telegram-apps/sdk';
+ R, i! o/ j, E& L
) \2 B, w0 L. d* a+ X. R; S- mountSecondaryButton();7 ]7 e" X$ X7 y& } A. n2 i
- isSecondaryButtonMounted(); // true
复制代码 0 c. m4 j) o! l. r8 U
要卸载,请使用 unmount 方法: Variable : - secondaryButton.unmount();* F* z0 x9 |- L8 Q8 C# \1 F: T/ s) W
- secondaryButton.isMounted(); // false
复制代码Functions : - import {) K: V! d/ U2 P- o+ R
- unmountSecondaryButton,* i" j. ~; j( [/ C& j! q [1 p2 s
- isSecondaryButtonMounted,) |, V8 q; e: t9 V( g# N7 e1 `. f
- } from '@telegram-apps/sdk'; ], s% d7 B: w$ q: K
2 Z" M' V a9 ]5 Q* {8 W+ q* p- unmountSecondaryButton();
( O. i$ ?/ v$ o, l) W - isSecondaryButtonMounted(); // false
复制代码WARNING 该组件的属性取决于 Mini App 和 Theme Params 组件的值。 具体来说,二级按钮使用 Mini App 的 bottomBarBgColor 和一些主题参数颜色。 在使用辅助按钮之前,请确保将这些组件安装到 。 设置属性要更新按钮属性,请使用 setParams 方法。 它接受一个带有可选 属性的对象,每个属性负责各自的按钮特性。 反过来,调用该方法会更新 ,如 backgroundColor, hasShineEffect, isVisible, isEnabled, isLoaderVisible, position, state, textColor 和 text。 Variable : - secondaryButton.setParams({
+ G6 ~9 i+ E6 f v, c - backgroundColor: '#000000', g# F5 d- u* p6 W6 H4 ?
- hasShineEffect: true,0 N8 V" Z7 Q9 ^7 v: c
- isEnabled: true,$ M5 D3 ~/ {0 k6 E* R# K" ?) X2 P
- isLoaderVisible: true,1 c* H1 v: F( n1 ]' [
- isVisible: true,; t' s$ B9 F- C/ _' g
- position: 'top',# S; H' e& O$ R4 m2 U6 c
- text: 'My text',
5 B* S* }; `2 D( M3 U - textColor: '#ffffff'( I2 ]& i/ A n0 X
- });) @3 H7 Y+ N/ ~8 {$ {7 L y
- secondaryButton.backgroundColor(); // '#000000'
$ O8 t* b+ m/ d$ t - secondaryButton.hasShineEffect(); // true
0 o [' F" h! e - secondaryButton.isEnabled(); // true* L* @1 v1 _7 c! T# z, N
- secondaryButton.isLoaderVisible(); // true
5 P' Q" A+ f7 j) j+ B9 r+ {# p; ] - secondaryButton.isVisible(); // true
" C; Z! k c7 e6 Y4 k' H - secondaryButton.position(); // 'top'
4 ?( \9 B# h4 Q% D( c0 D - secondaryButton.text(); // 'My text'
+ y" H* U- v# _6 m1 x. R O+ S' A9 s0 @# C - secondaryButton.textColor(); // '#ffffff'
4 C4 h& l0 K u2 D# k% G - * x/ l* v8 @+ Z8 M. t' c# T
- secondaryButton.state();
5 C4 ]0 e! ]$ k6 ], `# j5 ^ - // {
3 C6 ]& @6 i; z# M* T/ S4 [. ? - // backgroundColor: '#000000',5 v8 i) z5 H1 Q
- // hasShineEffect: true,
4 q) l/ l1 M2 F4 }5 Q5 y+ O - // isActive: true," x# t) t) [5 V- N6 _
- // isLoaderVisible: true,
3 o U6 W, x* o' B/ J2 d' N - // isVisible: true,
+ n7 I+ ?3 c0 F c: ~ - // position: 'top',3 n9 Y. }# Q7 Y5 P" d4 |
- // text: 'My text',% i' o6 F. M) M+ a$ R3 d+ t
- // textColor: '#ffffff'
* ^. d; ~+ g4 u. G& \0 M - // }
复制代码Functions : - import {( l' S2 h6 X. E9 ^2 `: F" |
- setSecondaryButtonParams,! c+ Q& L# A. k0 c/ Y3 p
- secondaryButtonBackgroundColor,/ R6 ~3 y5 {$ ~% t! _- j
- secondaryButtonHasShineEffect,
/ V8 c. [6 I1 P h - isSecondaryButtonVisible,* B# b! W- h9 l
- isSecondaryButtonEnabled,
7 C5 Y, q( g5 N - isSecondaryButtonLoaderVisible,' J \( {% @) T, j+ w% c; V6 @
- secondaryButtonState,
4 U2 C6 U! }% R+ t" a! C. X. i+ v - secondaryButtonTextColor,
/ P5 x& n5 T- _+ y9 t% G1 E - secondaryButtonText,# j/ s( L6 P, f* e
- secondaryButtonPosition,: J |- x3 Z. q1 Y$ { Z; |0 P
- } from '@telegram-apps/sdk';$ w) a4 b' c% i! p8 L0 X0 S
- ' M7 q5 O9 T, V7 M
- setSecondaryButtonParams({
/ L2 |; g6 [+ {: o4 Y( e) y - backgroundColor: '#000000',) g* i7 _. y t4 g8 u1 L
- hasShineEffect: true,
, u# n, ], L8 {9 L( o2 m! b+ q% l! ^ - isEnabled: true,- A) n; P4 ?3 _
- isLoaderVisible: true,3 h7 m6 @' K f1 x8 {* ]& i# v
- isVisible: true,
4 f# n9 X: d7 l$ ?" e3 ~( O - position: 'top', S4 Y, ~4 r& x4 h6 L9 z4 O
- text: 'My text',5 k4 |/ l# G3 g: Z; q
- textColor: '#ffffff'& t( r' I/ K4 c1 ~9 N
- });
6 p8 M( v+ m3 }' I# u# x! j - secondaryButtonBackgroundColor(); // '#000000'. I0 {9 r D# X/ N0 Q
- secondaryButtonHasShineEffect(); // true' i* e) {1 v/ c$ c
- isSecondaryButtonEnabled(); // true
5 y7 ?" ]" Y4 A: c. V- x7 @ - isSecondaryButtonLoaderVisible(); // true3 k) ~, n! E+ a7 _( L" @) z% x
- isSecondaryButtonVisible(); // true
& H Z3 y+ c2 `# B5 O/ b0 l! r - secondaryButtonPosition(); // 'top'2 Q( _0 r G; x
- secondaryButtonText(); // 'My text', D+ u9 d( u, b z
- secondaryButtonTextColor(); // '#ffffff'
; K" r7 z. B9 }3 v$ i4 r - 9 E- ]" V0 Z* [9 M4 {
- secondaryButtonState();9 ?6 B8 t/ Y0 ?/ C8 ^5 C% X6 K
- // { v( Z; ?" D) w1 J r4 L
- // backgroundColor: '#000000',# K9 z+ I9 Q( Z9 N9 w( W i
- // hasShineEffect: true,
1 P" _4 R: I/ ?2 s# i0 P - // isActive: true,: A; Y+ X: V: _' E8 o% t' P7 x: t
- // isLoaderVisible: true,
/ B, F+ z! b4 i! F: [6 p% Z: `$ T6 b: r - // isVisible: true,
+ I L- O7 [7 D/ r$ G - // position: 'top',
' L8 ^! \. s" f# Z - // text: 'My text',
/ q; V! j; }/ w6 j: W8 K X, J9 H - // textColor: '#ffffff'" P) I% t/ G& {0 B1 V! I7 U& k
- // }
复制代码 跟踪点击要添加按钮点击监听器,请使用 onClick 方法。 它返回一个函数,用于移除绑定的 监听器。 或者,您也可以使用 offClick 方法。 Variable : - function listener() {" d+ X! C1 f6 M5 t4 i
- console.log('Clicked!');
! C4 A* O% O+ L- }" W2 Y - }8 Y, ]( f* O/ i- s. e' X% i( e
- " Q: Z# a0 S l9 @0 o2 L5 r
- const offClick = secondaryButton.onClick(listener);3 K1 _& V# D# U* h5 c
- offClick();
3 o5 W9 }7 H9 \1 ~- i5 u - // or! v% Z6 B+ S3 M( x q# `8 q W/ P
- secondaryButton.onClick(listener);" U5 u; I: f3 n( w2 {- }
- secondaryButton.offClick(listener);
复制代码Functions : - import {
% a, P h; i3 k; V2 D2 R0 Z - onSecondaryButtonClick,
) r+ O# r- ]7 w! V* a3 u0 A - offSecondaryButtonClick,2 X% v0 d1 \7 x5 K
- } from '@telegram-apps/sdk';
% \& N0 t( i" g - F7 `* @* W8 q/ z
- function listener() {
4 W8 ?8 F! J1 x1 Q - console.log('Clicked!');
2 Z3 L" h: R( y: B$ Y - }" {( U) x5 d2 r+ O! @9 |7 E
' `% t5 _. Y( f2 W- const offClick = onSecondaryButtonClick(listener);
4 q& o7 z! W/ Z7 D! F1 [( v+ Y - offClick();% D4 Z: f6 ?# |
- // or
- C- l" q8 ~* v! w' I2 T* ]/ r - onSecondaryButtonClick(listener);
" x4 w3 o4 o* [! }: S - offSecondaryButtonClick(listener);
复制代码 ) V. ~' U! N+ s) N# q
; `8 d& o# Y0 b' m2 a
|