辅助按钮 负责 Telegram 迷你应用程序二级按钮的💠组件。 检查支持要检查当前 Telegram 迷你应用程序版本是否支持辅助按钮,请使用 isSupported 方法: Variable : - import { secondaryButton } from '@telegram-apps/sdk';$ q y4 e, W' b. d; _1 G+ S
- l3 M' _2 N7 R- secondaryButton.isSupported(); // boolean
复制代码Functions : - import { isSecondaryButtonSupported } from '@telegram-apps/sdk';% p0 R& |7 D! |
: ?& Q. r1 Z0 `1 z( v( I- isSecondaryButtonSupported(); // boolean
复制代码 安装在使用该组件之前,有必要将其安装到配置正确的 属性中。 为此,请使用 mount 方法。 它将更新 isMounted 信号属性。 Variable : - import { secondaryButton } from '@telegram-apps/sdk';
. N2 X0 a2 c0 x$ L3 P, r
5 k2 A& Q6 U p' T- secondaryButton.mount();
1 R4 k$ s, s& ^- C% ~. n - secondaryButton.isMounted(); // true
复制代码Functions : - import {: M. b+ @) s, M" a8 w
- mountSecondaryButton,
( k% ?% f4 C9 \ - isSecondaryButtonMounted,/ y3 t0 w: k& Y6 D9 R0 z. b
- } from '@telegram-apps/sdk';5 H2 z. o; y7 p/ I( w3 g' z
+ ^, j, F7 Y2 b- mountSecondaryButton();
e2 E( m& U2 C9 R; V - isSecondaryButtonMounted(); // true
复制代码
7 V4 W8 b7 U9 N) g2 l要卸载,请使用 unmount 方法: Variable : - secondaryButton.unmount();* P, n1 E2 @3 e2 m
- secondaryButton.isMounted(); // false
复制代码Functions : - import {
+ h _* n9 q- ? s' G* d - unmountSecondaryButton,
& W4 m. {/ V- W$ F$ a7 m - isSecondaryButtonMounted,
8 ^$ c) j. ]8 }8 @! F - } from '@telegram-apps/sdk';
3 a& w( {" D- W' ^( z, e+ e' b6 A0 h
6 I7 S0 B& g: Y9 u3 J" F0 j3 @' h- unmountSecondaryButton();0 E8 N% f! P3 Q+ R3 P) y$ T. C/ F
- isSecondaryButtonMounted(); // false
复制代码WARNING 该组件的属性取决于 Mini App 和 Theme Params 组件的值。 具体来说,二级按钮使用 Mini App 的 bottomBarBgColor 和一些主题参数颜色。 在使用辅助按钮之前,请确保将这些组件安装到 。 设置属性要更新按钮属性,请使用 setParams 方法。 它接受一个带有可选 属性的对象,每个属性负责各自的按钮特性。 反过来,调用该方法会更新 ,如 backgroundColor, hasShineEffect, isVisible, isEnabled, isLoaderVisible, position, state, textColor 和 text。 Variable : - secondaryButton.setParams({+ P' Z' f6 P% R. K
- backgroundColor: '#000000',! K( ]: N" X- h) G% D
- hasShineEffect: true,
" A2 k$ N& i% p8 y+ {1 N' Y - isEnabled: true,% E- B# N2 K6 w0 x0 O
- isLoaderVisible: true,
9 B; t f2 g) }, f - isVisible: true,
# V: N$ B* I0 V$ u - position: 'top',! W" L6 p9 L; j2 W/ p3 P" |, d I
- text: 'My text',: a" ]9 g- J4 q8 A/ Z0 e
- textColor: '#ffffff'
. V6 x9 `2 o& [- T - });
3 {4 h" O4 g( I* l' X& F - secondaryButton.backgroundColor(); // '#000000', ]) k C- h) s) Z5 t
- secondaryButton.hasShineEffect(); // true c- `! h7 F# E U0 P1 O
- secondaryButton.isEnabled(); // true
7 t) L- g6 S4 e# h! E - secondaryButton.isLoaderVisible(); // true
$ U8 h+ [% \2 s+ a% c - secondaryButton.isVisible(); // true9 A/ v& \; F7 o9 Z' W
- secondaryButton.position(); // 'top'8 Q7 S) H6 C4 h) x1 q
- secondaryButton.text(); // 'My text'
0 e# r; M& ], u' P5 c" Y% {2 n1 J - secondaryButton.textColor(); // '#ffffff'
' @$ _6 u# R& G% z5 D4 ~7 m6 d
: d u1 m( f. Q- secondaryButton.state();6 [+ r8 o' ^" Z' W
- // {
# v7 ^- m; j; X% H4 Z6 q; t9 p% t' h4 [* m* j - // backgroundColor: '#000000',
8 v; D0 Y4 x/ X1 e9 L+ E - // hasShineEffect: true,
) p* R2 B/ }. @/ u3 \+ z - // isActive: true,
8 y# Q" c+ P7 G - // isLoaderVisible: true,7 C. p# \* F2 k( h( n
- // isVisible: true,
- `1 J8 N, H' B! v9 E; F' M - // position: 'top',; ]4 R$ Y' _) y: o/ D
- // text: 'My text',& {) s* L; S2 ?) u
- // textColor: '#ffffff'
) K# r2 N- @; q0 y2 y - // }
复制代码Functions : - import {
i! A3 X: N. m, [4 ` - setSecondaryButtonParams,) Z, W( h- |1 `4 I% q5 }
- secondaryButtonBackgroundColor,
! R5 ^5 B, M+ F% V - secondaryButtonHasShineEffect,
( f a2 ?0 s+ W- j* i1 [ k; X - isSecondaryButtonVisible," d1 S: q( F7 l R4 w, ?
- isSecondaryButtonEnabled,$ M& V( g: i+ l, s" r
- isSecondaryButtonLoaderVisible,$ P* a( G9 I! l+ K3 Z* T
- secondaryButtonState,8 u7 K7 ?1 Z* w7 S% q
- secondaryButtonTextColor,
8 |) |. z: f N. s' ^1 n - secondaryButtonText,
9 l A# W2 G5 ]1 m) ] j3 F - secondaryButtonPosition,8 N l1 Q) N: m# `5 a/ N
- } from '@telegram-apps/sdk';
( _9 J' M U h2 } - 8 l7 q+ X+ W9 k& \! W9 f5 H& J
- setSecondaryButtonParams({
: X, @. o" H4 u, o3 d) Y9 I - backgroundColor: '#000000',
% K$ O4 ~: W1 b/ M0 T7 j e - hasShineEffect: true, a0 m- b- { Y; x1 F0 k% `
- isEnabled: true,
; d" j" g( G3 c1 @6 p - isLoaderVisible: true,( l( B& g- E* U. i2 E* r4 m/ o8 N
- isVisible: true,, h2 P2 y' u4 y( y
- position: 'top',
" U. @) x8 @5 b# M: L. m9 Z+ e) D - text: 'My text',8 e& h, c2 `$ Y/ ~/ C6 r
- textColor: '#ffffff'
/ [! g$ X( K h P; R+ H+ r - });3 K6 v/ |" k1 w& V
- secondaryButtonBackgroundColor(); // '#000000'# F- m/ v) g/ g9 o: q) t
- secondaryButtonHasShineEffect(); // true
/ Q9 o* G, a+ G" w+ k l - isSecondaryButtonEnabled(); // true8 ~6 G+ s: l$ U. {
- isSecondaryButtonLoaderVisible(); // true8 f& I6 @8 O6 c
- isSecondaryButtonVisible(); // true
! Z* ]8 [& U8 ?2 P. \# l - secondaryButtonPosition(); // 'top'
2 V% W0 g) Q1 x) L7 O' t - secondaryButtonText(); // 'My text'+ @2 h2 [ z! m, c4 Q5 b$ Y
- secondaryButtonTextColor(); // '#ffffff'/ N1 T3 h. T- f; o
- - o; G& j5 t0 O+ c1 r
- secondaryButtonState();
6 J# @1 U$ e$ v( H" \3 `: [- L& s% x - // {- x- k7 N0 V1 `5 I( O H3 A+ w
- // backgroundColor: '#000000',
/ r) x0 d2 H3 c9 F& p; a - // hasShineEffect: true,
. T+ l8 y( M, q - // isActive: true,
7 h1 O" W, p9 d9 v- _( j - // isLoaderVisible: true,
& d, J6 m. q6 W- d7 h4 I - // isVisible: true,
9 j# M8 m% Z$ H$ E8 X* \: @ - // position: 'top',
1 k* M( r8 k& A6 |2 X) V - // text: 'My text',: |. o. l, p8 M( W
- // textColor: '#ffffff'- j" W- c# [6 L. C$ H5 Q
- // }
复制代码 跟踪点击要添加按钮点击监听器,请使用 onClick 方法。 它返回一个函数,用于移除绑定的 监听器。 或者,您也可以使用 offClick 方法。 Variable : - function listener() {6 c$ `6 F) Z. r* p" ^; Q- n
- console.log('Clicked!');
' k& u J7 k3 p+ b - }
. r% }2 d9 l. d0 a- d
_8 _/ b' `$ t4 @1 s$ E1 k1 c- const offClick = secondaryButton.onClick(listener);8 e4 z( m& p' l- B4 U2 p. u3 [
- offClick();
! g7 ^1 O' D% }" R) l5 v# K0 W9 t# I - // or* w0 B, u7 V$ I8 b% a: P$ [; x
- secondaryButton.onClick(listener);4 r P( g3 |6 S' B2 I9 y
- secondaryButton.offClick(listener);
复制代码Functions : - import {, _$ `$ n' C5 M: N+ k6 w
- onSecondaryButtonClick,. U/ l6 o2 M1 h/ B
- offSecondaryButtonClick,
8 S2 v' o- e: H* S U+ P) b - } from '@telegram-apps/sdk';
5 X% n0 I. l3 L! Y: h - 2 |% B; z# }, i4 S* \
- function listener() {
4 ^& u3 B; ?- u1 H; J0 F% j5 R3 E! [ - console.log('Clicked!');
, {( X& k. H0 e& [4 A$ w* P# F - }
9 [# u) F, p" y+ M% \5 u - * Q# l1 l r# Q4 O# g1 J, y) o
- const offClick = onSecondaryButtonClick(listener);9 ~' w5 `$ O: V4 e
- offClick();
# h( j3 y/ v( l2 }4 @& b5 I+ o) o w - // or
( S$ M7 a9 S1 V A - onSecondaryButtonClick(listener);( y5 i1 ~9 ~+ \3 ?: y, @0 o3 ?
- offSecondaryButtonClick(listener);
复制代码 3 w X# [; h2 K0 F; c, \3 C9 a i
$ O% h9 Q$ \1 n9 u+ A7 r% z' [' G5 t* |
|