Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Q: ConnectedView – animations/transitions on props changes #7

Open
skinandbones opened this issue Feb 11, 2020 · 1 comment
Open

Comments

@skinandbones
Copy link

I'm really loving SwiftUIFlux and the direction things are going with ConnectedView. Great job!

One question I've run into is how to handle animations when props change. Here's a very contrived example (leaving out some bits for brevity) ...

struct SimpleExample: ConnectedView {
  struct Props {
    let isVisible: Bool
  }

  func map(state: AppState, dispatch: @escaping DispatchFunction) -> Props {
    return Props(
      isVisible: state.isVisible
    )
  }

  func body(props: Props) -> some View {
    VStack {
      Text("A simple example")

      if props.isVisible {
        Text("I'm visible!").transition(.slide).animation(.easeInOut)
      }
    }
  }
}

This all works except for the animation/transition.

Generally we'd just handle this stuff with @State .... bindings and be done but I'm trying to figure out if there's a way I can manage either the bound @State variable from the store or some other solution so the state of my UI is coming 100% from my store.

In the past in Redux, I've had situations that are more like:

  func map(state: AppState, dispatch: @escaping DispatchFunction) -> Props {
    return Props(
      isVisible: someComplicatedLogic(state)
    )
  }

isVisible is derived from the state and should update / recompute when state changes.

Any recommendations how to handle this situation in a SwiftUIFlux'y way?

@levous
Copy link

levous commented Mar 16, 2020

There shouldn't be anything specific to do with SwiftUIFlux.
this article explains some changes in SwiftUI:
https://swiftui-lab.com/advanced-transitions/

try

      if props.isVisible {
        Text("I'm visible!").transition(
          AnyTransition.opacity.animation(.easeInOut(duration: 1.0))
        )
      }


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants