TelegramMessenger / Telegram-iOS

Telegram-iOS
6.38k stars 1.67k forks source link

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

Open Edgar-P-yan opened 8 months ago

Edgar-P-yan commented 8 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 7 months 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 7 months 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 7 months 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 6 months 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

kesha-antonov commented 4 months ago

env(safe-area-inset-bottom) is always 0 no matter what i try to change in styles or viewport

aabbdev commented 4 months ago

@kesha-antonov normal, it depend of the situation, sometime you don't have margins on the phone

aabbdev commented 4 months ago

@kesha-antonov you have to setup this before:

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

in the future you gonna have dvh

kesha-antonov commented 4 months ago

env(safe-area-inset-bottom) gives 0

aabbdev commented 4 months ago

you have to use var(--safe-area-inset-bottom)

aabbdev commented 4 months ago

you don't read the messages, and solving your problem doesn't seem to be your problem, so I think we can close the ticket

aabbdev commented 4 months ago

and for information Telegram iOS use Firefox

kesha-antonov commented 4 months ago

you have to use var(--safe-area-inset-bottom)

Thanks, I'll try it

kmsheng commented 3 weeks ago

To be honest, telegram has made another IE browser. We're suffering.

kmsheng commented 3 weeks ago

iPhone 13 pro gives zero safe-area-inset-bottom, but iPhone 13 pro max gives 34px

aabbdev commented 3 weeks ago

@kmsheng haha I was thinking the same at one point I give up