Post

Replies

Boosts

Views

Activity

Reply to Access Environment values through PresentationDetents.Context
Yes I'm able to lookup those properties using the context but I'm not able to see the updated values. I'm not trying to update environment using context but rather looking at its values. I want to achieve something like this example but the printed value is the properties default value. struct CustomValueKey: EnvironmentKey { static var defaultValue: CGFloat = 4 } extension EnvironmentValues { var customValue: CGFloat { get { self[CustomValueKey.self] } set { self[CustomValueKey.self] = newValue } } } struct CustomDetent: CustomPresentationDetent { static func height(in context: Context) -> CGFloat? { let customValue = context.customValue // prints property's default value print(customValue) return 300 } } struct Sheet: View { var body: some View { Color.red .presentationDetents([.custom(CustomDetent.self)]) } } struct ContentView: View { @State var showSheet = false var body: some View { Button("Show sheet") { showSheet.toggle() } .sheet(isPresented: $showSheet) { Sheet() } .environment(\.customValue, 24) // this value is not available in custom detent's context } } ``
Aug ’24