辅助按钮 负责 Telegram 迷你应用程序二级按钮的💠组件。 检查支持要检查当前 Telegram 迷你应用程序版本是否支持辅助按钮,请使用 isSupported 方法: Variable : - import { secondaryButton } from '@telegram-apps/sdk';( ?! y4 K/ D: B! E# W
4 T3 Y& p' `* z% F9 \& g! H- secondaryButton.isSupported(); // boolean
复制代码Functions : - import { isSecondaryButtonSupported } from '@telegram-apps/sdk';1 G b/ c: S, u
- " C; C: c" m( B& {% k7 F' v
- isSecondaryButtonSupported(); // boolean
复制代码 安装在使用该组件之前,有必要将其安装到配置正确的 属性中。 为此,请使用 mount 方法。 它将更新 isMounted 信号属性。 Variable : - import { secondaryButton } from '@telegram-apps/sdk';
# B0 [7 E; H5 z( d+ b% ~) v - % ^# S* r! z5 E( T& x; ]8 S
- secondaryButton.mount();
9 z# E5 V- ^1 `" v6 H - secondaryButton.isMounted(); // true
复制代码Functions : - import {5 M( b* p& i; J" N
- mountSecondaryButton,
' C. v3 a" K- W L( o; ^- v$ _7 U - isSecondaryButtonMounted,
5 `2 @: o3 D2 j, x- o - } from '@telegram-apps/sdk';! T- c$ ?! H8 {: F: S* c
- U3 G# T- [! |& w5 _' @3 {
- mountSecondaryButton();# j% ?9 n4 b1 p& C+ Y; R0 W. m8 W
- isSecondaryButtonMounted(); // true
复制代码
, O2 v/ u* z, O2 J要卸载,请使用 unmount 方法: Variable : - secondaryButton.unmount();
" |3 B9 {* u# J# S& P' ~ - secondaryButton.isMounted(); // false
复制代码Functions : - import {0 g$ Q7 U5 E3 d9 d* g: O9 g; x- S
- unmountSecondaryButton,' U3 ]- U6 o' u+ Z' |
- isSecondaryButtonMounted,. T9 B3 S2 y) j9 s3 _* b
- } from '@telegram-apps/sdk';
0 B- O m6 }$ g# m - ! J' n( M4 z& l" s; F; F" s$ j: N
- unmountSecondaryButton();
l& ^$ w4 U, P' y; Q* [- F - isSecondaryButtonMounted(); // false
复制代码WARNING 该组件的属性取决于 Mini App 和 Theme Params 组件的值。 具体来说,二级按钮使用 Mini App 的 bottomBarBgColor 和一些主题参数颜色。 在使用辅助按钮之前,请确保将这些组件安装到 。 设置属性要更新按钮属性,请使用 setParams 方法。 它接受一个带有可选 属性的对象,每个属性负责各自的按钮特性。 反过来,调用该方法会更新 ,如 backgroundColor, hasShineEffect, isVisible, isEnabled, isLoaderVisible, position, state, textColor 和 text。 Variable : - secondaryButton.setParams({* a* D% o5 ]4 h" R$ F- U
- backgroundColor: '#000000',5 @ D- U7 c9 p/ T# }* I5 U# m
- hasShineEffect: true,
- y, e, I. v$ Y: j3 \- m - isEnabled: true,. w- F" O1 e/ B
- isLoaderVisible: true,
& x* }/ |" z7 W! P3 ^* X' \" ]- a - isVisible: true,
& Y% i+ z/ f0 y7 p - position: 'top',: n9 K6 |+ D7 n+ A6 o! ~
- text: 'My text',6 }' ~9 U! t0 A$ q
- textColor: '#ffffff'4 t5 ^& v/ ^; ~+ D) E9 M, z
- });
+ L4 x3 |9 s' ^+ W8 T8 V( \ - secondaryButton.backgroundColor(); // '#000000'5 {2 W4 ^. I- z1 H5 l
- secondaryButton.hasShineEffect(); // true
5 K* U/ P1 \! T - secondaryButton.isEnabled(); // true1 @9 D) b- f) y w, {2 F
- secondaryButton.isLoaderVisible(); // true" r4 \' F9 \. }9 P8 m; [* c. z- l0 d
- secondaryButton.isVisible(); // true
! S: @7 ~; a( c+ V - secondaryButton.position(); // 'top'
- o- K2 \ C v, q( j8 h- k - secondaryButton.text(); // 'My text'$ k. G4 P3 O/ t6 i# g
- secondaryButton.textColor(); // '#ffffff'
6 B1 O, `6 x4 N1 V, h* ]
( e+ ?5 |+ _5 d# g6 j z1 Z* Y- F; g) B7 c- secondaryButton.state();$ _/ n2 K2 N9 y. U. h* r0 h
- // {3 A, ~' H1 V% R8 f
- // backgroundColor: '#000000',7 M' k7 r6 w. R* I; e
- // hasShineEffect: true,4 K& o) o. O. c+ i* L' ~
- // isActive: true,& n3 w' {$ H. C7 {
- // isLoaderVisible: true,) y, x) a4 M3 R
- // isVisible: true,7 `4 p5 Z3 Q4 F" l
- // position: 'top', p8 _) P2 N, d5 k6 a- z8 M0 w
- // text: 'My text',
5 X) E0 ^. A/ D/ r - // textColor: '#ffffff'
+ n3 P0 |/ a5 C - // }
复制代码Functions : - import {
% K7 Y. L. S9 d2 i5 f5 ? - setSecondaryButtonParams,
# [0 x, `& t. _% a5 I: B - secondaryButtonBackgroundColor,
2 ]% X- k" h& l2 M - secondaryButtonHasShineEffect,
9 M# `5 m J6 b' C3 E - isSecondaryButtonVisible,4 {. y8 @5 e3 c/ V: f
- isSecondaryButtonEnabled,; O5 t, h& A4 q7 n2 B3 T6 A
- isSecondaryButtonLoaderVisible,
3 a b5 _# F4 D; s3 H' h R3 x - secondaryButtonState,
& [! w' W( U3 w. C5 |( `, O - secondaryButtonTextColor,
/ m, Z9 L0 D1 B0 V& [: l - secondaryButtonText,
0 n! z- p* V0 N3 {" @ - secondaryButtonPosition,6 Q% n$ m4 N" H' s2 ?
- } from '@telegram-apps/sdk';
$ B& w0 K2 [7 i. _; ^2 M* Y L - 9 l0 V2 Q; G+ A5 v* T( M. l9 y
- setSecondaryButtonParams({4 q8 O9 C9 E$ G3 x2 M
- backgroundColor: '#000000',! z, G q# h3 G
- hasShineEffect: true,
& @- f) s+ L. y2 K c; | - isEnabled: true,
9 X' N- m8 V3 j" v( ]+ A2 A3 ~7 _ - isLoaderVisible: true,. B A* v7 f# G& V
- isVisible: true,, Z" V( M% O4 ]+ C
- position: 'top',
0 N r: ^5 e2 d/ c - text: 'My text',( Z2 f* Q8 [& Z# @
- textColor: '#ffffff'
# B' ?8 N7 y. H1 X2 G - });: j; b& t( Z1 }2 H. R
- secondaryButtonBackgroundColor(); // '#000000'( H/ {1 ^6 x$ U5 A
- secondaryButtonHasShineEffect(); // true
8 B! e4 c; h% T9 L) R3 o - isSecondaryButtonEnabled(); // true9 A, E2 }3 @* r8 u3 H
- isSecondaryButtonLoaderVisible(); // true
6 Y1 w. G" X( |4 ^! Z# Q' G# Z - isSecondaryButtonVisible(); // true6 b* K; R5 C# S+ R b8 k" M
- secondaryButtonPosition(); // 'top'
4 Z @% `$ ^) u; [9 S" { - secondaryButtonText(); // 'My text'5 T5 e2 U6 r- \
- secondaryButtonTextColor(); // '#ffffff'
( j, B/ B+ B6 s8 `. c7 n" E2 @
& {- x* F: y5 A% r$ @- secondaryButtonState();/ A) M& L _ U3 o( q5 L+ I
- // {
9 _: A3 F: R9 f- O2 l; {$ v, X% T - // backgroundColor: '#000000',
, f7 l$ y( o+ d8 g" X. @ - // hasShineEffect: true,
' T, T: G6 _' c8 c& G& V a I - // isActive: true,
! h* Q2 K! q! b# e: \- g1 D - // isLoaderVisible: true,
; T, h: n( W# L - // isVisible: true,( `4 S/ L/ f: x9 w
- // position: 'top',2 B) ~ z& K" S6 a2 m/ P X+ v' h& G+ ?
- // text: 'My text',% a# e9 p5 E! X' D8 R3 K
- // textColor: '#ffffff'
6 L* P+ T! @/ c7 H - // }
复制代码 跟踪点击要添加按钮点击监听器,请使用 onClick 方法。 它返回一个函数,用于移除绑定的 监听器。 或者,您也可以使用 offClick 方法。 Variable : - function listener() {
9 S8 m- \" m! y% `3 e - console.log('Clicked!');" z0 I8 Z& Y0 b+ G# x' D f" n
- }2 `" `0 g! C4 O/ z
- 0 {5 S9 w6 a5 X; h
- const offClick = secondaryButton.onClick(listener);8 Z+ H0 f9 V1 I2 H* F
- offClick();% Y" l/ S- t* _1 \
- // or# S! ` `) |8 r
- secondaryButton.onClick(listener);0 W" s# n0 _- O3 h( v
- secondaryButton.offClick(listener);
复制代码Functions : - import {
+ b! {, N3 V% p1 c+ n - onSecondaryButtonClick,
5 O6 I) `- y: Z6 l* {/ U0 Z - offSecondaryButtonClick,
( b5 j! {) i5 u- C" P* k f; V - } from '@telegram-apps/sdk';
6 l9 l9 q( ~8 N( l
$ }. f- ?( [7 ?% [( r& X* q- function listener() {
5 L( Z% B1 q8 H1 j% } - console.log('Clicked!');$ k8 ?' ~: d- V( {7 U
- }
( P0 j' I6 t- r) E
; j( d- o" C1 o5 T# j' p- const offClick = onSecondaryButtonClick(listener);2 r, F: ]. y9 T
- offClick();/ K k8 e; P( g' O k
- // or$ g0 h, }& ~% l9 E& ~: Q
- onSecondaryButtonClick(listener);
* C( M% U8 o+ [7 b9 H - offSecondaryButtonClick(listener);
复制代码
3 W8 U- C" j2 o) N, I0 Q. M' x0 I4 J) K/ o
|