Created
May 26, 2023 05:20
-
-
Save badrinathvm/b4786feaaa71c37b91ea88ab06bbc3d9 to your computer and use it in GitHub Desktop.
Disclosure Group
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
// | |
// DropDown.swift | |
// Custom Action Sheet | |
// | |
// Created by Rani Badri on 5/25/23. | |
// Copyright © 2023 Balaji. All rights reserved. | |
// | |
import Foundation | |
import SwiftUI | |
struct DropDownView: View { | |
@State private var isExpanded = false | |
@State private var selectedItem = "v1/message" | |
var options = ["v1/message", "v2/message"] | |
@GestureState private var isDetectingTripleTap = false | |
@State private var tripleTapCount = 0 | |
var body: some View { | |
VStack { | |
Text("Tap count: \(tripleTapCount)") | |
.gesture( | |
TapGesture(count: 1) | |
.onEnded { | |
tripleTapCount += 1 | |
} | |
.updating($isDetectingTripleTap) { currentState, gestureState, transaction in | |
gestureState = true | |
} | |
) | |
if tripleTapCount >= 2 { | |
if #available(iOS 14.0, *) { | |
DisclosureGroup(selectedItem, isExpanded: $isExpanded) { | |
ScrollView(Axis.Set.horizontal, showsIndicators: false) { | |
ForEach(options, id:\.self) { option in | |
VStack { | |
Button { | |
self.selectedItem = option | |
self.isExpanded.toggle() | |
} label: { | |
Text(option) | |
.foregroundColor(Color.white) | |
.frame(maxWidth: .infinity, alignment: .leading) | |
.padding(.top) | |
} | |
} | |
} | |
} | |
} | |
.accentColor(Color.white) | |
.padding() | |
.background(Color.black) | |
.cornerRadius(8) | |
.padding() | |
} else { | |
// Fallback on earlier versions | |
} | |
} | |
Spacer() | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment