Skip to content

Commit

Permalink
arrow animation & fix for section title (#209)
Browse files Browse the repository at this point in the history
* fix: contains next fixes:

* on tap on current element in dropdown view hide the dropdown view without refreshing of content
* added rotation animation for expandable cell arrow and for dropdown title arrow
* set line limit for courseDropdownTitle to 1 line and added paddings

* fix: hide dropdown when user is scrolling
  • Loading branch information
forgotvas authored Dec 18, 2023
1 parent e58a7cd commit f81aefa
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,9 @@ struct CourseExpandableContentView: View {
.lineLimit(1)
.foregroundColor(Theme.Colors.textPrimary)
Spacer()
if isExpanded {
Image(systemName: "chevron.right")
.foregroundColor(Theme.Colors.accentColor)
.rotationEffect(.degrees(90))
} else {
Image(systemName: "chevron.right")
.foregroundColor(Theme.Colors.accentColor)
}
Image(systemName: "chevron.right")
.foregroundColor(Theme.Colors.accentColor)
.dropdownArrowRotationAnimation(value: isExpanded)
}
.padding(.horizontal, 30)
.padding(.vertical, 15)
Expand Down
31 changes: 18 additions & 13 deletions Course/Course/Presentation/Unit/CourseUnitView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -296,21 +296,26 @@ public struct CourseUnitView: View {
}
}
VStack {
NavigationBar(
title: isDropdownActive ? sequenceTitle : "",
leftButtonAction: {
viewModel.router.back()
playerStateSubject.send(VideoPlayerState.kill)
}).padding(.top, isHorizontal ? 10 : 0)
Group {
NavigationBar(
title: isDropdownActive ? sequenceTitle : "",
leftButtonAction: {
viewModel.router.back()
playerStateSubject.send(VideoPlayerState.kill)
})
.padding(.top, isHorizontal ? 10 : 0)
.padding(.leading, isHorizontal ? -16 : 0)
if isDropdownActive {
CourseUnitDropDownTitle(
title: unitTitle,
isAvailable: isDropdownAvailable,
showDropdown: $showDropdown)
.padding(.top, 0)
.offset(y: -25)
if isDropdownActive {
CourseUnitDropDownTitle(
title: unitTitle,
isAvailable: isDropdownAvailable,
showDropdown: $showDropdown)
.padding(.top, 0)
.padding(.horizontal, 48)
.offset(y: -25)
}
}
.padding(.trailing, isHorizontal ? 215 : 0)
Spacer()
}
HStack(alignment: .center) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,17 @@ struct CourseUnitDropDownTitle: View {
HStack {
Text(title)
.opacity(showDropdown ? 0.7 : 1.0)
.lineLimit(1)
if isAvailable {
if showDropdown {
Image(systemName: "chevron.right")
.rotationEffect(.degrees(90))
} else {
Image(systemName: "chevron.right")
}
Image(systemName: "chevron.right")
.dropdownArrowRotationAnimation(value: showDropdown)
}
}
}
.buttonStyle(.plain)
} else {
Text(title)
.lineLimit(1)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ struct CourseUnitVerticalsDropdownView: View {
.onTapGesture {
showDropdown.toggle()
}
.simultaneousGesture(
DragGesture()
.onChanged { _ in
if showDropdown { showDropdown.toggle() }
}
)
CourseUnitDropDownList(content: {
ForEach(verticals, id: \.id) { vertical in
let isLast = verticals.last?.id == vertical.id
Expand All @@ -31,6 +37,10 @@ struct CourseUnitVerticalsDropdownView: View {
isLast: isLast,
isSelected: isSelected
) {
if isSelected {
showDropdown.toggle()
return
}
action(vertical)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,21 @@ struct DropdownAnimationModifier<V>: ViewModifier where V: Equatable {
}
}

struct DropdownArrowRotationModifier: ViewModifier {
var value: Bool
func body(content: Content) -> some View {
content
.rotationEffect(value ? .degrees(90) : .degrees(0))
.animation(.easeOut(duration: 0.2), value: value)
}
}

extension View {
func dropdownAnimation<V>(isActive: Bool, value: V) -> some View where V: Equatable {
modifier(DropdownAnimationModifier(isActive: isActive, value: value))
}

func dropdownArrowRotationAnimation(value: Bool) -> some View {
modifier(DropdownArrowRotationModifier(value: value))
}
}

0 comments on commit f81aefa

Please sign in to comment.