skiptools / skip-ui

SwiftUI for Android
https://skip.tools
GNU Lesser General Public License v3.0
114 stars 11 forks source link

Work with safe area #6

Open Wolfaks opened 10 months ago

Wolfaks commented 10 months ago

How to work with safe area in iOS and Android? Different margins at the bottom on different platforms. Base SwiftUI methods are not supported in Skip. Thanks

marcprux commented 10 months ago

This will be good to add. I'm going to move this over to the skip-ui repository to track it there.

For the time being, you can put any iOS-specific modifiers inside #if !SKIP / #endif blocks so you can support the iOS side of the safe area (see https://skip.tools/docs/platformcustomization/).

Wolfaks commented 10 months ago

Unfortunately, this does not solve the problem of different iPhone models (SE 2-3 gen without safe area and X and newer with safe area), they should have different indents at the bottom...

marcprux commented 10 months ago

this does not solve the problem of different iPhone models

Skip doesn't block you from doing anything that is possible in SwiftUI. When you build for iOS, you are building directly against the platform's SwiftUI, so you can do anything that is supported there.

When a feature is un-supported in Skip (because we haven't implemented the equivalent Android feature using SkipUI's Compose bridge), then you simply need to embed the iOS-specific code in an #if !SKIP block. This prevents the Skip transpiler from converting it into Kotlin (and thus raising an error about being unsupported).

For example:

MyView()
  .background(Color.red)
  #if !SKIP
  .ignoresSafeArea(edges: .bottom) // unsupported on Android, so needs to be in a #if !SKIP block
  #endif