-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Simple UI Portfolio design feedback (#331)
* Add feature flag and mode selector for simple UI * WIP * Search * Onboarding and pnls * Move the swiftui chart logic to dydxLineChartViewModel for reuse * Chart * Add delay to reduce loading state updates * Default to show 90D PNL chart * Nav * Header * Chart Control * Market details * Position info * TradeSheet and buy/sell tips * WIP * Size input * Validation error * Keyboard * keyboard optimization * CTA button * background color * Clean up * Menu * History bottom tabbar area * Mode switcher * Keyboard/UI optimizations * Design review feedbacks * light logo * Clean up * Switch default theme to Dark * Add gradient to the market list bottom
- Loading branch information
Showing
32 changed files
with
338 additions
and
118 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
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
63 changes: 63 additions & 0 deletions
63
PlatformUI/PlatformUI/KeyboardObserving/KeyboardObserving.swift
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,63 @@ | ||
// | ||
// KeyboardObserving.swift | ||
// PlatformUI | ||
// | ||
// Created by Rui Huang on 06/01/2025. | ||
// | ||
|
||
import Foundation | ||
import SwiftUI | ||
import UIKit | ||
|
||
public enum KeyboardObservingMode { | ||
case yPadding, yOffset | ||
} | ||
|
||
extension View { | ||
public func keyboardObserving(offset: CGFloat = 0.0, mode: KeyboardObservingMode = .yPadding) -> some View { | ||
self.modifier(KeyboardObserving(offset: offset, mode: mode)) | ||
} | ||
} | ||
|
||
struct KeyboardObserving: ViewModifier { | ||
|
||
let offset: CGFloat | ||
let mode: KeyboardObservingMode | ||
|
||
@State var keyboardHeight: CGFloat = 0 | ||
@State var keyboardAnimationDuration: Double = 0 | ||
|
||
func body(content: Content) -> some View { | ||
content | ||
.if(mode == .yPadding, transform: { content in | ||
content.padding([.bottom], keyboardHeight) | ||
}) | ||
.if(mode == .yOffset, transform: { content in | ||
content.offset(y: -keyboardHeight) | ||
}) | ||
.edgesIgnoringSafeArea((keyboardHeight > 0) ? [.bottom] : []) | ||
.animation(.easeOut(duration: keyboardAnimationDuration), value: keyboardHeight) | ||
.onReceive( | ||
NotificationCenter.default.publisher(for: UIResponder.keyboardWillChangeFrameNotification) | ||
.receive(on: RunLoop.main), | ||
perform: updateKeyboardHeight | ||
) | ||
} | ||
|
||
func updateKeyboardHeight(_ notification: Notification) { | ||
guard let info = notification.userInfo else { return } | ||
// Get the duration of the keyboard animation | ||
keyboardAnimationDuration = (info[UIResponder.keyboardAnimationDurationUserInfoKey] as? Double) | ||
?? 0.25 | ||
|
||
guard let keyboardFrame = info[UIResponder.keyboardFrameEndUserInfoKey] as? CGRect | ||
else { return } | ||
// If the top of the frame is at the bottom of the screen, set the height to 0. | ||
if keyboardFrame.origin.y == UIScreen.main.bounds.height { | ||
keyboardHeight = 0 | ||
} else { | ||
// IMPORTANT: This height will _include_ the SafeAreaInset height. | ||
keyboardHeight = keyboardFrame.height + offset | ||
} | ||
} | ||
} |
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
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
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
Oops, something went wrong.