-
-
Save hallee/e2c79eb771e6780005d92822981f3df9 to your computer and use it in GitHub Desktop.
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
import ComposableArchitecture | |
import SwiftUI | |
struct PopoverReducer: ReducerProtocol { | |
struct State: Hashable { | |
var isPopoverVisible: Bool | |
} | |
enum Action: Hashable { | |
case setPopoverVisible(visible: Bool) | |
} | |
func reduce(into state: inout State, action: Action) -> Effect<Action, Never> { | |
switch action { | |
case .setPopoverVisible(let visible): | |
state.isPopoverVisible = visible | |
return .none | |
} | |
} | |
} | |
struct ContentView: View { | |
let store: StoreOf<PopoverReducer> = .init( | |
initialState: .init(isPopoverVisible: false), | |
reducer: PopoverReducer() | |
) | |
var body: some View { | |
WithViewStore(store) { viewStore in | |
VStack { | |
Button { | |
viewStore.send(.setPopoverVisible(visible: true)) | |
} label: { | |
{ () -> EmptyView in | |
print("PARENT RENDER") | |
return EmptyView() | |
}() | |
Text("Open popover") | |
} | |
} | |
.padding() | |
.popover( | |
isPresented: viewStore.binding( | |
get: { $0.isPopoverVisible }, | |
send: PopoverReducer.Action.setPopoverVisible(visible:) | |
) | |
) { | |
{ () -> EmptyView in | |
print("POPOVER RENDER") | |
return EmptyView() | |
}() | |
Text("Popover") | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment