-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
543 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 1,56 @@ | ||
// | ||
// Extensions.swift | ||
// Laffey | ||
// | ||
// Created by 戴元平 on 8/15/20. | ||
// Copyright © 2020 Wei Dai. All rights reserved. | ||
// | ||
|
||
import SwiftUI | ||
|
||
public extension Color { | ||
static let salmon = Color(rgb: 0xFF7E79) | ||
|
||
init(red: Int, green: Int, blue: Int) { | ||
assert(red >= 0 && red <= 255, "Invalid red component") | ||
assert(green >= 0 && green <= 255, "Invalid green component") | ||
assert(blue >= 0 && blue <= 255, "Invalid blue component") | ||
|
||
self.init(red: Double(red) / 255.0, green: Double(green) / 255.0, blue: Double(blue) / 255.0) | ||
} | ||
|
||
init(rgb: Int) { | ||
self.init( | ||
red: (rgb >> 16) & 0xFF, | ||
green: (rgb >> 8) & 0xFF, | ||
blue: rgb & 0xFF | ||
) | ||
} | ||
} | ||
|
||
struct KeyboardResponsiveModifier: ViewModifier { | ||
@State private var offset: CGFloat = 0 | ||
|
||
func body(content: Content) -> some View { | ||
content | ||
.padding(.bottom, offset) | ||
.onAppear { | ||
NotificationCenter.default.addObserver(forName: UIResponder.keyboardWillShowNotification, object: nil, queue: .main) { notif in | ||
let value = notif.userInfo![UIResponder.keyboardFrameEndUserInfoKey] as! CGRect | ||
let height = value.height | ||
let bottomInset = UIApplication.shared.windows.first?.safeAreaInsets.bottom | ||
self.offset = height - (bottomInset ?? 0) | ||
} | ||
|
||
NotificationCenter.default.addObserver(forName: UIResponder.keyboardWillHideNotification, object: nil, queue: .main) { notif in | ||
self.offset = 0 | ||
} | ||
} | ||
} | ||
} | ||
|
||
extension View { | ||
func keyboardResponsive() -> ModifiedContent<Self, KeyboardResponsiveModifier> { | ||
return modifier(KeyboardResponsiveModifier()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.