Skip to content

Commit

Permalink
Hide code by default and add animation when state change
Browse files Browse the repository at this point in the history
  • Loading branch information
ludovic35 committed Nov 27, 2024
1 parent a317daa commit 4b20e7c
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions Showcase/Showcase/Pages/Utils/ShowcaseTokenCode.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,14 @@ import SwiftUI

struct ShowcaseTokenCode: View {

// MARK: Environment properties

@Environment(\.theme) private var theme
@Environment(\.colorScheme) private var colorScheme

@State private var isCodeVisible = true
// MARK: Stored properties

@State private var isCodeVisible = false
var code: String

// MARK: Body
Expand All @@ -44,9 +48,10 @@ struct ShowcaseTokenCode: View {
.typeBodyStrongLarge(theme)
.foregroundStyle(theme.colorContentDefault.color(for: colorScheme))
.padding(.vertical, theme.spacePaddingInlineShort)
Image(isCodeVisible ? "ic_chevron-up" : "ic_chevron-down")
Image("ic_chevron-up")
.resizable()
.renderingMode(.template)
.rotationEffect(Angle.degrees(isCodeVisible ? 0 : 180))
.foregroundColor(theme.colorBgBrandPrimary.color(for: colorScheme))
.frame(width: 20, height: 20)
.padding(.trailing, theme.spacePaddingInlineMedium)
Expand Down Expand Up @@ -102,6 +107,8 @@ struct ShowcaseTokenCode: View {
}

private func toggle() {
isCodeVisible.toggle()
withAnimation {
isCodeVisible.toggle()
}
}
}

0 comments on commit 4b20e7c

Please sign in to comment.