TelegramMessenger / Telegram-iOS

Telegram-iOS
5.4k stars 1.45k forks source link

Support env(safe-area-inset-bottom) and others inside Mini Apps #1377

Open Edgar-P-yan opened 2 months ago

Edgar-P-yan commented 2 months ago

Checklist

Description

I'm trying to implement a chat on top of Telegram Mini Apps, and found out that the IPhone bottom white bar is closing some elements that are sticked to the bottom of the screen. For these scenarios we could just add a padding-bottom: env(safe-area-inset-bottom) as described here https://webkit.org/blog/7929/designing-websites-for-iphone-x/. It works inside iOS Chrome, iOS Safari, but not inside Telegram Mini Apps.

Expected Behavior

What we get in Chrome and Safari:

image image

Actual Behavior

Instead the padding does not work, probably because the padding-bottom: env(safe-area-inset-bottom) resolves to padding-bottom: 0 or none

image

Steps to Reproduce

  1. Host a simple code like this <div style="height: env(safe-area-inset-bottom); background-color: red"></div>
  2. Check it on an IPhone device horizontally, so the bottom browser navigation hides, and the white bar starts covering the visible web view
  3. You should see a red line
  4. Do the same thing inside Telegram Web App, the red line does not show up, although the white bar covers the visible content.

Environment

Device: iPhone 14 Pro Max

iOS version: 17.2.1

App version: 10.9.2

dmaximyuk commented 1 month ago

I fully support this thread. There is a problem at least in the implementation of the "bottom navbar" component. I would really like to see a non-crutch solution

GMELUM commented 1 month ago

I don’t understand what the Telegram developers relied on when creating the automatic addition of safe zones. This adds a lot of problems, just like specifying the webview height. The only solution to the problems with safe zones is to keep the classic approach, and not create something crooked.

GMELUM commented 1 month ago

@Edgar-P-yan, you can calculate the difference between the height obtained from viewportHeight and window.innerHeight. This will give you the safe zone value. This works just as poorly as the option that Telegram offers. But I don’t know any other options yet =(

aabbdev commented 1 month ago
:root {
     --safe-area-inset-bottom: calc(100vh - var(--tg-viewport-stable-height, 100vh))
}

Example

div.safemybottomelement {
   padding-bottom: calc(1rem + var(--safe-area-inset-bottom));
}
// another example
div.safemybottomelement2 {
   padding-bottom: var(--safe-area-inset-bottom);
}

It's my gift, we can probably close the ticket