Skip to content

Commit 55a8b46

Browse files
committed
Improved Catalyst support
Removed more deprecated, unavailable API
1 parent 102f56c commit 55a8b46

22 files changed

+210
-171
lines changed

LNPCSwiftRefinements/SwiftRefinements.swift

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,23 @@ extension UIViewController {
122122
}
123123
}
124124
}
125+
126+
var effectivePopupInteractionStyle: PopupInteractionStyle {
127+
switch __effectivePopupInteractionStyle {
128+
case .drag:
129+
return .drag
130+
case .snap:
131+
return __popupSnapPercent == .defaultPopupSnapPercent ? .snap : .customizedSnap(percent: __popupSnapPercent)
132+
case .scroll:
133+
return .scroll
134+
case .none:
135+
return .none
136+
case .default:
137+
fallthrough
138+
@unknown default:
139+
fatalError("Please open an issue here: https://github.com/LeoNatan/LNPopupController/issues/new/choose")
140+
}
141+
}
125142
}
126143

127144
public

LNPopupController/LNPopupController/LNPopupBar.h

Lines changed: 0 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -116,66 +116,4 @@ NS_SWIFT_UI_ACTOR
116116

117117
@end
118118

119-
#pragma mark Deprecations
120-
121-
extern const UIBlurEffectStyle LNBackgroundStyleInherit LN_UNAVAILABLE_API("Use LNPopupBarAppearance instead.");
122-
123-
@interface LNPopupBar (Deprecated)
124-
125-
/// If `true`, the popup bar will automatically inherit its style from the bottom docking view.
126-
@property (nonatomic, assign) BOOL inheritsVisualStyleFromDockingView LN_UNAVAILABLE_API("Use inheritsAppearanceFromDockingView instead.");
127-
128-
/// The popup bar background style that specifies its appearance.
129-
///
130-
/// Use `LNBackgroundStyleInherit` value to inherit the docking view's bar style if possible, or use a system default.
131-
///
132-
/// Defaults to `LNBackgroundStyleInherit`.
133-
@property (nonatomic, assign) UIBlurEffectStyle backgroundStyle LN_UNAVAILABLE_API("Use LNPopupBarAppearance.backgroundEffect instead.");
134-
135-
/// The tint color to apply to the popup bar background.
136-
@property (nullable, nonatomic, strong) UIColor* barTintColor LN_UNAVAILABLE_API("Use LNPopupBarAppearance.backgroundColor instead.");
137-
138-
/// A Boolean value that indicates whether the popup bar is translucent (`true`) or not (`false`).
139-
@property(nonatomic, assign, getter=isTranslucent) BOOL translucent LN_UNAVAILABLE_API("Use LNPopupBarAppearance.configureWithOpaqueBackground() instead.");
140-
141-
/// Display attributes for the popup bar’s title text.
142-
///
143-
/// You may specify the font, text color, and shadow properties for the title in the text attributes dictionary, using the keys found in `NSAttributedString.h`.
144-
@property (nullable, nonatomic, copy) NSDictionary<NSAttributedStringKey, id>* titleTextAttributes LN_UNAVAILABLE_API("Use LNPopupBarAppearance.titleTextAttributes instead.");
145-
146-
/// Display attributes for the popup bar’s subtitle text.
147-
///
148-
/// You may specify the font, text color, and shadow properties for the title in the text attributes dictionary, using the keys found in `NSAttributedString.h`.
149-
@property (nullable, nonatomic, copy) NSDictionary<NSAttributedStringKey, id>* subtitleTextAttributes LN_UNAVAILABLE_API("Use LNPopupBarAppearance.subtitleTextAttributes instead.");
150-
151-
/// When enabled, titles and subtitles that are longer than the space available will scroll text over time.
152-
///
153-
/// Defaults to `false`.
154-
@property (nonatomic, assign) BOOL marqueeScrollEnabled LN_UNAVAILABLE_API("Use LNPopupBarAppearance.marqueeScrollEnabled instead.");
155-
156-
/// The scroll rate, in points, of the title and subtitle marquee animation.
157-
///
158-
/// Defaults to `30`.
159-
@property (nonatomic, assign) CGFloat marqueeScrollRate LN_UNAVAILABLE_API("Use LNPopupBarAppearance.marqueeScrollRate instead.");
160-
161-
/// The delay, in seconds, before starting the title and subtitle marquee animation.
162-
///
163-
/// Defaults to `2`.
164-
@property (nonatomic, assign) NSTimeInterval marqueeScrollDelay LN_UNAVAILABLE_API("Use LNPopupBarAppearance.marqueeScrollDelay instead.");
165-
166-
/// When enabled, the title and subtitle marquee scroll animations will be coordinated.
167-
///
168-
/// If either the title or subtitle of the current popup item change, the animation will reset so the two can scroll together.
169-
///
170-
/// Defaults to `true`.
171-
@property (nonatomic, assign) BOOL coordinateMarqueeScroll LN_UNAVAILABLE_API("Use LNPopupBarAppearance.coordinateMarqueeScroll instead.");
172-
173-
/// An array of custom bar button items to display on the left side. (read-only)
174-
@property (nullable, nonatomic, copy, readonly) NSArray<UIBarButtonItem*>* leftBarButtonItems LN_UNAVAILABLE_API("Use leadingBarButtonItems instead.");
175-
176-
/// An array of custom bar button items to display on the right side. (read-only)
177-
@property (nullable, nonatomic, copy, readonly) NSArray<UIBarButtonItem*>* rightBarButtonItems LN_UNAVAILABLE_API("Use barButtonItems or trailingBarButtonItems instead.");
178-
179-
@end
180-
181119
NS_ASSUME_NONNULL_END

LNPopupController/LNPopupController/LNPopupCloseButton.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,16 @@ NS_SWIFT_UI_ACTOR
3636
@interface LNPopupCloseButton : UIButton <UIAppearanceContainer>
3737

3838
/// Gets or sets the style of the popup close button. Has the same effect as setting the `LNPopupContentView.popupCloseButtonStyle` property of the popup content view.
39-
@property (nonatomic) LNPopupCloseButtonStyle style UI_APPEARANCE_SELECTOR;
39+
@property (nonatomic, assign) LNPopupCloseButtonStyle style UI_APPEARANCE_SELECTOR;
40+
41+
/// The effective popup close button style used by the system. (read-only)
42+
///
43+
/// Use this property's value to determine, at runtime, what the result of `LNPopupCloseButtonStyleDefault` is.
44+
@property (nonatomic, assign, readonly) LNPopupCloseButtonStyle effectiveStyle;
4045

4146
/// The button’s background view. (read-only)
4247
///
43-
/// The value of this property will be `nil` if ``style`` is not set to `LNPopupCloseButtonStyleRound`.
48+
/// The value of this property will be `nil` if `style` is set to any value other than `LNPopupCloseButtonStyleRound`.
4449
///
4550
/// @note Although this property is read-only, its own properties are read/write. Use these properties to configure the appearance and behavior of the button’s background view.
4651
@property (nonatomic, strong, readonly) UIVisualEffectView* backgroundView;

LNPopupController/LNPopupController/LNPopupContentView.h

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,12 @@ NS_SWIFT_UI_ACTOR
2525
/// The popup close button style.
2626
///
2727
/// Defaults to `LNPopupCloseButtonStyleDefault`.
28-
@property (nonatomic) LNPopupCloseButtonStyle popupCloseButtonStyle UI_APPEARANCE_SELECTOR;
28+
@property (nonatomic, assign) LNPopupCloseButtonStyle popupCloseButtonStyle UI_APPEARANCE_SELECTOR;
29+
30+
/// The effective popup close button style used by the system. (read-only)
31+
///
32+
/// Use this property's value to determine, at runtime, what the result of `LNPopupCloseButtonStyleDefault` is.
33+
@property (nonatomic, assign, readonly) LNPopupCloseButtonStyle effectivePopupCloseButtonStyle;
2934

3035
/// The popup close button. (read-only)
3136
@property (nonatomic, strong, readonly) LNPopupCloseButton* popupCloseButton;
@@ -44,24 +49,4 @@ NS_SWIFT_UI_ACTOR
4449

4550
@end
4651

47-
#pragma mark Deprecations
48-
49-
extern const UIBlurEffectStyle LNBackgroundStyleInherit LN_UNAVAILABLE_API("Use backgroundEffect instead.");
50-
51-
@interface LNPopupContentView (Deprecated)
52-
53-
/// Attempt to automatically move the popup close button under top bars, such as navigation bars.
54-
///
55-
/// Note: No longer supported. Instead, implement `UIViewController.positionPopupCloseButton()` and position the button in your content controller's view hierarchy.
56-
@property (nonatomic) BOOL popupCloseButtonAutomaticallyUnobstructsTopBars LN_UNAVAILABLE_API("No longer supported. Instead, implement UIViewController.positionPopupCloseButton() and position the button in your content controller's view hierarchy.");
57-
58-
/// The popup content view background style, used when the popup content controller's view has transparency.
59-
///
60-
/// Use `LNBackgroundStyleInherit` value to inherit the popup bar's background style if possible.
61-
///
62-
/// Defaults to `LNBackgroundStyleInherit`.
63-
@property (nonatomic, assign) UIBlurEffectStyle backgroundStyle LN_UNAVAILABLE_API("Use backgroundEffect instead.");
64-
65-
@end
66-
6752
NS_ASSUME_NONNULL_END

LNPopupController/LNPopupController/Private/LNPopupBar+Private.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ inline __attribute__((always_inline)) LNPopupBarStyle _LNPopupResolveBarStyleFro
138138

139139
- (void)_cancelAnyUserInteraction;
140140

141+
+ (BOOL)isCatalystApp;
141142
- (BOOL)isWidePad;
142143

143144
@end

LNPopupController/LNPopupController/Private/LNPopupBar.mm

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,7 @@ - (nonnull instancetype)initWithFrame:(CGRect)frame
444444
_contentView.clipsToBounds = NO;
445445
[self addSubview:_contentView];
446446

447-
if (@available(iOS 13.4, *))
447+
if(@available(iOS 13.4, *))
448448
{
449449
UIPointerInteraction* pointerInteraction = [[UIPointerInteraction alloc] initWithDelegate:self];
450450
[_contentView addInteraction:pointerInteraction];
@@ -2129,8 +2129,24 @@ - (void)_cancelGestureRecognizers
21292129
}
21302130
}
21312131

2132+
+ (BOOL)isCatalystApp
2133+
{
2134+
BOOL isCatalystApp = NSProcessInfo.processInfo.isMacCatalystApp;
2135+
if(@available(iOS 14.0, *))
2136+
{
2137+
isCatalystApp = isCatalystApp || NSProcessInfo.processInfo.iOSAppOnMac;
2138+
}
2139+
2140+
return isCatalystApp;
2141+
}
2142+
21322143
- (BOOL)isWidePad
21332144
{
2145+
if(LNPopupBar.isCatalystApp)
2146+
{
2147+
return YES;
2148+
}
2149+
21342150
return self.traitCollection.horizontalSizeClass == UIUserInterfaceSizeClassRegular && UIDevice.currentDevice.userInterfaceIdiom == UIUserInterfaceIdiomPad;
21352151
}
21362152

LNPopupController/LNPopupController/Private/LNPopupCloseButton.mm

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ - (instancetype)initWithContainingContentView:(LNPopupContentView*)contentView
7474
_style = LNPopupCloseButtonStyleGrabber;
7575
[self _setupForChevronButton];
7676

77-
if (@available(iOS 13.4, *))
77+
if(@available(iOS 13.4, *))
7878
{
7979
self.pointerInteractionEnabled = YES;
8080
self.pointerStyleProvider = ^UIPointerStyle * _Nullable(UIButton * _Nonnull button, UIPointerEffect * _Nonnull proposedEffect, UIPointerShape * _Nonnull proposedShape) {
@@ -89,6 +89,11 @@ - (instancetype)initWithContainingContentView:(LNPopupContentView*)contentView
8989
return self;
9090
}
9191

92+
- (LNPopupCloseButtonStyle)effectiveStyle
93+
{
94+
return self.popupContentView.effectivePopupCloseButtonStyle;
95+
}
96+
9297
- (void)setStyle:(LNPopupCloseButtonStyle)style
9398
{
9499
//This will take care of cases where the user sets LNPopupCloseButtonStyleDefault as well as close button repositioning.

LNPopupController/LNPopupController/Private/LNPopupContentView.m

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,14 @@ LNPopupCloseButtonStyle _LNPopupResolveCloseButtonStyleFromCloseButtonStyle(LNPo
1616
LNPopupCloseButtonStyle rv = style;
1717
if(rv == LNPopupCloseButtonStyleDefault)
1818
{
19-
#if TARGET_OS_MACCATALYST
20-
rv = LNPopupCloseButtonStyleRound;
21-
#else
22-
rv = LNPopupCloseButtonStyleGrabber;
23-
#endif
19+
if([LNPopupBar isCatalystApp])
20+
{
21+
rv = LNPopupCloseButtonStyleRound;
22+
}
23+
else
24+
{
25+
rv = LNPopupCloseButtonStyleGrabber;
26+
}
2427
}
2528
return rv;
2629
}
@@ -54,7 +57,7 @@ - (nonnull instancetype)initWithFrame:(CGRect)frame
5457
_popupCloseButton.popupContentView = self;
5558

5659
__weak __typeof(self) weakSelf = self;
57-
if (@available(iOS 13.4, *))
60+
if(@available(iOS 13.4, *))
5861
{
5962
_popupCloseButton.pointerInteractionEnabled = YES;
6063
_popupCloseButton.pointerStyleProvider = ^ UIPointerStyle* (UIButton *button, UIPointerEffect *proposedEffect, UIPointerShape *proposedShape) {
@@ -219,6 +222,10 @@ - (void)_repositionPopupCloseButtonAnimated:(BOOL)animated
219222
topConstant += layoutFrame.origin.y;
220223
topConstant = MAX(self.popupCloseButton.style == LNPopupCloseButtonStyleRound ? 12 : 0, topConstant);
221224

225+
#if TARGET_OS_MACCATALYST
226+
topConstant += 20;
227+
#endif
228+
222229
CGFloat leadingConstant = layoutFrame.origin.x;
223230

224231
if(topConstant != _popupCloseButtonTopConstraint.constant || leadingConstant != _popupCloseButtonLeadingConstraint.constant)

0 commit comments

Comments
 (0)