Skip to content

Commit 6e3aaf2

Browse files
committed
Correctly limit SwiftUI image controller size and observe preferredContentSize for changes
Closes #597
1 parent cc1bef4 commit 6e3aaf2

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

LNPopupController/LNPopupController/Private/LNPopupBar.mm

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1121,11 +1121,14 @@ - (void)setSwiftuiImageController:(UIViewController *)swiftuiImageController
11211121
if(_swiftuiImageController != nil)
11221122
{
11231123
[_swiftuiImageController.view removeFromSuperview];
1124+
[_swiftuiImageController removeObserver:self forKeyPath:@"preferredContentSize"];
11241125
}
11251126

11261127
_swiftuiImageController = swiftuiImageController;
11271128
if(_swiftuiImageController != nil)
11281129
{
1130+
[_swiftuiImageController addObserver:self forKeyPath:@"preferredContentSize" options:NSKeyValueObservingOptionNew context:NULL];
1131+
11291132
_swiftuiImageController.view.backgroundColor = UIColor.clearColor;
11301133

11311134
_swiftuiImageController.view.translatesAutoresizingMaskIntoConstraints = NO;
@@ -1816,7 +1819,7 @@ - (CGSize)_imageViewSizeWithMaxWidth:(CGFloat)width maxHeight:(CGFloat)height
18161819

18171820
if(_swiftuiImageController != nil)
18181821
{
1819-
return _swiftuiImageController.preferredContentSize;
1822+
return LNMakeSizeWithAspectRatioInsideSize(_swiftuiImageController.preferredContentSize, CGSizeMake(width, height));
18201823
}
18211824

18221825
if(_imageView.contentMode != UIViewContentModeScaleAspectFit)
@@ -1951,6 +1954,12 @@ - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(N
19511954
{
19521955
[self._barDelegate _popupBarMetricsDidChange:self];
19531956
}
1957+
1958+
if([keyPath isEqualToString:@"preferredContentSize"] == YES && object == _swiftuiImageController)
1959+
{
1960+
[self _layoutImageView];
1961+
[self _setNeedsTitleLayoutRemovingLabels:NO];
1962+
}
19541963
}
19551964

19561965
- (void)setCustomBarViewController:(LNPopupCustomBarViewController*)customBarViewController

0 commit comments

Comments
 (0)