Created
May 8, 2021 23:01
-
-
Save froggomad/256bf9f398c103b17a70acad724750fa to your computer and use it in GitHub Desktop.
pull to change number of lines in text object
This file contains hidden or 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
VStack { | |
HStack { | |
Text(log.name) | |
.lineLimit(lineLimit) // lineLimit is @State var | |
.foregroundColor(.black) | |
.multilineTextAlignment(.leading) | |
Spacer() | |
} | |
.padding(3) | |
PullView() | |
.scaleEffect(scale) // scale is @State var: CGSize | |
.animation(.spring(response: 0.4, | |
dampingFraction: 0.6)) | |
.gesture( | |
DragGesture(minimumDistance: 1.0, coordinateSpace: .local) | |
.onChanged({ value in | |
let verticalAmount = Int(value.translation.height) | |
// TODO: track line height instead of arbitrary | |
// value | |
let pullSensitivity: Int = 10 | |
// dragging down, increase height | |
if verticalAmount > pullSensitivity { | |
scale = .init(width: 1, | |
height: 1.33) | |
// dragging up, decrease height | |
} else if verticalAmount < -pullSensitivity { | |
scale = .init(width: 1, | |
height: 0.66) | |
} | |
// change number of lines in Text Object | |
lineLimit += verticalAmount / pullSensitivity | |
}) | |
.onEnded({ value in | |
// return view to normal | |
scale = .init(width: 1, | |
height: 1) | |
}) | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment