Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add landscape mode support #102

Merged
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ public struct SignInView: View {
@State private var email: String = ""
@State private var password: String = ""

@Environment (\.isHorizontal) private var isHorizontal

@ObservedObject
private var viewModel: SignInViewModel

Expand All @@ -32,7 +34,8 @@ public struct SignInView: View {
CoreAssets.appLogo.swiftUIImage
.resizable()
.frame(maxWidth: 189, maxHeight: 54)
.padding(.vertical, 40)
.padding(.top, isHorizontal ? 20 : 40)
.padding(.bottom, isHorizontal ? 10 : 40)

ScrollView {
VStack {
Expand Down Expand Up @@ -152,6 +155,7 @@ public struct SignInView: View {
.hideNavigationBar()
.navigationBarBackButtonHidden(true)
.navigationBarHidden(true)
.ignoresSafeArea(.all, edges: .horizontal)
.background(Theme.Colors.background.ignoresSafeArea(.all))
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ public struct SignUpView: View {
@State
private var disclosureGroupOpen: Bool = false

@Environment (\.isHorizontal) private var isHorizontal

@ObservedObject
private var viewModel: SignUpViewModel

Expand Down Expand Up @@ -44,6 +46,7 @@ public struct SignUpView: View {
.backButtonStyle(color: .white)
})
.foregroundColor(Theme.Colors.styledButtonText)
.padding(.leading, isHorizontal ? 48 : 0)

}.frame(minWidth: 0,
maxWidth: .infinity,
Expand Down Expand Up @@ -135,6 +138,7 @@ public struct SignUpView: View {
}
}
}
.ignoresSafeArea(.all, edges: .horizontal)
.background(Theme.Colors.background.ignoresSafeArea(.all))
.hideNavigationBar()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ public struct ResetPasswordView: View {

@State private var isRecovered: Bool = false

@Environment (\.isHorizontal) private var isHorizontal

@ObservedObject
private var viewModel: ResetPasswordViewModel

Expand All @@ -35,7 +37,7 @@ public struct ResetPasswordView: View {
leftButtonColor: .white,
leftButtonAction: {
viewModel.router.back()
})
}) .padding(.leading, isHorizontal ? 48 : 0)

ScrollView {
VStack {
Expand Down Expand Up @@ -149,7 +151,10 @@ public struct ResetPasswordView: View {
}
}
}
.ignoresSafeArea(.all, edges: .horizontal)

.background(Theme.Colors.background.ignoresSafeArea(.all))

.hideNavigationBar()
}
}
Expand Down
82 changes: 78 additions & 4 deletions Core/Core/Extensions/ViewExtension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,54 @@ public extension View {
.padding(.horizontal, 48)
}

@ViewBuilder
func frameLimit(sizePortrait: CGFloat = 560, sizeLandscape: CGFloat = 648) -> some View {
return HStack {
Spacer(minLength: 0)
self.frame(maxWidth: UIDevice.current.orientation == .portrait ? sizePortrait : sizeLandscape)
Spacer(minLength: 0)
if UIDevice.current.userInterfaceIdiom == .pad {
HStack {
Spacer(minLength: 0)
self.frame(maxWidth: UIDevice.current.orientation.isPortrait ? sizePortrait : sizeLandscape)
Spacer(minLength: 0)
}
} else { self }
}

@ViewBuilder
func adaptiveHStack<Content: View>(spacing: CGFloat = 0, currentOrientation: UIInterfaceOrientation,
@ViewBuilder content: () -> Content) -> some View {
if currentOrientation.isLandscape && UIDevice.current.userInterfaceIdiom != .pad {
VStack(alignment: .center, spacing: spacing, content: content)
} else if currentOrientation.isPortrait && UIDevice.current.userInterfaceIdiom != .pad {
HStack(spacing: spacing, content: content)
} else if UIDevice.current.userInterfaceIdiom != .phone {
HStack(spacing: spacing, content: content)
}
}

@ViewBuilder
func adaptiveStack<Content: View>(spacing: CGFloat = 0,
isHorizontal: Bool,
@ViewBuilder content: () -> Content) -> some View {
if isHorizontal, UIDevice.current.userInterfaceIdiom != .pad {
HStack(spacing: spacing, content: content)
} else {
VStack(alignment: .center, spacing: spacing, content: content)
}
}

@ViewBuilder
func adaptiveNavigationStack<Content: View>(
spacing: CGFloat = 0,
isHorizontal: Bool,
@ViewBuilder content: () -> Content
) -> some View {
if UIDevice.current.userInterfaceIdiom == .pad {
HStack(spacing: spacing, content: content)
} else {
if isHorizontal {
HStack(alignment: .top, spacing: spacing, content: content)
} else {
VStack(alignment: .center, spacing: spacing, content: content)
}
}
}

Expand All @@ -118,6 +161,26 @@ public extension View {
}
}

func roundedBackgroundWeb(
_ color: Color = Theme.Colors.background,
strokeColor: Color = Theme.Colors.backgroundStroke,
ipadMaxHeight: CGFloat = .infinity,
maxIpadWidth: CGFloat = 420
) -> some View {
var idiom: UIUserInterfaceIdiom { UIDevice.current.userInterfaceIdiom }
return VStack {
VStack {}.frame(height: 1)
ZStack {
self
.frame(maxWidth: maxIpadWidth, maxHeight: idiom == .pad ? ipadMaxHeight : .infinity)
RoundedCorners(tl: 24, tr: 24)
.stroke(style: StrokeStyle(lineWidth: 1))
.foregroundColor(strokeColor)
.offset(y: -1)
}
}
}

func hideNavigationBar() -> some View {
if #available(iOS 16.0, *) {
return self.navigationBarHidden(true)
Expand Down Expand Up @@ -199,3 +262,14 @@ public extension Image {
.foregroundColor(color)
}
}

public extension EnvironmentValues {
var isHorizontal: Bool {
if UIDevice.current.userInterfaceIdiom != .pad {
if let windowScene = UIApplication.shared.connectedScenes.first as? UIWindowScene {
return windowScene.windows.first?.windowScene?.interfaceOrientation.isLandscape ?? true
}
}
return false
}
}
Loading