Skip to content

Commit

Permalink
Demo project updates
Browse files Browse the repository at this point in the history
  • Loading branch information
LeoNatan committed Oct 17, 2024
1 parent 1fcbe30 commit 261151a
Show file tree
Hide file tree
Showing 8 changed files with 141 additions and 66 deletions.
2 changes: 1 addition & 1 deletion LNPopupSettings
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@ struct NavDemoView : View {

var body: some View {
MaterialNavigationStack {
SafeAreaDemoView(colorSeed:"nil", includeToolbar: true, includeLink: true, presentBarHandler: presentBarHandler, appearanceHandler: appearanceHandler, hideBarHandler: hideBarHandler, showDismissButton: false, onDismiss: onDismiss)
let bottomButtonsHandlers = SafeAreaDemoView.BottomButtonHandlers(presentBarHandler: presentBarHandler, appearanceHandler: appearanceHandler, hideBarHandler: hideBarHandler)
let bottomBarHideSupport = SafeAreaDemoView.BottomBarHideSupport(showsBottomBarHideButton: true)

SafeAreaDemoView(colorSeed:"nil", includeToolbar: true, includeLink: true, bottomButtonsHandlers: bottomButtonsHandlers, showDismissButton: false, onDismiss: onDismiss, bottomBarHideSupport: bottomBarHideSupport)
.navigationBarTitle("Navigation View")
.navigationBarTitleDisplayMode(.inline)
.toolbar {
Expand Down
93 changes: 65 additions & 28 deletions LNPopupUIExample/LNPopupUIExample/DemoScenes/PopupDemoView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -90,18 +90,29 @@ struct BackgroundViewColorModifier: ViewModifier {
}

struct HideShowTabBarModifier: ViewModifier {
let includePadding: Bool
let hideShowTabBar: () -> Void
@Environment(\.horizontalSizeClass) var horizontalSizeClass

@Binding var bottomBarHideSupport: SafeAreaDemoView.BottomBarHideSupport?

@ViewBuilder func body(content: Content) -> some View {
content.toolbar {
ToolbarItem(placement: .navigationBarLeading) {
Button {
hideShowTabBar()
} label: {
Image(systemName: "rectangle.bottomthird.inset.fill")
}.padding(includePadding ? .horizontal : [], 8)
if #available(iOS 18.0, *), bottomBarHideSupport?.showsBottomBarHideButton ?? false {
content.toolbar {
ToolbarItem(placement: .navigationBarLeading) {
Button {
withAnimation {
bottomBarHideSupport?.isBottomBarPresented.toggle()
}
} label: {
if UIDevice.current.userInterfaceIdiom == .pad && horizontalSizeClass == .regular && bottomBarHideSupport?.isBottomBarTab ?? false {
Image(systemName: "rectangle.topthird.inset.filled")
} else {
Image(systemName: "rectangle.bottomthird.inset.filled")
}
}
}
}
} else {
content
}
}
}
Expand All @@ -116,6 +127,18 @@ struct TrailingImageLabelStyle: LabelStyle {
}

struct SafeAreaDemoView : View {
struct BottomButtonHandlers {
var presentBarHandler: (() -> Void)? = nil
var appearanceHandler: (() -> Void)? = nil
var hideBarHandler: (() -> Void)? = nil
}

struct BottomBarHideSupport {
var showsBottomBarHideButton: Bool = false
var isBottomBarTab: Bool? = false
var isBottomBarPresented: Bool = true
}

let includeLink: Bool
let includeToolbar: Bool
let offset: Bool
Expand All @@ -131,10 +154,9 @@ struct SafeAreaDemoView : View {
let appearanceHandler: (() -> Void)?
let hideBarHandler: (() -> Void)?

@State private var isBottomBarPresented: Bool
let bottomBarPresentationButtonPadding: Bool
@State var bottomBarHideSupport: BottomBarHideSupport?

init(colorSeed: String = "nil", colorIndex: Int = 0, includeToolbar: Bool = false, includeLink: Bool = false, offset: Bool = false, isPopupOpen: Binding<Bool>? = nil, presentBarHandler: (() -> Void)? = nil, appearanceHandler: (() -> Void)? = nil, hideBarHandler: (() -> Void)? = nil, showDismissButton: Bool? = nil, onDismiss: (() -> Void)? = nil, isBottomBarPresented: State<Bool>? = nil) {
init(colorSeed: String = "nil", colorIndex: Int = 0, includeToolbar: Bool = false, includeLink: Bool = false, offset: Bool = false, isPopupOpen: Binding<Bool>? = nil, bottomButtonsHandlers: BottomButtonHandlers? = nil, showDismissButton: Bool? = nil, onDismiss: (() -> Void)? = nil, bottomBarHideSupport: BottomBarHideSupport? = nil) {
self.includeLink = includeLink
self.includeToolbar = includeToolbar
self.offset = offset
Expand All @@ -150,12 +172,11 @@ struct SafeAreaDemoView : View {
self.colorSeed = colorSeed
self.colorIndex = colorIndex

self.presentBarHandler = presentBarHandler
self.appearanceHandler = appearanceHandler
self.hideBarHandler = hideBarHandler
self.presentBarHandler = bottomButtonsHandlers?.presentBarHandler
self.appearanceHandler = bottomButtonsHandlers?.appearanceHandler
self.hideBarHandler = bottomButtonsHandlers?.hideBarHandler

_isBottomBarPresented = isBottomBarPresented ?? State(initialValue: true)
bottomBarPresentationButtonPadding = isBottomBarPresented != nil
_bottomBarHideSupport = State(initialValue: bottomBarHideSupport)
}

var body: some View {
Expand Down Expand Up @@ -200,8 +221,11 @@ struct SafeAreaDemoView : View {
Spacer()

NavigationLink {
SafeAreaDemoView(colorSeed: colorSeed, colorIndex: colorIndex + 1, includeToolbar: includeToolbar, includeLink: includeLink, presentBarHandler: presentBarHandler, appearanceHandler: appearanceHandler, hideBarHandler: hideBarHandler, showDismissButton: true, onDismiss: onDismiss, isBottomBarPresented: _isBottomBarPresented)
let bottomButtonsHandlers = BottomButtonHandlers(presentBarHandler: presentBarHandler, appearanceHandler: appearanceHandler, hideBarHandler: hideBarHandler)

SafeAreaDemoView(colorSeed: colorSeed, colorIndex: colorIndex + 1, includeToolbar: includeToolbar, includeLink: includeLink, bottomButtonsHandlers: bottomButtonsHandlers, showDismissButton: true, onDismiss: onDismiss)
.navigationTitle("LNPopupUI")
.toolbarRoleIfPad18()
} label: {
Label {
Text("Next")
Expand All @@ -218,11 +242,9 @@ struct SafeAreaDemoView : View {
.edgesIgnoringSafeArea([.top, .bottom])
.fontWeight(.semibold)
.tint(Color(uiColor: .label))
.modifier(HideShowTabBarModifier(includePadding: bottomBarPresentationButtonPadding) {
isBottomBarPresented.toggle()
})
.toolbar(includeToolbar && isBottomBarPresented ? .visible : .hidden, for: .bottomBar)
.toolbar(isBottomBarPresented ? .visible : .hidden, for: .tabBar)
.modifier(HideShowTabBarModifier(bottomBarHideSupport: $bottomBarHideSupport))
.toolbar(includeToolbar && bottomBarHideSupport?.isBottomBarPresented ?? true ? .visible : .hidden, for: .bottomBar)
.toolbar(bottomBarHideSupport?.isBottomBarPresented ?? true ? .visible : .hidden, for: .tabBar)
}
}
}
Expand All @@ -242,6 +264,14 @@ struct HapticFeedbackModifier: ViewModifier {
}
}

struct LimitFloatingContentWidthModifier: ViewModifier {
@AppStorage(.limitFloatingWidth, store: .settings) var limitFloatingWidth: Bool = true

@ViewBuilder func body(content: Content) -> some View {
content.popupBarLimitFloatingContentWidth(limitFloatingWidth)
}
}

struct MarqueeModifier: ViewModifier {
@AppStorage(.marqueeEnabled, store: .settings) var marqueeEnabled: Bool = false
@AppStorage(.marqueeCoordinationEnabled, store: .settings) var marqueeCoordinationEnabled: Bool = true
Expand Down Expand Up @@ -446,6 +476,7 @@ struct PopupDemoViewModifier: ViewModifier {
.popupCloseButtonStyle(closeButtonStyle)
.modifier(MarqueeModifier())
.modifier(HapticFeedbackModifier())
.modifier(LimitFloatingContentWidthModifier())
.modifier(FloatingBackgroundEffectModifier(blurEffectStyle: blurEffectStyle, barStyle: barStyle))
.modifier(BackgroundEffectModifier(blurEffectStyle: blurEffectStyle, barStyle: barStyle))
.modifier(CustomBarModifier(customPopupBar: customPopupBar))
Expand Down Expand Up @@ -495,16 +526,22 @@ fileprivate extension View {
}

struct MaterialTabView<Content: View>: View {
let content: Content
let tabView: any View


init(@ViewBuilder content: () -> Content) {
self.content = content()
tabView = TabView {
content().fixBottomBarAppearance()
}
}

@available(iOS 18.0, *)
init<C>(@TabContentBuilder<Never> content: () -> C) where Content == TabContentBuilder<Never>.Content<C>, C : TabContent {
tabView = TabView.init<C>(content: content)
}

var body: some View {
TabView {
content.fixBottomBarAppearance()
}
AnyView(tabView)
}
}

Expand Down
28 changes: 11 additions & 17 deletions LNPopupUIExample/LNPopupUIExample/DemoScenes/TabDemoView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ struct InnerView : View {

var body: some View {
ZStack(alignment: .topTrailing) {
SafeAreaDemoView(colorSeed: tabIdx != nil ? (tabIdx! == -1 ? "tab_\(Int.random(in: 0..<1000))" : "tab_\(tabIdx!)") : "nil", presentBarHandler: presentBarHandler, hideBarHandler: hideBarHandler, showDismissButton: showDismissButton)
let bottomButtonsHandlers = SafeAreaDemoView.BottomButtonHandlers(presentBarHandler: presentBarHandler, hideBarHandler: hideBarHandler)

SafeAreaDemoView(colorSeed: tabIdx != nil ? (tabIdx! == -1 ? "tab_\(Int.random(in: 0..<1000))" : "tab_\(tabIdx!)") : "nil", bottomButtonsHandlers: bottomButtonsHandlers, showDismissButton: showDismissButton)
if let showDismissButton, showDismissButton == true {
VStack {
Button("Gallery") {
Expand All @@ -43,6 +45,8 @@ struct InnerView : View {
}

struct TabDemoView : View {
@Environment(\.horizontalSizeClass) var horizontalSizeClass

@State private var isBarPresented: Bool = true
private let onDismiss: () -> Void
let demoContent: DemoContent
Expand All @@ -62,22 +66,12 @@ struct TabDemoView : View {

var body: some View {
MaterialTabView {
InnerView(tabIdx:0, onDismiss: onDismiss, presentBarHandler: presentBarHandler, hideBarHandler: hideBarHandler)
.tabItem {
Label("Tab", systemImage: "1.square")
}
InnerView(tabIdx:1, onDismiss: onDismiss, presentBarHandler: presentBarHandler, hideBarHandler: hideBarHandler)
.tabItem {
Label("Tab", systemImage: "2.square")
}
InnerView(tabIdx:2, onDismiss: onDismiss, presentBarHandler: presentBarHandler, hideBarHandler: hideBarHandler)
.tabItem {
Label("Tab", systemImage: "3.square")
}
InnerView(tabIdx:3, onDismiss: onDismiss, presentBarHandler: presentBarHandler, hideBarHandler: hideBarHandler)
.tabItem {
Label("Tab", systemImage: "4.square")
}
ForEach(1..<5) { idx in
InnerView(tabIdx:idx - 1, onDismiss: onDismiss, presentBarHandler: presentBarHandler, hideBarHandler: hideBarHandler)
.tabItem {
Label("Tab", systemImage: "1.square")
}
}
}
.popupDemo(demoContent: demoContent, isBarPresented: $isBarPresented, includeContextMenu: UserDefaults.settings.bool(forKey: .contextMenuEnabled))
}
Expand Down
61 changes: 44 additions & 17 deletions LNPopupUIExample/LNPopupUIExample/DemoScenes/TabNavView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,27 @@ import SwiftUI
import LoremIpsum
import LNPopupUI

struct ToolbarRolePad18Modifier: ViewModifier {
@Environment(\.horizontalSizeClass) var horizontalSizeClass

func body(content: Content) -> some View {
return content.toolbarRole(UIDevice.current.userInterfaceIdiom == .pad && horizontalSizeClass == .regular ? .editor : .navigationStack)
}
}

extension View {
func toolbarRoleIfPad18() -> some View {
if #available(iOS 18.0, *) {
return self.modifier(ToolbarRolePad18Modifier())
} else {
return self
}
}
}

struct InnerNavView : View {


let tabIdx: Int
let onDismiss: () -> Void

Expand All @@ -19,14 +39,20 @@ struct InnerNavView : View {

var body: some View {
MaterialNavigationStack {
SafeAreaDemoView(colorSeed:"tab_\(tabIdx)", includeLink: true, presentBarHandler: presentBarHandler, hideBarHandler: hideBarHandler, showDismissButton: true, onDismiss: onDismiss)
let bottomButtonsHandlers = SafeAreaDemoView.BottomButtonHandlers(presentBarHandler: presentBarHandler, hideBarHandler: hideBarHandler)
let bottomBarHideSupport = SafeAreaDemoView.BottomBarHideSupport(showsBottomBarHideButton: true, isBottomBarTab: true)

SafeAreaDemoView(colorSeed: "tab_\(tabIdx)", includeLink: true, bottomButtonsHandlers: bottomButtonsHandlers, showDismissButton: true, onDismiss: onDismiss, bottomBarHideSupport: bottomBarHideSupport)
.navigationBarTitle("Tab View + Navigation View")
.navigationBarTitleDisplayMode(.inline)
.toolbarRoleIfPad18()
}
}
}

struct TabNavView : View {
@Environment(\.horizontalSizeClass) var horizontalSizeClass

@State private var isBarPresented: Bool = true

private let onDismiss: () -> Void
Expand All @@ -46,25 +72,26 @@ struct TabNavView : View {
}

var body: some View {
MaterialTabView {
InnerNavView(tabIdx:0, onDismiss: onDismiss, presentBarHandler: presentBarHandler, hideBarHandler: hideBarHandler)
.tabItem {
Label("Tab", systemImage: "1.square")
}
InnerNavView(tabIdx:1, onDismiss: onDismiss, presentBarHandler: presentBarHandler, hideBarHandler: hideBarHandler)
.tabItem {
Label("Tab", systemImage: "2.square").foregroundStyle(.red)
}
InnerNavView(tabIdx:2, onDismiss: onDismiss, presentBarHandler: presentBarHandler, hideBarHandler: hideBarHandler)
.tabItem {
Label("Tab", systemImage: "3.square")
if #available(iOS 18.0, *) {
MaterialTabView {
ForEach(1..<5) { idx in
Tab("Tab\(UIDevice.current.userInterfaceIdiom == .pad && horizontalSizeClass == .regular ? " \(idx)" : "")", systemImage: "\(idx).square") {
InnerNavView(tabIdx:idx - 1, onDismiss: onDismiss, presentBarHandler: presentBarHandler, hideBarHandler: hideBarHandler)
}
}
InnerNavView(tabIdx:3, onDismiss: onDismiss, presentBarHandler: presentBarHandler, hideBarHandler: hideBarHandler)
.tabItem {
Label("Tab", systemImage: "4.square")
}
.popupDemo(demoContent: demoContent, isBarPresented: $isBarPresented, includeContextMenu: UserDefaults.settings.bool(forKey: .contextMenuEnabled))
} else {
MaterialTabView {
ForEach(1..<5) { idx in
InnerNavView(tabIdx:idx - 1, onDismiss: onDismiss, presentBarHandler: presentBarHandler, hideBarHandler: hideBarHandler)
.tabItem {
Label("Tab", systemImage: "\(idx).square").foregroundStyle(.red)
}
}
}
.popupDemo(demoContent: demoContent, isBarPresented: $isBarPresented, includeContextMenu: UserDefaults.settings.bool(forKey: .contextMenuEnabled))
}
.popupDemo(demoContent: demoContent, isBarPresented: $isBarPresented, includeContextMenu: UserDefaults.settings.bool(forKey: .contextMenuEnabled))
}
}

Expand Down
2 changes: 1 addition & 1 deletion LNPopupUIExample/LNPopupUIExample/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<key>CFBundlePackageType</key>
<string>$(PRODUCT_BUNDLE_PACKAGE_TYPE)</string>
<key>CFBundleShortVersionString</key>
<string>1.8.7</string>
<string>1.9.-1</string>
<key>CFBundleVersion</key>
<string>1</string>
<key>LSApplicationCategoryType</key>
Expand Down
14 changes: 14 additions & 0 deletions LNPopupUIExample/LNPopupUIExample/SceneSelection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,19 @@ fileprivate struct LNHeaderFooterView: View {
}
}

extension View {
func pagePresentationIfPossible() -> some View {
if #available(iOS 18.0, *) {
return self
.presentationSizing(
.page
)
} else {
return self
}
}
}

struct SceneSelection: View {
@Environment(\.horizontalSizeClass) var horizontalSizeClass
@Environment(\.verticalSizeClass) var verticalSizeClass
Expand Down Expand Up @@ -100,6 +113,7 @@ struct SceneSelection: View {
NavDemoView(demoContent: DemoContent()) {
viewSheetPresented.toggle()
}
.pagePresentationIfPossible()
})
CellPaddedButton("View") {
viewPresented.toggle()
Expand Down
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ let package = Package(
],
dependencies: [
// .package(path: "../LNPopupController"),
.package(url: "https://github.com/LeoNatan/LNPopupController.git", from: Version(stringLiteral: "2.19.6")),
.package(url: "https://github.com/LeoNatan/LNPopupController.git", from: Version(stringLiteral: "2.20.1")),
// .package(path: "../LNSwiftUIUtils"),
.package(url: "https://github.com/LeoNatan/LNSwiftUIUtils.git", from: Version(stringLiteral: "1.1.0"))
],
Expand Down

0 comments on commit 261151a

Please sign in to comment.