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

store.dispatch cancelling UITapGestureRecognizer and preventing UITextField input. #317

Open
ghost opened this issue Jan 5, 2018 · 1 comment

Comments

@ghost
Copy link

ghost commented Jan 5, 2018

I have an interesting situation that has been driving me nuts for a day or two that I'd like to solve.

The issue arises when trying to dispatch an action within either an @IBAction function for a tap recognizer or within the UITextfield delegate function shouldChangeCharactersIn.

Some things to note are:

  1. Both functions are in the same view controller which is subscribed to the state.
  2. The state is working, since other view controllers are dispatching actions correctly.
  3. The subscribed controller in question is returning values via the newState() function.
  4. There are no project build errors, but this issue creates an unwanted behavior.
  5. Had the issue with ReSwift 3.0.0. Updated to 4.0.1 and still the same issue.
  6. More than likely this is all happening on the main thread for this controller.
  7. I suspect it's a fault at my end, and not a direct issue with the ReSwift code.

For example, this function works fine as is, until trying to use the store.dispatch line.
When this line is uncommented, the tap won't fire at all.

@IBAction func toggleTap(_ sender: UITapGestureRecognizer) {
    UIView.animate(withDuration: 0.5) {
      self.dismissKeyboard()
      self.resultToggle.flipY()
      self.resultsView.isHidden = self.toggle
    }
    //store.dispatch(SearchOpen(open: toggle))
    toggle = !toggle
  }

Where this code in the shouldChangeCharactersIn function works as intended, but if the store.dispatch lines are uncommented, any text input of the textfields is prevented.

    switch textField {
    case searchField:
      searchCompleter.queryFragment = prospectiveText
      //store.dispatch(SearchLast(last: prospectiveText))
      print("\(prospectiveText)")
    default:
      //store.dispatch(JumpTitle(title: prospectiveText))
      print("\(prospectiveText)")
    }

Some things to note for this are:

  1. The print statements are temporary, and are outputting the expected text.
  2. The switch|case is for the two textfields in the view controller.
  3. As the code above, the textfields accept input from the standard keyboard.
  4. The textfields are not disabled in any way and do accept a tap to become first responder.

If the store.dispatch lines are uncommented this behavior happens:

  1. The textfields refuse any text input and the keyboard dismisses on first tap of any key.

Any help or suggestions of a solution would be great, thanks.

--mike

@DivineDominion
Copy link
Contributor

Hard to say without looking at the rest of the code. Like, what happens on state updates? Do they override the view/view controller data in a weird way?

I'd try 2 things to find the problem:

  1. Dispatch an irrelevant action, like struct TracerAction: ReSwift.Action { } to see if the dispatching is the problem, or the state updates (this unrecognized action should not result in state changes but may trigger still subscribers)
  2. Disable consumption of state updates in subscribers (e.g. newState is still called by the library but does not update the view)

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

1 participant