LiaDevelopers

Concepts

Make your app feel part of Lia. Lia's theme as CSS variables, the viewport and safe areas, the person's language and right to left text, and sound they can mute.

#Lia's theme

Lia passes its colours to your page, light or dark, as the person has Lia set. After Lia.init() they're CSS variables on your page's root, kept current when the person switches:

css
body {
  background: var(--lia-bg-color);
  color: var(--lia-text-color);
}
.card { background: var(--lia-secondary-bg-color); }
.hint { color: var(--lia-hint-color); }
button.primary { background: var(--lia-button-color); color: var(--lia-button-text-color); }
VariableFrom Lia.themeWhat it is
--lia-bg-colorbg_colorThe page's background
--lia-text-colortext_colorText
--lia-hint-colorhint_colorQuieter text
--lia-link-colorlink_colorLinks (Lia blue)
--lia-button-colorbutton_colorButtons (Lia blue)
--lia-button-text-colorbutton_text_colorText on buttons
--lia-secondary-bg-colorsecondary_bg_colorCards and wells
--lia-header-bg-colorheader_bg_colorLia's header
--lia-bottom-bar-bg-colorbottom_bar_bg_colorBehind the bottom buttons
--lia-accent-text-coloraccent_text_colorAccented text
--lia-section-bg-colorsection_bg_colorSections
--lia-section-header-text-colorsection_header_text_colorSection headings
--lia-subtitle-text-colorsubtitle_text_colorSubtitles
--lia-destructive-text-colordestructive_text_colorDestructive actions
--lia-section-separator-colorsection_separator_colorHairlines
--lia-color-schemeLia.colorSchemelight or dark

The names follow Telegram's theme parameters, so code written for Telegram mini apps maps across. Listen for the theme event to redraw anything you paint yourself (a canvas, say).

You can also set the colour behind your page and of Lia's header with Lia.setBackgroundColor and Lia.setHeaderColor.

#The viewport

Lia.viewport is { height, expanded }: the height your page has in px, and whether a sheet is pulled up to full height. The viewport event fires when it changes (the sheet pulled up, bottom buttons shown), and --lia-viewport-height holds the height.

#Safe areas

Phones have notches and home bars. Lia passes them as Lia.safeArea and CSS variables, in px:

VariableWhat it is
--lia-safe-area-inset-top, -bottom, -left, -rightThe phone's own safe area (Lia.safeArea)
--lia-content-safe-area-inset-top, -bottom, -left, -rightClear of Lia's floating Close and ⋯ in fullscreen too (Lia.contentSafeArea)

In a sheet or under Lia's header, you mostly need the bottom one. In fullscreen, keep content below the content safe area's top:

css
.app {
  padding-top: var(--lia-content-safe-area-inset-top, 0px);
  padding-bottom: var(--lia-safe-area-inset-bottom, 0px);
}

#Language

Lia.language is the language the person uses Lia in, one of Lia's 13:

CodeLanguageCodeLanguage
enEnglishidBahasa Indonesia
esEspañolfilFilipino
ptPortuguêsswKiswahili
frFrançaishiहिन्दी
trTürkçearالعربية (right to left)
ruРусскийzh中文
viTiếng Việt

Show your app's own words in it. The SDK sets your page's lang for you; Lia.rtl says whether the language reads right to left, so set the direction yourself:

JavaScript
Lia.init().then(function () {
  document.documentElement.dir = Lia.rtl ? "rtl" : "ltr";
  render(WORDS[Lia.language] || WORDS.en);
  Lia.ready();
});
Lia.on("languageChanged", function (data) {
  document.documentElement.dir = data.rtl ? "rtl" : "ltr";
  render(WORDS[data.language] || WORDS.en);
});

#Sound

People can mute your app from Lia's ⋯ menu, and Lia remembers it for your app. Lia.soundOn says whether they want your sounds, and soundChanged says when it changes. Play sounds only while it's on.

JavaScript
let soundOn = Lia.soundOn;
Lia.on("soundChanged", function (data) {
  soundOn = data.on;
  if (!soundOn) music.pause();
});
function play(sound) { if (soundOn) sound.play(); }

Your page may play sound without waiting for a first tap. To mix with music already playing on the phone instead of stopping it, set navigator.audioSession.type = "ambient" where the phone supports it (Lia's own games do).

#Platform

Lia.platform is ios or android after init(). Lia's frame is the phone's own web view: Safari's on iPhone, Chrome's on Android.

Type to search every page, method and endpoint.