Skip to content

Commit

Permalink
Merge branch 'release/1.9.0(75)'
Browse files Browse the repository at this point in the history
  • Loading branch information
dhekra-rouatbi committed Jun 25, 2024
2 parents 39d3eb4 + 786e866 commit abf8d9e
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 30 deletions.
4 changes: 2 additions & 2 deletions Tella.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -3854,7 +3854,7 @@
CODE_SIGN_ENTITLEMENTS = "Tella/Supporting Files/Tella.entitlements";
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 74;
CURRENT_PROJECT_VERSION = 75;
DEVELOPMENT_ASSET_PATHS = "";
DEVELOPMENT_TEAM = 6ZG9T42688;
ENABLE_PREVIEWS = YES;
Expand All @@ -3881,7 +3881,7 @@
CODE_SIGN_ENTITLEMENTS = "Tella/Supporting Files/Tella.entitlements";
CODE_SIGN_IDENTITY = "iPhone Distribution";
CODE_SIGN_STYLE = Manual;
CURRENT_PROJECT_VERSION = 74;
CURRENT_PROJECT_VERSION = 75;
DEVELOPMENT_ASSET_PATHS = "";
DEVELOPMENT_TEAM = 6ZG9T42688;
"DEVELOPMENT_TEAM[sdk=iphoneos*]" = 6ZG9T42688;
Expand Down
70 changes: 42 additions & 28 deletions Tella/Components/BottomSheet/DragView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
//

import SwiftUI
import Combine

enum DragState {
case inactive
Expand Down Expand Up @@ -31,17 +32,17 @@ struct DragView<Content: View> : View {

var modalHeight:CGFloat
var shouldHideOnTap : Bool = true
var showWithAnimation : Bool = false
var showWithAnimation : Bool = true
var backgroundColor: Color = Styles.Colors.backgroundTab

@Binding var isShown:Bool


@GestureState private var dragState = DragState.inactive
@State private var value: CGFloat = 0
@EnvironmentObject var sheetManager: SheetManager



@GestureState private var dragState = DragState.inactive
@State private var keyboardHeight: CGFloat = 0
@State private var keyboardAnimationDuration: Double = 0.28 // default value
@State private var keyboardCancellable: AnyCancellable?

private func onDragEnded(drag: DragGesture.Value) {
let dragThreshold = modalHeight * (2/3)
if drag.predictedEndTranslation.height > dragThreshold || drag.translation.height > dragThreshold{
Expand Down Expand Up @@ -84,47 +85,60 @@ struct DragView<Content: View> : View {
UIApplication.shared.endEditing()
}
})

//Foreground
VStack{
Spacer()
ZStack{
ZStack {
self.content()
.frame(width: UIScreen.main.bounds.size.width, height:modalHeight)
.background(backgroundColor.opacity(1.0))
.cornerRadius(25, corners: [.topLeft, .topRight])
.edgesIgnoringSafeArea(.all)
}
.offset(y: isShown ? ((self.dragState.isDragging && dragState.translation.height >= 1) ? dragState.translation.height - self.value : -self.value) : modalHeight)
.if (showWithAnimation) {
$0.animation(.interpolatingSpring(stiffness: 300.0, damping: 30.0, initialVelocity: 10.0))
}
.offset(y: isShown ? ((self.dragState.isDragging && dragState.translation.height >= 1) ? dragState.translation.height - self.keyboardHeight : -self.keyboardHeight) : modalHeight)

.animation(.easeOut(duration: keyboardAnimationDuration))

.if (shouldHideOnTap) {
$0.gesture(drag)
}
}
}}.edgesIgnoringSafeArea(.all)
.if (showWithAnimation) {
$0.animation(.spring())
}

.onAppear{
NotificationCenter.default.addObserver(forName: UIResponder.keyboardWillShowNotification, object: nil, queue: .main) {(noti) in
if isShown {
let keyboardFrame = noti.userInfo?[UIResponder.keyboardFrameEndUserInfoKey] as? CGRect
self.value = keyboardFrame?.height ?? 0
}
.onAppear {
subscribeToKeyboardEvents()
}
.onDisappear {
self.unsubscribeFromKeyboardEvents()
}
}

private func subscribeToKeyboardEvents() {

let keyboardWillShowPublisher = NotificationCenter.default.publisher(for: UIResponder.keyboardWillShowNotification)
let keyboardWillHidePublisher = NotificationCenter.default.publisher(for: UIResponder.keyboardWillHideNotification)

keyboardCancellable = Publishers.Merge(keyboardWillShowPublisher, keyboardWillHidePublisher)
.sink { notification in
if notification.name == UIResponder.keyboardWillShowNotification {
if let keyboardFrame = notification.userInfo?[UIResponder.keyboardFrameEndUserInfoKey] as? CGRect {
if keyboardFrame.height > 0 {
self.keyboardHeight = keyboardFrame.height
}
}
NotificationCenter.default.addObserver(forName: UIResponder.keyboardWillHideNotification, object: nil, queue: .main) {(noti) in
self.value = 0
}
} else {
self.keyboardHeight = 0
}

}
}
}

private func unsubscribeFromKeyboardEvents() {
keyboardCancellable?.cancel()
}
}

func fraction_progress(lowerLimit: Double = 0, upperLimit:Double, current:Double, inverted:Bool = false) -> Double{
func fraction_progress(lowerLimit: Double = 0, upperLimit:Double, current:Double, inverted:Bool = false) -> Double {
var val:Double = 0
if current >= upperLimit {
val = 1
Expand Down

0 comments on commit abf8d9e

Please sign in to comment.