Skip to content

Conversation

@etoledom
Copy link
Contributor

@etoledom etoledom commented May 27, 2025

Closes BETS-50

Description

This PR is aimed to replace the native SwiftUI sheet presentation with the UIKit sheet presentation.

Wins from this changes are:

  • Native transition animation on SwiftUI context when the sheet height changes.
  • Native detection of dismissal attempt by the user.
  • Half and full detents support for pre-iOS16

To Achieve this the follow changes were made:

QuickEditorViewController is now used by both UIKit and SwiftUI contexts. It wraps QuickEditor view in a UIHostingController to be presented by UIKit framework.

From UIKit context:

Not many changes. It uses the public QuickEditorPresenter to present QuickEditorViewController in a bottom sheet.

A change was made where the CustomImageEditorControllerRepresentable conversion is handled by QuickEditorPresenter directly, in order to remove UIKit dependencies from the QuickEditorViewController init parameters.

From SwiftUI context:

There's a new QuickEditorBottomSheetPresenterViewController which will present modally (on a sheet) theQuickEditorViewController. This part is the trick to do the presentation work.

Then QuickEditorBottomSheetPresenterViewControllerRepresentable wraps it in a Representable, to be able to be inserted into the SwiftUI hierarchy.

Then, QuickEditorBottomSheetPresenterViewControllerRepresentable is initialised with the properties given by the public View.gravatarQuickEditorSheet extension, and passed to a new view modifier QuickEditorBottomSheetViewControllerPresentationModifier.

The new QuickEditorBottomSheetViewControllerPresentationModifier modifier will conditionally add or remove the presenter controller to the hierarchy according to isPresented property. And it will ensure that its dimensions are zero to keep it hidden. Every time the controller is added to the hierarchy, it will automatically present the QuickEditorController in a sheet presentation.

Testing Steps

From SwiftUI context:

  • Native transition animation on SwiftUI context when the sheet height changes.
  • Native detection of dismissal attempt by the user.
  • Custom image editor injection.
  • System color scheme, and user specified color scheme.
  • Update callbacks to parent app.
  • All different presentation styles.

From UIKit context:

Keen eye to:

  • Custom image editor injection.
  • System color scheme, and user specified color scheme.

As the rest has been mostly kept as it was before, but still good to smoke test everything else.

To prevent them to be overridden by a custom URLSession
@wpmobilebot
Copy link

wpmobilebot commented May 27, 2025

App Icon📲 You can test the changes from this Pull Request in Gravatar Prototype Build by scanning the QR code below to install the corresponding build.
App NameGravatar Prototype Build
Build Number2387
VersionPR #763
Bundle IDcom.automattic.gravatar-sdk-demo-uikit.prototype-build
Commit12ce401
Installation URL1qmh5rjrgkc4o
Automatticians: You can use our internal self-serve MC tool to give yourself access to those builds if needed.

ZStack {
content
quickEditorPresenter
.frame(width: 0, height: 0)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So this is the trick! 🪄

@etoledom etoledom marked this pull request as ready for review May 28, 2025 11:50
@etoledom etoledom changed the base branch from trunk to release/3.4.0 May 28, 2025 12:03
Copy link
Contributor

@pinarol pinarol left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Masterpiece 🎉

@etoledom etoledom merged commit 1b60c64 into release/3.4.0 May 28, 2025
8 checks passed
@etoledom etoledom deleted the etoledom/uikit-sheet-presentation branch May 28, 2025 12:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants