Skip to content

Commit

Permalink
Added fallback for older iOS versions.
Browse files Browse the repository at this point in the history
  • Loading branch information
aumChauhan committed Jan 20, 2024
1 parent 8f577a0 commit fee2ca9
Show file tree
Hide file tree
Showing 29 changed files with 193 additions and 152 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ MaterialUIKit is a SwiftUI package offering a set of user interface components i

## Requirements

- Xcode 14.0 and above
- iOS 17.0 and above
- iOS 15.0 and above

## Preview

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import SwiftUI

// MARK: - Extension View

@available(iOS 17.0, *)
@available(iOS 15.0, *)
extension View {

/// Presents a MaterialUI style alert over the current view.
Expand Down Expand Up @@ -48,7 +48,7 @@ extension View {
// MARK: - MUIAlertModifier

/// A view modifier that adds the MaterialUI style alert presentation behavior to any view.
@available(iOS 17.0, *)
@available(iOS 15.0, *)
private struct MUIAlertModifier: ViewModifier {

// MARK: - Properties
Expand Down Expand Up @@ -81,7 +81,7 @@ private struct MUIAlertModifier: ViewModifier {
// MARK: - MUIAlertView

/// A custom Material UI style alert view that can be presented over other views.
@available(iOS 17.0, *)
@available(iOS 15.0, *)
private struct MUIAlertView: View {

// MARK: - Properties
Expand Down Expand Up @@ -109,15 +109,15 @@ private struct MUIAlertView: View {
// Alert tittle
Text(title)
.font(.title2)
.fontWeight(.semibold)
.fontWeightWithFallback(.semibold)
.foregroundColor(MaterialUI.tint.primaryTitle())
.lineLimit(1)

// Alert message
if let message {
Text(message)
.font(.subheadline)
.fontWeight(.medium)
.fontWeightWithFallback(.medium)
.foregroundColor(MaterialUI.tint.secondaryTitle())
.multilineTextAlignment(.leading)
}
Expand Down Expand Up @@ -164,7 +164,7 @@ private struct MUIAlertView: View {
// In-Out animation
.scaleEffect(animationFlag ? 1 : 0)
.opacity(animationFlag ? 1 : 0)
.onChange(of: isPresented) { oldValue, newValue in
.onChangeWithFallback(of: isPresented) { oldValue, newValue in
withAnimation(.bouncy) {
animationFlag = isPresented
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import SwiftUI

// MARK: - Extension View

@available(iOS 17.0, *)
@available(iOS 15.0, *)
extension View {

/// A custom MaterialUI style snackbar that can be displayed at the bottom of the screen.
Expand Down Expand Up @@ -42,7 +42,7 @@ extension View {
// MARK: - MUISnackbarModifier

/// A view modifier that adds the MaterialUI style snackbar presentation behavior to any view.
@available(iOS 17.0, *)
@available(iOS 15.0, *)
private struct MUISnackbarModifier: ViewModifier {

// MARK: - Properties
Expand Down Expand Up @@ -71,7 +71,7 @@ private struct MUISnackbarModifier: ViewModifier {
// MARK: - MUISnackbarView

/// A custom MaterialUI style snackbar that can be displayed at the bottom of the screen.
@available(iOS 17.0, *)
@available(iOS 15.0, *)
private struct MUISnackbarView: View {

// MARK: - Properties
Expand Down Expand Up @@ -100,7 +100,8 @@ private struct MUISnackbarView: View {
// Snackbar message
Text(message)
.foregroundColor(MaterialUI.tint.primaryTitle())
.font(.system(.headline, weight: .medium))
.font(.headline)
.fontWeightWithFallback(.medium)

Spacer()

Expand All @@ -111,7 +112,8 @@ private struct MUISnackbarView: View {
} label: {
Text(primaryButtonTitle)
.textButtonStyle(0)
.font(.system(.headline, weight: .semibold))
.font(.headline)
.fontWeightWithFallback(.semibold)
}
}
}
Expand All @@ -127,7 +129,7 @@ private struct MUISnackbarView: View {
// In-animation
.offset(y: animationFlag ? 0 : UIScreen.main.bounds.height)
// To toggle of snackbar
.onChange(of: isPresented) { oldValue, newValue in
.onChangeWithFallback(of: isPresented) { oldValue, newValue in
withAnimation(.bouncy) {
animationFlag = isPresented
toggleOffSnackbar(isPresented: $isPresented, duration: duration)
Expand All @@ -138,7 +140,7 @@ private struct MUISnackbarView: View {

// MARK: - Extension MUISnackbarView

@available(iOS 17.0, *)
@available(iOS 15.0, *)
extension MUISnackbarView {

/// A function to toggle off the snackbar in specific time interval.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import SwiftUI

// MARK: - View Extension

@available(iOS 17.0, *)
@available(iOS 15.0, *)
extension View {

/// Presents a Material Design date picker.
Expand All @@ -27,7 +27,7 @@ extension View {
// MARK: - MUIDatePickerModifier

/// A view modifier that adds the MaterialUI style date picker presentation behavior to any view.
@available(iOS 17.0, *)
@available(iOS 15.0, *)
private struct MUIDatePickerModifier: ViewModifier {

// MARK: - Properties
Expand All @@ -47,7 +47,7 @@ private struct MUIDatePickerModifier: ViewModifier {
// MARK: - MUIDatePickerView

/// A custom Material UI style date picker view that can be presented over other views.
@available(iOS 17.0, *)
@available(iOS 15.0, *)
private struct MUIDatePickerView: View {

// MARK: - Properties
Expand Down Expand Up @@ -88,7 +88,7 @@ private struct MUIDatePickerView: View {
// In Animation
.scaleEffect(animationFlag ? 1 : 0)
.opacity(animationFlag ? 1 : 0)
.onChange(of: isPresented) { oldValue, newValue in
.onChangeWithFallback(of: isPresented) { oldValue, newValue in
withAnimation(.bouncy) {
animationFlag = isPresented
}
Expand All @@ -98,7 +98,7 @@ private struct MUIDatePickerView: View {

// MARK: - Extension MUIDatePickerView

@available(iOS 17.0, *)
@available(iOS 15.0, *)
extension MUIDatePickerView {

/// Returns the dismiss button bar for the date picker.
Expand All @@ -123,7 +123,7 @@ extension MUIDatePickerView {
// Selected date
Text("\(selection.formattedMUIDate())")
.font(.title)
.fontWeight(.medium)
.fontWeightWithFallback(.medium)
.foregroundColor(MaterialUI.tint.primaryTitle())
.padding(.top, 5)
.padding(.leading, 10)
Expand All @@ -147,7 +147,7 @@ extension MUIDatePickerView {
// Selected date
Text("\(selection.formattedMUIDate())")
.font(.title)
.fontWeight(.medium)
.fontWeightWithFallback(.medium)
.foregroundColor(MaterialUI.tint.primaryTitle())
.padding(.top, 5)
.padding(.leading, 10)
Expand All @@ -172,7 +172,7 @@ extension MUIDatePickerView {
// MARK: - Extension Date

/// An extension on `Date` to format dates in a specific format.
@available(iOS 17.0, *)
@available(iOS 15.0, *)
extension Date {

/// Formats the date in the "E, MMM D" style.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import SwiftUI
// MARK: - MUISecureField

/// A SwiftUI view representing a MaterialUI style secure field.
@available(iOS 17.0, *)
@available(iOS 15.0, *)
public struct MUISecureField: View {

// MARK: - Properties
Expand Down Expand Up @@ -123,7 +123,7 @@ public struct MUISecureField: View {
isFocused.toggle()
}
// To change `@FocusState` value with animation
.onChange(of: isFocused) { oldValue, newValue in
.onChangeWithFallback(of: isFocused) { oldValue, newValue in
withAnimation(.bouncy) {
secureFieldIsFocused = newValue
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import SwiftUI
// MARK: - MUITextField

/// A SwiftUI view representing a MaterialUI style text field.
@available(iOS 17.0, *)
@available(iOS 15.0, *)
public struct MUITextField: View {

// MARK: - Properties
Expand Down Expand Up @@ -122,7 +122,7 @@ public struct MUITextField: View {
isFocused.toggle()
}
// To change `@FocusState` value with animation
.onChange(of: isFocused) { oldValue, newValue in
.onChangeWithFallback(of: isFocused) { oldValue, newValue in
withAnimation(.bouncy) {
textFieldIsFocused = newValue
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import SwiftUI

// MARK: - Extension View

@available(iOS 17.0, *)
@available(iOS 15.0, *)
extension View {

/// Presents a Material Design time picker.
Expand All @@ -26,7 +26,7 @@ extension View {
// MARK: - MUITimePickerModifier

/// A view modifier that adds the MaterialUI style time picker presentation behavior to any view.
@available(iOS 17.0, *)
@available(iOS 15.0, *)
private struct MUITimePickerModifier: ViewModifier {

// MARK: - Properties
Expand All @@ -46,7 +46,7 @@ private struct MUITimePickerModifier: ViewModifier {
// MARK: - MUITimePickerView

/// A custom Material UI style time picker view that can be presented over other views.
@available(iOS 17.0, *)
@available(iOS 15.0, *)
private struct MUITimePickerView: View {

// MARK: - Properties
Expand Down Expand Up @@ -88,7 +88,7 @@ private struct MUITimePickerView: View {
// In Animation
.scaleEffect(animationFlag ? 1 : 0)
.opacity(animationFlag ? 1 : 0)
.onChange(of: isPresented) { oldValue, newValue in
.onChangeWithFallback(of: isPresented) { oldValue, newValue in
withAnimation(.bouncy) {
animationFlag = isPresented
}
Expand All @@ -98,7 +98,7 @@ private struct MUITimePickerView: View {

// MARK: - Extension MUITimePickerView

@available(iOS 17.0, *)
@available(iOS 15.0, *)
extension MUITimePickerView {

/// Returns the dismiss button bar for the time picker.
Expand All @@ -123,7 +123,7 @@ extension MUITimePickerView {
// Time
Text("\(selection.formatted(date: .omitted, time: .shortened))")
.font(.title)
.fontWeight(.medium)
.fontWeightWithFallback(.medium)
.foregroundColor(MaterialUI.tint.primaryTitle())
.padding(.top, 5)
.padding(.leading, 10)
Expand All @@ -147,7 +147,7 @@ extension MUITimePickerView {
// Time
Text("\(selection.formatted(date: .omitted, time: .shortened))")
.font(.title)
.fontWeight(.medium)
.fontWeightWithFallback(.medium)
.foregroundColor(MaterialUI.tint.primaryTitle())
.padding(.top, 5)
.padding(.leading, 10)
Expand Down
Loading

0 comments on commit fee2ca9

Please sign in to comment.