import { Bridge } from '../Bridge'; import { EventEmitter } from 'twa-core'; import { MainButtonEventsMap } from './events'; import { RGBColor } from 'twa-core'; interface ConOptions { isActive?: boolean; isVisible?: boolean; isProgressVisible?: boolean; } declare const ee: EventEmitter; /** * Controls the main button, which is displayed at the bottom * of the Web App in the Telegram interface. * * TODO: Desktop animation is rather bad in case, we call progress visibility * right after click. It is not smooth. * * TODO: We need event to get current main button state. */ export declare class MainButton { private bridge; private _color; private _textColor; private _isActive; private _isVisible; private _isProgressVisible; private _text; private ee; /** * Sends current button state to native app. * @private */ private commit; /** * Updates current button color. * * @param color - color to set. * @private */ private set color(value); /** * Updates current button activity state. * * @param active - should button be active. * @private */ private set isActive(value); /** * Updates current progress visibility state. * * @param visible - should progress be visible. * @private */ private set isProgressVisible(value); /** * Updates current button visibility state. * * @param visible - should button be visible. * @private */ private set isVisible(value); /** * Sets current button text. Note, that minimum text length is 1 symbols * and the maximum is 64. * * @param text - text to set. * @throws {Error} Text has incorrect length. */ private set text(value); /** * Updates current button text color. * @param color - target color. */ private set textColor(value); constructor(bridge: Bridge, color: RGBColor, textColor: RGBColor, text: string, options?: ConOptions); /** * Current button color. */ get color(): RGBColor; /** * Disables button. * FIXME: This method does not work on Android. Event "main_button_pressed" * keeps getting received even in case, button is disabled. * Issue: https://github.com/Telegram-Web-Apps/documentation/issues/1 */ disable: () => this; /** * Enables button. */ enable: () => this; /** * Hides button. */ hide: () => this; /** * Hides button progress. */ hideProgress: () => this; /** * Shows whether the button is active. */ get isActive(): boolean; /** * Shows whether the button is displaying a loading indicator. */ get isProgressVisible(): boolean; /** * Shows whether the button is visible. */ get isVisible(): boolean; /** * Adds new event listener. * FIXME: Event 'main_button_pressed' is still being received on Android * even if the main button is disabled. * Issue: https://github.com/Telegram-Web-Apps/client-sdk/issues/3 * * @param event - event name. * @param listener - event listener. */ on: typeof ee['on']; /** * Removes event listener. * * @param event - event name. * @param listener - event listener. */ off: typeof ee['off']; /** * Shows the button. Note that opening the Web App from the attachment * menu hides the main button until the user interacts with the Web App * interface. */ show: () => this; /** * A method to show a loading indicator on the button. * It is recommended to display loading progress if the action tied to the * button may take a long time. */ showProgress: () => this; /** * Sets new main button text. * @param text - new text. */ setText: (text: string) => this; /** * Sets new main button text color. * @param color - new text color. */ setTextColor: (color: RGBColor) => this; /** * Updates current button color. * @param color - color to set. */ setColor: (color: RGBColor) => this; /** * Current button text. */ get text(): string; /** * Current button text color. */ get textColor(): RGBColor; } export {};