Skip to content

Commit 67e16af

Browse files
committed
Fix SPM
Automatically discover `LNPopupImageView` views inside popup content controllers Introduce `LNPopupTransitionView` protocol Rename `LNPopupShadowedImageView` to `LNPopupImageView`
1 parent 5417eda commit 67e16af

33 files changed

+203
-144
lines changed

LNPCSwiftRefinements/SwiftRefinements.swift

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ import SwiftUI
1616

1717
@_cdecl("__ln_doNotCall__fixUIHostingViewHitTest")
1818
@_spi(LNPopupControllerInternal)
19-
public func __ln_doNotCall__fixUIHostingViewHitTest() {
19+
public
20+
func __ln_doNotCall__fixUIHostingViewHitTest() {
2021
DispatchQueue.main.async {
2122
guard let view = UIHostingController(rootView: EmptyView()).view else {
2223
return
@@ -50,14 +51,16 @@ public func __ln_doNotCall__fixUIHostingViewHitTest() {
5051
}
5152
#endif
5253

53-
public extension Double {
54+
public
55+
extension Double {
5456
/// The default popup snap percent. See `LNPopupInteractionStyle.customizedSnap(percent:)` for more information.
5557
static var defaultPopupSnapPercent: Double {
5658
return __LNSnapPercentDefault
5759
}
5860
}
5961

60-
public extension UIViewController {
62+
public
63+
extension UIViewController {
6164
/// Available interaction styles with the popup bar and popup content view.
6265
enum PopupInteractionStyle {
6366
/// The default interaction style for the current environment.
@@ -121,7 +124,8 @@ public extension UIViewController {
121124
}
122125
}
123126

124-
public extension LNPopupItem {
127+
public
128+
extension LNPopupItem {
125129
/// The popup item's attributed title.
126130
///
127131
/// If no title or subtitle is set, the system will use the view controller's title.
@@ -147,7 +151,8 @@ public extension LNPopupItem {
147151
}
148152
}
149153

150-
public extension LNPopupBarAppearance {
154+
public
155+
extension LNPopupBarAppearance {
151156
/// Display attributes for the popup bar’s title text.
152157
///
153158
/// Only attributes from the UIKit scope are supported.
@@ -175,7 +180,8 @@ public extension LNPopupBarAppearance {
175180
}
176181
}
177182

178-
public extension UIViewController {
183+
public
184+
extension UIViewController {
179185
/// Presents an interactive popup bar in the receiver's view hierarchy and optionally opens the popup in the same animation. The popup bar is attached to the receiver's docking view.
180186
///
181187
/// You may call this method multiple times with different controllers, triggering replacement to the popup content view and update to the popup bar, if popup is open or bar presented, respectively.

LNPopupController/LNPopupController.xcodeproj/project.pbxproj

Lines changed: 71 additions & 71 deletions
Large diffs are not rendered by default.

LNPopupController/LNPopupController/LNPopupBar.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#import <LNPopupController/LNPopupItem.h>
1212
#import <LNPopupController/LNPopupCustomBarViewController.h>
1313
#import <LNPopupController/LNPopupBarAppearance.h>
14-
#import <LNPopupController/LNPopupShadowedImageView.h>
14+
#import <LNPopupController/LNPopupImageView.h>
1515

1616
#define LN_UNAVAILABLE_PREVIEWING_MSG "Add context menu interaction or register for previewing directly on the popup bar view."
1717

@@ -74,7 +74,7 @@ NS_SWIFT_UI_ACTOR
7474
@property (nullable, nonatomic, copy, readonly) NSArray<UIBarButtonItem*>* trailingBarButtonItems;
7575

7676
/// An image view displayed when the bar style is prominent. (read-only)
77-
@property (nonatomic, strong, readonly) LNPopupShadowedImageView* imageView;
77+
@property (nonatomic, strong, readonly) LNPopupImageView* imageView;
7878

7979
/// The popup bar style.
8080
@property (nonatomic, assign) LNPopupBarStyle barStyle UI_APPEARANCE_SELECTOR;

LNPopupController/LNPopupController/LNPopupShadowedImageView.h renamed to LNPopupController/LNPopupController/LNPopupImageView.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//
2-
// LNPopupShadowedImageView.h
2+
// LNPopupImageView.h
33
// LNPopupController
44
//
55
// Created by Léo Natan on 2025-03-24.
@@ -15,7 +15,7 @@ NS_ASSUME_NONNULL_BEGIN
1515
/// When used inside a popup content view, instances of this class are especially suited as image transition targets.
1616
///
1717
/// See `UIViewController.viewForPopupTransition(from:to:)`.
18-
@interface LNPopupShadowedImageView : UIImageView
18+
@interface LNPopupImageView : UIImageView
1919

2020
/// The corner radius of the image view.
2121
@property (nonatomic, assign) CGFloat cornerRadius;

LNPopupController/LNPopupController/Private/LNPopupBar.mm

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
#import "_LNPopupSwizzlingUtils.h"
1313
#import "_LNPopupBase64Utils.hh"
1414
#import "NSAttributedString+LNPopupSupport.h"
15-
#import "LNPopupShadowedImageView+Private.h"
15+
#import "LNPopupImageView+Private.h"
1616
#import "UIView+LNPopupSupportPrivate.h"
1717

1818
#ifdef DEBUG
@@ -296,7 +296,7 @@ @implementation LNPopupBar
296296
{
297297
BOOL _delaysBarButtonItemLayout;
298298

299-
LNPopupShadowedImageView* _imageView;
299+
LNPopupImageView* _imageView;
300300

301301
_LNPopupBarTitlesView* _titlesView;
302302
NSLayoutConstraint* _titlesViewLeadingConstraint;
@@ -518,7 +518,7 @@ - (nonnull instancetype)initWithFrame:(CGRect)frame
518518

519519
_needsLabelsLayout = YES;
520520

521-
_imageView = [[LNPopupShadowedImageView alloc] initWithContainingPopupBar:self];;
521+
_imageView = [[LNPopupImageView alloc] initWithContainingPopupBar:self];;
522522
_imageView.autoresizingMask = UIViewAutoresizingNone;
523523
_imageView.contentMode = UIViewContentModeScaleAspectFit;
524524
_imageView.accessibilityTraits = UIAccessibilityTraitImage;

LNPopupController/LNPopupController/Private/LNPopupController.mm

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -383,9 +383,9 @@ - (void)animateOpenTransitionIfNeededWithAnimator:(UIViewPropertyAnimator*)anima
383383
}
384384

385385
_LNPopupTransitionOpenAnimator* handler;
386-
if([userView isKindOfClass:LNPopupShadowedImageView.class])
386+
if([userView conformsToProtocol:@protocol(LNPopupTransitionView)])
387387
{
388-
handler = [[_LNPopupTransitionPreferredOpenAnimator alloc] initWithUserView:(LNPopupShadowedImageView*)userView popupBar:self.popupBar popupContentView:self.popupContentView];
388+
handler = [[_LNPopupTransitionPreferredOpenAnimator alloc] initWithUserView:(LNPopupImageView*)userView popupBar:self.popupBar popupContentView:self.popupContentView];
389389
}
390390
else
391391
{
@@ -404,7 +404,7 @@ - (void)animateCloseTransitionIfNeededWithAnimator:(UIViewPropertyAnimator*)anim
404404

405405
_LNPopupTransitionCloseAnimator* handler;
406406

407-
if([userView isKindOfClass:LNPopupShadowedImageView.class])
407+
if([userView conformsToProtocol:@protocol(LNPopupTransitionView)])
408408
{
409409
handler = [[_LNPopupTransitionPreferredCloseAnimator alloc] initWithUserView:userView popupBar:self.popupBar popupContentView:self.popupContentView currentContentController:self.currentContentController containerController:self.containerController];
410410
}

LNPopupController/LNPopupController/Private/LNPopupShadowedImageView+Private.h renamed to LNPopupController/LNPopupController/Private/LNPopupImageView+Private.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
//
2-
// LNPopupShadowedImageView+Private.h
2+
// LNPopupImageView+Private.h
33
// LNPopupController
44
//
55
// Created by Léo Natan on 2025-03-24.
66
// Copyright © 2015-2025 Léo Natan. All rights reserved.
77
//
88

9-
#import "LNPopupShadowedImageView.h"
9+
#import <LNPopupController/LNPopupImageView.h>
1010
#import "LNPopupBar+Private.h"
1111

1212
NS_ASSUME_NONNULL_BEGIN
1313

14-
@interface LNPopupShadowedImageView ()
14+
@interface LNPopupImageView ()
1515

1616
- (instancetype)initWithContainingPopupBar:(LNPopupBar*)popupBar;
1717

LNPopupController/LNPopupController/Private/LNPopupShadowedImageView.m renamed to LNPopupController/LNPopupController/Private/LNPopupImageView.mm

Lines changed: 43 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
//
2-
// LNPopupShadowedImageView.m
2+
// LNPopupImageView.mm
33
// LNPopupController
44
//
55
// Created by Léo Natan on 2025-03-24.
66
// Copyright © 2015-2025 Léo Natan. All rights reserved.
77
//
88

9-
#import "LNPopupShadowedImageView+Private.h"
9+
#import "LNPopupImageView+Private.h"
10+
#import "_LNPopupBase64Utils.hh"
11+
#import "UIViewController+LNPopupSupportPrivate.h"
12+
#import <LNPopupController/UIViewController+LNPopupSupport.h>
1013

1114
@interface _LNPopupBarImageContentLayer: CALayer @end
1215
@implementation _LNPopupBarImageContentLayer
@@ -36,12 +39,20 @@ - (instancetype)init
3639
_imageContentsLayer = [_LNPopupBarImageContentLayer layer];
3740
_imageContentsLayer.masksToBounds = YES;
3841
_imageContentsLayer.cornerCurve = kCACornerCurveContinuous;
39-
[self addSublayer:_imageContentsLayer];
42+
[super addSublayer:_imageContentsLayer];
4043
}
4144

4245
return self;
4346
}
4447

48+
- (void)addSublayer:(CALayer *)layer
49+
{
50+
layer.masksToBounds = YES;
51+
layer.cornerCurve = kCACornerCurveContinuous;
52+
layer.cornerRadius = _imageContentsLayer.cornerRadius;
53+
[super addSublayer:layer];
54+
}
55+
4556
- (void)layoutSublayers
4657
{
4758
[super layoutSublayers];
@@ -50,28 +61,29 @@ - (void)layoutSublayers
5061

5162
- (void)setCornerRadius:(CGFloat)cornerRadius
5263
{
53-
[(LNPopupShadowedImageView*)self.delegate setCornerRadius:cornerRadius];
64+
[(LNPopupImageView*)self.delegate setCornerRadius:cornerRadius];
5465
}
5566

5667
- (void)setSuperCornerRadius:(CGFloat)cornerRadius
5768
{
58-
// super.cornerRadius = cornerRadius;
5969
_imageContentsLayer.cornerRadius = cornerRadius;
70+
for(CALayer* sublayer in self.sublayers)
71+
{
72+
if(sublayer != _imageContentsLayer)
73+
{
74+
sublayer.cornerRadius = cornerRadius;
75+
}
76+
}
6077
}
6178

6279
- (void)setContents:(id)contents
6380
{
6481
[_imageContentsLayer setContents:contents];
6582
}
6683

67-
//- (void)setMasksToBounds:(BOOL)masksToBounds
68-
//{
69-
// NSLog(@"Fuck off!");
70-
//}
71-
7284
@end
7385

74-
@implementation LNPopupShadowedImageView
86+
@implementation LNPopupImageView
7587
{
7688
__weak LNPopupBar* _containingBar;
7789
}
@@ -200,4 +212,24 @@ - (void)setImage:(UIImage *)image
200212
}
201213
}
202214

215+
- (void)didMoveToWindow
216+
{
217+
if(self.window == nil || _containingBar != nil)
218+
{
219+
return;
220+
}
221+
222+
static NSString* vCFA = LNPopupHiddenString("_viewControllerForAncestor");
223+
224+
UIViewController* candidate = [self valueForKey:vCFA];
225+
candidate.ln_discoveredTransitionView = self;
226+
}
227+
228+
- (NSString *)description
229+
{
230+
return [NSString stringWithFormat:@"%@ cornerRadius: %@ shadow: %@", super.description, @(self.cornerRadius), self.shadow];
231+
}
232+
203233
@end
234+
235+
@implementation LNPopupImageView (TransitionSupport) @end

LNPopupController/LNPopupController/Private/UIView+LNPopupSupportPrivate.mm

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,6 @@ - (NSArray*)_ln_rSTTV
292292
NSArray* rv = [self _ln_rSTTV];
293293
NSMutableArray* popupRV = [NSMutableArray new];
294294

295-
//_viewControllerForAncestor
296295
static NSString* vCFA = LNPopupHiddenString("_viewControllerForAncestor");
297296

298297
for(UIView* scrollToTopCandidate in rv)

LNPopupController/LNPopupController/Private/UIViewController+LNPopupSupport.mm

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
#pragma clang diagnostic ignored "-Wincomplete-implementation"
3232
@implementation UIViewController (LNPopupSupportPrivate)
3333

34-
@dynamic ln_popupController, popupPresentationContainerViewController, popupContentViewController, bottomBarSupport;
34+
@dynamic ln_popupController, popupPresentationContainerViewController, popupContentViewController, bottomBarSupport, ln_discoveredTransitionView;
3535

3636
@end
3737
#pragma clang diagnostic pop
@@ -276,7 +276,7 @@ - (BOOL)positionPopupCloseButton:(LNPopupCloseButton*)popupCloseButton
276276

277277
- (nullable UIView*)viewForPopupTransitionFromPresentationState:(LNPopupPresentationState)fromState toPresentationState:(LNPopupPresentationState)toState
278278
{
279-
return nil;
279+
return self._ln_discoveredTransitionView;
280280
}
281281

282282
- (void)viewWillMoveToPopupContainerContentView:(LNPopupContentView *)popupContentView
@@ -346,6 +346,28 @@ - (void)setAllowPopupHapticFeedbackGeneration:(BOOL)allowPopupHapticFeedbackGene
346346
self._ln_popupController.wantsFeedbackGeneration = allowPopupHapticFeedbackGeneration;
347347
}
348348

349+
static const void* _LNPopupContentControllerDiscoveredTransitionView = &_LNPopupContentControllerDiscoveredTransitionView;
350+
351+
- (void)_ln_setDiscoveredTransitionView:(LNPopupImageView *)ln_discoveredShadowedImageView
352+
{
353+
id objToSet = nil;
354+
if(ln_discoveredShadowedImageView != nil)
355+
{
356+
objToSet = [_LNWeakRef refWithObject:ln_discoveredShadowedImageView];
357+
}
358+
objc_setAssociatedObject(self, _LNPopupContentControllerDiscoveredTransitionView, objToSet, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
359+
}
360+
361+
- (LNPopupImageView *)_ln_discoveredTransitionView
362+
{
363+
_LNWeakRef* rv = objc_getAssociatedObject(self, _LNPopupContentControllerDiscoveredTransitionView);
364+
if(rv != nil && rv.object == nil)
365+
{
366+
[self _ln_setDiscoveredTransitionView:nil];
367+
}
368+
return rv.object;
369+
}
370+
349371
@end
350372

351373
@implementation UIViewController (LNCustomContainerPopupSupport)

LNPopupController/LNPopupController/Private/UIViewController+LNPopupSupportPrivate.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ void _LNPopupSupportSetPopupInsetsForViewController(UIViewController* controller
8080
- (BOOL)_ln_isObjectFromSwiftUI;
8181

8282
- (BOOL)_ln_shouldPopupContentViewFadeForTransition;
83+
@property (nullable, nonatomic, weak, setter=_ln_setDiscoveredTransitionView:, getter=_ln_discoveredTransitionView) LNPopupImageView* ln_discoveredTransitionView;
8384

8485
@end
8586

LNPopupController/LNPopupController/Private/UIViewController+LNPopupSupportPrivate.mm

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -484,21 +484,6 @@ - (void)_ln_willTransitionToTraitCollection:(UITraitCollection *)newCollection w
484484
}
485485
}
486486

487-
- (UIViewController*)_findAncestorParentPopupContainerController
488-
{
489-
if(self._ln_popupController_nocreate)
490-
{
491-
return self;
492-
}
493-
494-
if(self.parentViewController == nil)
495-
{
496-
return nil;
497-
}
498-
499-
return [self.parentViewController _findAncestorParentPopupContainerController];
500-
}
501-
502487
- (UIViewController*)_findChildInPopupPresentation
503488
{
504489
if(self._ln_popupController_nocreate)
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,13 @@
77
//
88

99
#import "_LNPopupTransitionCloseAnimator.h"
10+
#import <LNPopupController/UIViewController+LNPopupSupport.h>
1011

1112
NS_ASSUME_NONNULL_BEGIN
1213

1314
@interface _LNPopupTransitionPreferredCloseAnimator : _LNPopupTransitionCloseAnimator
1415

15-
@property (nonatomic, strong, readonly) LNPopupShadowedImageView* view;
16+
@property (nonatomic, strong, readonly) UIView<LNPopupTransitionView>* view;
1617

1718
@end
1819

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@
77
//
88

99
#import "_LNPopupTransitionOpenAnimator.h"
10-
#import <LNPopupController/LNPopupShadowedImageView.h>
10+
#import <LNPopupController/UIViewController+LNPopupSupport.h>
1111

1212
NS_ASSUME_NONNULL_BEGIN
1313

1414
@interface _LNPopupTransitionPreferredOpenAnimator : _LNPopupTransitionOpenAnimator
1515

16-
@property (nonatomic, strong, readonly) LNPopupShadowedImageView* view;
16+
@property (nonatomic, strong, readonly) UIView<LNPopupTransitionView>* view;
1717

1818
@end
1919

0 commit comments

Comments
 (0)