Skip to content

Commit

Permalink
Add landscape mode support (#102)
Browse files Browse the repository at this point in the history
* Add landscape mode support

* remove commented lines

* Update CourseUnitView.swift

Add one dot to progress

* update design

* resolve merge conflicts

* update progress dots

* bug fixes

When a user swipes back from the problem screen, the app numbs and the user cannot tap. Fixed.
The component name is in the center of the screen. Fixed.

* code style improvements

---------

Co-authored-by: stepanokdev <[email protected]>
  • Loading branch information
IvanStepanok and Stepanokdev authored Oct 16, 2023
1 parent 60aa494 commit c42342e
Show file tree
Hide file tree
Showing 26 changed files with 632 additions and 445 deletions.
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
6 changes: 5 additions & 1 deletion Core/Core/Extensions/UIApplicationExtension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ extension UINavigationController: UIGestureRecognizerDelegate {
}

public func gestureRecognizerShouldBegin(_ gestureRecognizer: UIGestureRecognizer) -> Bool {
return viewControllers.count > 1
if #available(iOS 17, *) {
return false
} else {
return viewControllers.count > 1
}
}
}
87 changes: 83 additions & 4 deletions Core/Core/Extensions/ViewExtension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,59 @@ 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 +166,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 +267,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

0 comments on commit c42342e

Please sign in to comment.