[S] Allow SwiftUI content view to size up until maximum width #241
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Change Description
This PR should allow a SwiftUI view that is being used within the PopTip to resize a little better. Previously if the content of a SwiftUI content view was too wide it would just run of the screen, or if given a fixed width (using the
.frame(width: 200)
view modifier on the SwiftUI itself) then text would truncate instead of wrapping onto new lines. Hopefully this change should improve this behaviour by modifying the frame calculation for the UIHostingViewController view within theshow
method. Essentially a maximum width is calculated which is the width of the device minus padding/margin/etc. so that the full thing is still visible, and then the height is derived using theUIView
methodsizeThatFits
. This is not a perfect solution, but is an improvement in my opinion - thoughts?This could be improved to work better with different directions, and applied to the other variants of PopTip.
This partially addresses the issue I mentioned at the end of my last PR #239.
Testing
Testing this functionality should be possible by playing around with the SwiftUI views within
SwiftUIView.swift
. A second view has been added which utilises different behaviours, and it automatically toggles when tapping thetopLeft
button (so it will now cycle between custom view and a SwiftUI view where the SwiftUI view also alternates each time).Closing notes
If there are any issues, or questions around these changes, please let me know! If all is good with this @andreamazz, it'd be great to be able to have it merged and the version bumped as appropriate - it does change the existing behaviour for those that use it, so may be worth doing a decent bump! 😄