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

Add async-CustomInput support #182

Merged
merged 5 commits into from
Jun 18, 2019
Merged

Add async-CustomInput support #182

merged 5 commits into from
Jun 18, 2019

Conversation

inamiy
Copy link
Contributor

@inamiy inamiy commented Jun 4, 2019

This PR is an experiment of asynchronously displaying CustomInput after cell tap.
Example demo can be found in SignUp screen.

This feature is needed when OptionPicker 's data is not ready yet and requires async fetch before CustomInput presentation.
It is triggered by state change and focusesOnFirstDisplay is set.

The implementation is complete, so please review and tell me this is the right way to go.
(Please don't review about example code. It will be deleted afterwards)

Changes

  • ad713ac Added func customInputImmediately(when:input:)
  • Added focusesOnFirstDisplay
  • Allow CustomInputComponent.ComponentView to present FocusToolbar without back/forward buttons when it is not focus-eligible (due to asynchrony).

Screencast

TODO

  • Organize example

@inamiy inamiy added the help wanted Extra attention is needed label Jun 4, 2019
@inamiy inamiy self-assigned this Jun 4, 2019
@inamiy
Copy link
Contributor Author

inamiy commented Jun 5, 2019

ad713ac
Simplified code to func customInputImmediately(when:input:).
Previous tweaks in func customInput is reverted.

@inamiy inamiy added the ready for review Reviewers can now review the PR label Jun 6, 2019
@inamiy inamiy marked this pull request as ready for review June 6, 2019 10:40
@RuiAAPeres RuiAAPeres requested review from andersio, TheAdamBorek and dmcrodrigues and removed request for andersio and TheAdamBorek June 12, 2019 10:24
input: (State) -> CustomInput,
highlightColor: UIColor? = UIColor(red: 239/255.0, green: 239/255.0, blue: 244/255.0, alpha: 1)
) -> AnyRenderable {
return CustomInputComponent(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really need to change CustomInputComponent to support this? Why can't we just return self when state is nil? At least I think this should be done the same way that we build boxes where sections and/or nodes are conditionally composed depending on a certain condition and here I think we could follow the same principle, if the state is nil it means there's no CustomInput so we don't need a CustomInputComponent but once that changes we can then build a CustomInputComponent to display that input.

I'm not sure if I'm missing some detail.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

state = nil doesn't mean we don't use customInput at all.
It's rather the same behavior as we already have: "Show customInput when user tapped"

On the contrary, when state exists, customInput shows immediately when re-rendered.
It also holds the same property "show customInput when user tapped" as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe I should rename method e.g. func customInput(immediatelyWhen:...) so that "immediately" belongs to state existence.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

state = nil doesn't mean we don't use customInput at all.
It's rather the same behavior as we already have: "Show customInput when user tapped"

I'm a bit confused, in your example you tap Gender and there's no input being presented, you display an activity indicator as accessory and after 1 sec. your state changes and then it shows the option picker, why do we need to have a custom input before the change of state?

Copy link
Contributor Author

@inamiy inamiy Jun 12, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we need to have a custom input before the change of state

That's good question!
IIRC I tried the same approach by removing customInput only when loading.
But this caused Bento diffing animation for the entire "gender cell" that I wanted to avoid.
So, keeping customInput throughout the handling is (probably) required to avoid such animations.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh yes it does that because we are swapping from one component to another one if we do that 😕

I don't see any way to avoid that animation but maybe @andersio has an idea.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There could be some diffing optimization, but I think it's still OK to always keep customInput during loading.
It might still be able to tap though (which will be a bug), I can add isEnabled property to prevent that, so that we don't need to worry about removal animation of customInput.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(For sure diffing optimization will be more nice, but we won't probably invest too much here)

Copy link
Contributor

@andersio andersio Jun 17, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#146 is meant to tackle that. But I'd be surprised that there is any deleting animation. It should be a subtle cross-fade.

@inamiy
Copy link
Contributor Author

inamiy commented Jun 14, 2019

In PR party, @andersio came up with an idea of showing loading indicator inside keyboard so that focus eligibility (keyboard switching) can still work and has a better user experience.

While I agree on this UX improvement, this PR is still orthogonal that we want to have some functionality to present the keyboard immediately, e.g. SwiftUI's presentation(_: Modal?) driven by state change to set Modal.

So, we concluded that this PR will be reviewed separately without considering about loading-keyboard.

Copy link
Contributor

@andersio andersio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto

@inamiy
Copy link
Contributor Author

inamiy commented Jun 17, 2019

f789bcc Reverted example code.

@inamiy inamiy merged commit c6faf66 into develop Jun 18, 2019
@inamiy inamiy deleted the inamiy/async-CustomInput branch June 18, 2019 08:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed ready for review Reviewers can now review the PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants