Skip to content

Commit

Permalink
Change how Objective C enums are imported into Swift
Browse files Browse the repository at this point in the history
`LNPopupBarStyle` -> `LNPopupBar.Style`
`LNPopupBarProgressViewStyle` -> `LNPopupBar.ProgressViewStyle`
`LNPopupCloseButtonStyle` -> `LNPopupCloseButton.Style`
`LNPopupInteractionStyle` -> `UIViewController.PopupInteractionStyle`
`LNPopupPresentationState` -> `UIViewController.PopupPresentationState`

Since this and the previous commit are API changes, bumping the minor version. In most cases, the compiler should give an appropriate “Moved” message to help ease the transition.
  • Loading branch information
LeoNatan committed Oct 21, 2023
1 parent 18ee619 commit 03549cc
Show file tree
Hide file tree
Showing 10 changed files with 65 additions and 61 deletions.
37 changes: 19 additions & 18 deletions LNPCSwiftRefinements/SwiftRefinements.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,27 @@ extension Double {
}
}

/// Available interaction styles with the popup bar and popup content view.
public enum LNPopupInteractionStyle {
/// The default interaction style for the current environment.
case `default`
/// Drag interaction style.
case drag
/// Snap interaction style.
case snap
/// Customized snap interaction style.
/// - Parameter percent: The percent of the container controller's view height to drag before closing the popup.
case customizedSnap(percent: Double)
/// Scroll interaction style.
case scroll
/// No interaction.
case none
}

public extension UIViewController {
/// Available interaction styles with the popup bar and popup content view.
enum PopupInteractionStyle {
/// The default interaction style for the current environment.
case `default`
/// Drag interaction style.
case drag
/// Snap interaction style.
case snap
/// Customized snap interaction style.
/// - Parameter percent: The percent of the container controller's view height to drag before closing the popup.
case customizedSnap(percent: Double)
/// Scroll interaction style.
case scroll
/// No interaction.
case none
}


/// The popup bar interaction style.
var popupInteractionStyle: LNPopupInteractionStyle {
var popupInteractionStyle: PopupInteractionStyle {
get {
switch __popupInteractionStyle {
case .none:
Expand Down
2 changes: 1 addition & 1 deletion LNPopupController/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>2.15.24</string>
<string>2.16.-1</string>
<key>CFBundleVersion</key>
<string>1</string>
<key>LSRequiresIPhoneOS</key>
Expand Down
4 changes: 2 additions & 2 deletions LNPopupController/LNPopupController/LNPopupBar.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ typedef NS_ENUM(NSInteger, LNPopupBarStyle) {
///
/// Do not set this style directly. Instead, set the `LNPopupBar.customBarViewController` property and the framework will use this style.
LNPopupBarStyleCustom = 0xFFFF
};
} NS_SWIFT_NAME(LNPopupBar.Style);

/// Available styles for the popup bar progress view.
typedef NS_ENUM(NSInteger, LNPopupBarProgressViewStyle) {
Expand All @@ -49,7 +49,7 @@ typedef NS_ENUM(NSInteger, LNPopupBarProgressViewStyle) {

/// No progress view
LNPopupBarProgressViewStyleNone = 0xFFFF
};
} NS_SWIFT_NAME(LNPopupBar.ProgressViewStyle);

NS_SWIFT_UI_ACTOR
/// A popup bar is a control that displays popup information. Content is populated from ``LNPopupItem`` items.
Expand Down
2 changes: 1 addition & 1 deletion LNPopupController/LNPopupController/LNPopupCloseButton.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ typedef NS_ENUM(NSInteger, LNPopupCloseButtonStyle) {
LNPopupCloseButtonStyleNone = 0xFFFF,

LNPopupCloseButtonStyleFlat LN_DEPRECATED_API("Use LNPopupCloseButtonStyle.grabber instead.") = LNPopupCloseButtonStyleGrabber
};
} NS_SWIFT_NAME(LNPopupCloseButton.Style);

NS_ASSUME_NONNULL_BEGIN

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

NS_ASSUME_NONNULL_BEGIN

@class UIViewController;

NS_REFINED_FOR_SWIFT
/// The default popup snap percent. See `UIViewController.popupSnapPercent` for more information.
extern const double LNSnapPercentDefault;
Expand All @@ -35,7 +37,7 @@ typedef NS_ENUM(NSInteger, LNPopupInteractionStyle) {

/// No interaction
LNPopupInteractionStyleNone = 0xFFFF
} NS_SWIFT_NAME(__LNPopupInteractionStyle);
} NS_SWIFT_NAME(UIViewController.__PopupInteractionStyle);

/// The state of the popup presentation.
typedef NS_ENUM(NSInteger, LNPopupPresentationState){
Expand All @@ -51,7 +53,7 @@ typedef NS_ENUM(NSInteger, LNPopupPresentationState){
LNPopupPresentationStateHidden LN_DEPRECATED_API("Use LNPopupPresentationStateBarHidden instead.") = LNPopupPresentationStateBarHidden,
LNPopupPresentationStateClosed LN_DEPRECATED_API("Use LNPopupPresentationStateBarPresented instead.") = LNPopupPresentationStateBarPresented,
LNPopupPresentationStateTransitioning LN_DEPRECATED_API("Should no longer be used.") = 2,
};
} NS_SWIFT_NAME(UIViewController.PopupPresentationState);

/// Popup content support for ``UIViewController`` subclasses.
@interface UIViewController (LNPopupContent)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class DemoAlbumTableViewController: UITableViewController {
tableView.separatorEffect = UIVibrancyEffect(blurEffect: UIBlurEffect(style: .systemThinMaterial))

#if LNPOPUP
let barStyle = LNPopupBarStyle(rawValue: UserDefaults.standard.object(forKey: PopupSettingsBarStyle) as? Int ?? 0)!
let barStyle = LNPopupBar.Style(rawValue: UserDefaults.standard.object(forKey: PopupSettingsBarStyle) as? Int ?? 0)!
tabBarController?.popupBar.barStyle = barStyle

if tabBarController?.popupBar.effectiveBarStyle == .floating {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ class DemoMusicPlayerController: UIHostingController<PlayerView> {

let playPause = playerView.playbackSettings.isPlaying ? pause : play

if LNPopupBarStyle(rawValue: UserDefaults.standard.object(forKey: PopupSettingsBarStyle) as? Int ?? 0)! == LNPopupBarStyle.compact {
if LNPopupBar.Style(rawValue: UserDefaults.standard.object(forKey: PopupSettingsBarStyle) as? Int ?? 0)! == LNPopupBar.Style.compact {
popupItem.leadingBarButtonItems = [ playPause ]
popupItem.trailingBarButtonItems = [ next ]
} else {
Expand Down Expand Up @@ -237,7 +237,7 @@ class DemoMusicPlayerController: UIHostingController<PlayerView> {

var albumTitle: String = "" {
didSet {
if LNPopupBarStyle(rawValue: UserDefaults.standard.object(forKey: PopupSettingsBarStyle) as? Int ?? 0)! == .compact {
if LNPopupBar.Style(rawValue: UserDefaults.standard.object(forKey: PopupSettingsBarStyle) as? Int ?? 0)! == .compact {
popupItem.subtitle = albumTitle
}
playerView.playbackSettings.albumTitle = albumTitle
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ fileprivate struct CellPaddedToggle<S>: View where S: StringProtocol {
}

struct SettingsView : View {
@AppStorage(PopupSettingsBarStyle) var barStyle: LNPopupBarStyle = .default
@AppStorage(PopupSettingsInteractionStyle) var interactionStyle: __LNPopupInteractionStyle = .default
@AppStorage(PopupSettingsCloseButtonStyle) var closeButtonStyle: LNPopupCloseButtonStyle = .default
@AppStorage(PopupSettingsProgressViewStyle) var progressViewStyle: LNPopupBarProgressViewStyle = .default
@AppStorage(PopupSettingsBarStyle) var barStyle: LNPopupBar.Style = .default
@AppStorage(PopupSettingsInteractionStyle) var interactionStyle: UIViewController.__PopupInteractionStyle = .default
@AppStorage(PopupSettingsCloseButtonStyle) var closeButtonStyle: LNPopupCloseButton.Style = .default
@AppStorage(PopupSettingsProgressViewStyle) var progressViewStyle: LNPopupBar.ProgressViewStyle = .default
@AppStorage(PopupSettingsMarqueeStyle) var marqueeStyle: Int = 0
@AppStorage(PopupSettingsVisualEffectViewBlurEffect) var blurEffectStyle: UIBlurEffect.Style = .default

Expand All @@ -79,39 +79,39 @@ struct SettingsView : View {
var body: some View {
Form {
Picker(selection: $barStyle) {
CellPaddedText("Default").tag(LNPopupBarStyle.default)
CellPaddedText("Compact").tag(LNPopupBarStyle.compact)
CellPaddedText("Prominent").tag(LNPopupBarStyle.prominent)
CellPaddedText("Floating").tag(LNPopupBarStyle.floating)
CellPaddedText("Default").tag(LNPopupBar.Style.default)
CellPaddedText("Compact").tag(LNPopupBar.Style.compact)
CellPaddedText("Prominent").tag(LNPopupBar.Style.prominent)
CellPaddedText("Floating").tag(LNPopupBar.Style.floating)
} label: {
Text("Bar Style")
}

Picker(selection: $interactionStyle) {
CellPaddedText("Default").tag(__LNPopupInteractionStyle.default)
CellPaddedText("Drag").tag(__LNPopupInteractionStyle.drag)
CellPaddedText("Snap").tag(__LNPopupInteractionStyle.snap)
CellPaddedText("Scroll").tag(__LNPopupInteractionStyle.scroll)
CellPaddedText("None").tag(__LNPopupInteractionStyle.none)
CellPaddedText("Default").tag(UIViewController.__PopupInteractionStyle.default)
CellPaddedText("Drag").tag(UIViewController.__PopupInteractionStyle.drag)
CellPaddedText("Snap").tag(UIViewController.__PopupInteractionStyle.snap)
CellPaddedText("Scroll").tag(UIViewController.__PopupInteractionStyle.scroll)
CellPaddedText("None").tag(UIViewController.__PopupInteractionStyle.none)
} label: {
Text("Interaction Style")
}

Picker(selection: $closeButtonStyle) {
CellPaddedText("Default").tag(LNPopupCloseButtonStyle.default)
CellPaddedText("Round").tag(LNPopupCloseButtonStyle.round)
CellPaddedText("Chevron").tag(LNPopupCloseButtonStyle.chevron)
CellPaddedText("Grabber").tag(LNPopupCloseButtonStyle.grabber)
CellPaddedText("None").tag(LNPopupCloseButtonStyle.none)
CellPaddedText("Default").tag(LNPopupCloseButton.Style.default)
CellPaddedText("Round").tag(LNPopupCloseButton.Style.round)
CellPaddedText("Chevron").tag(LNPopupCloseButton.Style.chevron)
CellPaddedText("Grabber").tag(LNPopupCloseButton.Style.grabber)
CellPaddedText("None").tag(LNPopupCloseButton.Style.none)
} label: {
Text("Close Button Style")
}

Picker(selection: $progressViewStyle) {
CellPaddedText("Default").tag(LNPopupBarProgressViewStyle.default)
CellPaddedText("Top").tag(LNPopupBarProgressViewStyle.top)
CellPaddedText("Bottom").tag(LNPopupBarProgressViewStyle.bottom)
CellPaddedText("None").tag(LNPopupBarProgressViewStyle.none)
CellPaddedText("Default").tag(LNPopupBar.ProgressViewStyle.default)
CellPaddedText("Top").tag(LNPopupBar.ProgressViewStyle.top)
CellPaddedText("Bottom").tag(LNPopupBar.ProgressViewStyle.bottom)
CellPaddedText("None").tag(LNPopupBar.ProgressViewStyle.none)
} label: {
Text("Progress View Style")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,6 @@
<segue destination="okN-9b-CNT" kind="relationship" relationship="viewControllers" id="mpW-FJ-VUz"/>
<segue destination="okN-9b-CNT" kind="relationship" relationship="viewControllers" id="LFb-4R-xoq"/>
<segue destination="okN-9b-CNT" kind="relationship" relationship="viewControllers" id="vYe-8f-bz7"/>
<segue destination="okN-9b-CNT" kind="relationship" relationship="viewControllers" id="rYC-SC-1Ud"/>
</connections>
</tabBarController>
<placeholder placeholderIdentifier="IBFirstResponder" id="RRw-0R-8hQ" userLabel="First Responder" sceneMemberID="firstResponder"/>
Expand Down Expand Up @@ -587,7 +586,6 @@
<segue destination="l54-z5-xcG" kind="relationship" relationship="viewControllers" id="jsa-yG-B84"/>
<segue destination="l54-z5-xcG" kind="relationship" relationship="viewControllers" id="sDT-1s-aAn"/>
<segue destination="l54-z5-xcG" kind="relationship" relationship="viewControllers" id="nft-Ob-3Yp"/>
<segue destination="l54-z5-xcG" kind="relationship" relationship="viewControllers" id="FwL-Jm-YrX"/>
</connections>
</tabBarController>
<placeholder placeholderIdentifier="IBFirstResponder" id="JzB-yf-S2V" userLabel="First Responder" sceneMemberID="firstResponder"/>
Expand Down Expand Up @@ -616,7 +614,7 @@
<segue reference="08s-5F-WiR"/>
<segue reference="7V8-5m-eAW"/>
<segue reference="SIC-fE-4sh"/>
<segue reference="Jqg-bQ-l0b"/>
<segue reference="nft-Ob-3Yp"/>
<segue reference="1U6-NV-9t4"/>
<segue reference="iD8-2E-cMh"/>
<segue reference="SDh-r0-h83"/>
Expand Down
21 changes: 12 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ Customizing the popup bar progress view style is achieved by setting the popup b
navigationController?.popupBar.progressViewStyle = .top
```

To hide the progress view, set the `progressViewStyle` property to `LNPopupBarProgressViewStyle.none`.
To hide the progress view, set the `progressViewStyle` property to `LNPopupBar.ProgressViewStyle.none`.

<p align="center"><img src="./Supplements/progress_view_none.png" width="360"/><br/><br/><img src="./Supplements/progress_view_top.png" width="360"/><br/><br/><img src="./Supplements/progress_view_bottom.png" width="360"/></p>

Expand All @@ -218,7 +218,7 @@ Customizing the popup close button style is achieved by setting the popup conten
navigationController.popupContentView.popupCloseButtonStyle = .round
```

To hide the popup close button, set the `popupCloseButtonStyle` property to `LNPopupCloseButtonStyle.none`.
To hide the popup close button, set the `popupCloseButtonStyle` property to `LNPopupCloseButton.Style.none`.

<p align="center"><img src="./Supplements/close_button_none.png" width="360"/><br/><br/><img src="./Supplements/close_button_chevron.png" width="360"/><br/><br/><img src="./Supplements/close_button_round.png" width="360"/></p>

Expand All @@ -236,14 +236,17 @@ Remember to set the `inheritsAppearanceFromDockingView` property to `false`, or

```swift
let appearance = LNPopupBarAppearance()
appearance.titleTextAttributes = [.font: UIFont(name: "Chalkduster", size: 14)!, .foregroundColor: UIColor.yellow]
appearance.subtitleTextAttributes = [.font: UIFont(name: "Chalkduster", size: 12)!, .foregroundColor: UIColor.green]
appearance.titleTextAttributes = AttributeContainer()
.font(UIFontMetrics(forTextStyle: .headline).scaledFont(for: UIFont(name: "Chalkduster", size: 14)!))
.foregroundColor(UIColor.yellow)
appearance.subtitleTextAttributes = AttributeContainer()
.font(UIFontMetrics(forTextStyle: .subheadline).scaledFont(for: UIFont(name: "Chalkduster", size: 12)!))
.foregroundColor(UIColor.green)
appearance.backgroundEffect = UIBlurEffect(style: .systemChromeMaterialDark)

let appearanceProxy = LNPopupBar.appearance(whenContainedInInstancesOf: [UINavigationController.self])
appearanceProxy.inheritsAppearanceFromDockingView = false
appearanceProxy.standardAppearance = appearance
appearanceProxy.tintColor = .yellow
navigationController?.popupBar.inheritsAppearanceFromDockingView = false
navigationController?.popupBar.standardAppearance = appearance
navigationController?.popupBar.tintColor = .yellow
```

<p align="center"><img src="./Supplements/floating_custom.png" width="360"/> <img src="./Supplements/modern_custom.png" width="360"/> <img src="./Supplements/custom1.png" width="360"/></p>
Expand All @@ -260,7 +263,7 @@ In your `LNPopupCustomBarViewController` subclass, build your popup bar's view h

In your subclass, implement the `popupItemDidUpdate()` method to be notified of updates to the popup content view controller's item, or when a new popup content view controller is presented (with a new popup item). You must call the `super` implementation of this method.

Finally, set the `customBarViewController` property of the popup bar object to an instance of your `LNPopupCustomBarViewController` subclass. This will change the bar style to `LNPopupBarStyle.custom`.
Finally, set the `customBarViewController` property of the popup bar object to an instance of your `LNPopupCustomBarViewController` subclass. This will automatically change the bar style to `LNPopupBar.Style.custom`.

The included demo project includes two example custom popup bar scenes.

Expand Down

0 comments on commit 03549cc

Please sign in to comment.