Fix enabling feature flags on iOS 15
This commit is contained in:
parent
ff433c4270
commit
54fadaa270
|
@ -18,7 +18,6 @@ struct AdvancedPrefsView : View {
|
|||
@State private var mastodonCacheSize: Int64 = 0
|
||||
@State private var cloudKitStatus: CKAccountStatus?
|
||||
@State private var isShowingFeatureFlagAlert = false
|
||||
@State private var featureFlagName = ""
|
||||
|
||||
var body: some View {
|
||||
List {
|
||||
|
@ -32,23 +31,9 @@ struct AdvancedPrefsView : View {
|
|||
.listStyle(.insetGrouped)
|
||||
.appGroupedListBackground(container: PreferencesNavigationController.self)
|
||||
.onTapGesture(count: 3) {
|
||||
featureFlagName = ""
|
||||
isShowingFeatureFlagAlert = true
|
||||
}
|
||||
.alert("Enable Feature Flag", isPresented: $isShowingFeatureFlagAlert) {
|
||||
TextField("Flag Name", text: $featureFlagName)
|
||||
.textInputAutocapitalization(.never)
|
||||
.autocorrectionDisabled()
|
||||
|
||||
Button("Cancel", role: .cancel) {}
|
||||
Button("Enable") {
|
||||
if let flag = FeatureFlag(rawValue: featureFlagName) {
|
||||
preferences.enabledFeatureFlags.insert(flag)
|
||||
}
|
||||
}
|
||||
} message: {
|
||||
Text("Warning: Feature flags are intended for development and debugging use only. They are experimental and subject to change at any time.")
|
||||
}
|
||||
.modifier(FeatureFlagAlertModifier(showing: $isShowingFeatureFlagAlert))
|
||||
.navigationBarTitle(Text("Advanced"))
|
||||
}
|
||||
|
||||
|
@ -251,6 +236,74 @@ extension StatusContentType {
|
|||
}
|
||||
}
|
||||
|
||||
private struct FeatureFlagAlertModifier: ViewModifier {
|
||||
@Binding var showing: Bool
|
||||
@ObservedObject private var preferences = Preferences.shared
|
||||
@State private var featureFlagName = ""
|
||||
|
||||
func body(content: Content) -> some View {
|
||||
if #available(iOS 16.0, *) {
|
||||
content
|
||||
.onChange(of: showing) {
|
||||
if $0 {
|
||||
featureFlagName = ""
|
||||
}
|
||||
}
|
||||
.alert("Enable Feature Flag", isPresented: $showing) {
|
||||
textField
|
||||
Button("Cancel", role: .cancel) {}
|
||||
Button("Enable", action: enableFlag)
|
||||
} message: {
|
||||
warning
|
||||
}
|
||||
} else {
|
||||
content
|
||||
.sheet(isPresented: $showing) {
|
||||
NavigationView {
|
||||
List {
|
||||
Section {
|
||||
textField
|
||||
} footer: {
|
||||
warning
|
||||
}
|
||||
}
|
||||
.navigationTitle("Enable Feature Flag")
|
||||
.navigationBarTitleDisplayMode(.inline)
|
||||
.listStyle(.insetGrouped)
|
||||
.toolbar {
|
||||
ToolbarItem(placement: .cancellationAction) {
|
||||
Button("Cancel") {
|
||||
showing = false
|
||||
}
|
||||
}
|
||||
ToolbarItem(placement: .confirmationAction) {
|
||||
Button("Enable", action: self.enableFlag)
|
||||
}
|
||||
}
|
||||
}
|
||||
.navigationViewStyle(.stack)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private var textField: some View {
|
||||
TextField("Flag Name", text: $featureFlagName)
|
||||
.textInputAutocapitalization(.never)
|
||||
.autocorrectionDisabled()
|
||||
}
|
||||
|
||||
private var warning: Text {
|
||||
Text("Warning: Feature flags are intended for development and debugging use only. They are experimental and subject to change at any time.")
|
||||
}
|
||||
|
||||
private func enableFlag() {
|
||||
if let flag = FeatureFlag(rawValue: featureFlagName) {
|
||||
preferences.enabledFeatureFlags.insert(flag)
|
||||
showing = false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#if DEBUG
|
||||
struct AdvancedPrefsView_Previews : PreviewProvider {
|
||||
static var previews: some View {
|
||||
|
|
Loading…
Reference in New Issue