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 accept/decline buttons to game result dialog after rematch offer received #1153

Merged
merged 19 commits into from
Nov 20, 2024

Conversation

Jimima
Copy link
Contributor

@Jimima Jimima commented Nov 11, 2024

Just looking at this, seems straightforward to do but just wondering how to handle the UI. Initial implementation (not styled). UI suggestions welcome!

Relates to #1148

@veloce
Copy link
Contributor

veloce commented Nov 11, 2024

In some language "Rematch offered" can be a long text, so I'm not sure it would display nicely on one line.

We could instead have the "Rematch offered" on one line and below the centered buttons "Accept Decline".

@Jimima
Copy link
Contributor Author

Jimima commented Nov 11, 2024

One thing I'm noticing here is that swapping out the button to offer a rematch might be problematic in the case that the user is about the offer a rematch and the UX changes under them. Not sure how big of a problem this is in reality

@Jimima
Copy link
Contributor Author

Jimima commented Nov 11, 2024

Alternate approach

@veloce
Copy link
Contributor

veloce commented Nov 11, 2024

Good question, now sure either how to handle this properly. Perhaps it is not that much a problem.

Also, how about having the whole rematch offer block stand out with a light background color for instance?

@Jimima
Copy link
Contributor Author

Jimima commented Nov 11, 2024

@veloce thanks, I am a bit worried if we add a label above the buttons it will cause a layout shift which could be annoying. I wonder how clear the latest approach is, the "Accept rematch" button implies one has been offered but it's maybe not clear. I think the design is clean, at least

@veloce
Copy link
Contributor

veloce commented Nov 11, 2024

@veloce thanks, I am a bit worried if we add a label above the buttons it will cause a layout shift which could be annoying. I wonder how clear the latest approach is, the "Accept rematch" button implies one has been offered but it's maybe not clear. I think the design is clean, at least

Layout shift can be handled by animating the change I think. Like a height change animation coupled with an opacity animation maybe?

@veloce
Copy link
Contributor

veloce commented Nov 11, 2024

Feel free to experiment with this and share screen recording of the UX that you find works well also.

@Jimima
Copy link
Contributor Author

Jimima commented Nov 11, 2024

Sure I have not really worked with animations so I will have a play around, appreciate the feedback

@veloce
Copy link
Contributor

veloce commented Nov 11, 2024

Animation in flutter is not that hard, once you've chosen the right approach:

😆

@Jimima
Copy link
Contributor Author

Jimima commented Nov 13, 2024

Here is an attempt at using animation, I think it works. In summary:

  1. Remove rematch buttons when opponent offers rematch
  2. Add (hidden) label to indicate the opponent has offered a rematch
  3. Add (hidden) buttons to accent or decline
  4. Animate dialog to fit new content (over 400ms)
  5. Show label buttons once animation is complete

400ms based on gut feel and this

Simulator.Screen.Recording.-.iPhone.16.Plus.-.2024-11-13.at.13.17.40.mp4

@Boubou78000
Copy link

Boubou78000 commented Nov 13, 2024

I think it would be better without animation 😅 Or with a faster one

@Jimima
Copy link
Contributor Author

Jimima commented Nov 13, 2024

It can be faster I thought it would be easier to show it a bit slower for review. Not much point going too fast without simply removing it and I think without it the layout shift could be annoying. Happy for someone to make the call, ultimately, just trying things out at the moment

@Boubou78000
Copy link

Alternate approach

This one is good 👍

@Jimima Jimima force-pushed the 1148-accept-or-decline-rematch-request branch from bffa752 to eec9d65 Compare November 13, 2024 15:23
@Jimima Jimima marked this pull request as ready for review November 14, 2024 09:39
@veloce
Copy link
Contributor

veloce commented Nov 14, 2024

As suggested by @Boubou78000 your alternate approach is better to avoid the layout shift (not showing the "Your opponent offered a rematch").

We'd still use a FadeTransition (with a duration ~300ms I'd say) when the widgets change.

It should be pretty obvious that the opponent offers a rematch, seeing the labels "Accept rematch", "Decline".

Can you post a video showing all the states:

  • offering a rematch
  • cancel rematch offer
  • opponent asking for rematch

Thanks!

@Jimima
Copy link
Contributor Author

Jimima commented Nov 14, 2024

Yeah I'm a little concerned that the buttons alone are not enough but happy to go with that for now. I suspect there will be feedback if it's not clear! Will make the changes, no problem

@Jimima Jimima force-pushed the 1148-accept-or-decline-rematch-request branch from f54c9ed to b0d9fc5 Compare November 14, 2024 14:08
@Jimima
Copy link
Contributor Author

Jimima commented Nov 14, 2024

Changes as discussed. Video:

Simulator.Screen.Recording.-.iPhone.16.Pro.-.2024-11-14.at.13.41.28.mp4

@Boubou78000
Copy link

@Jimima there is still the rematch button when clicked it? Should it not just show a cancel rematch button, not both? Weird 😅

@Jimima
Copy link
Contributor Author

Jimima commented Nov 14, 2024

Oops, yeah that's just a bug. I should have noticed that. Should be better now

Simulator.Screen.Recording.-.iPhone.16.Pro.-.2024-11-14.at.16.20.28.mp4

@Boubou78000
Copy link

Oops, yeah that's just a bug. I should have noticed that. Should be better now

Simulator.Screen.Recording.-.iPhone.16.Pro.-.2024-11-14.at.16.20.28.mp4

Nice 👍

I just noticed another small thing: the rematch and the cancel rematch buttons are the same design, so MAYBE add a box or anything, just to see a visual change 🤔

Othetwise I think this PR is ready to merge 😃

@Jimima
Copy link
Contributor Author

Jimima commented Nov 19, 2024

@veloce I thought I had the commit but apparently not, IDE local history had it though :-)

I have pushed up the animated version.

I had a quick look at how I might keep the rematch button but disable it and I couldn't work out how the enabled/disabled state was being managed. Can you enlighten me?

@Jimima
Copy link
Contributor Author

Jimima commented Nov 19, 2024

Actually never mind, I figured it out I think. Here is a version as requested (I think)

Simulator.Screen.Recording.-.iPhone.16.Pro.-.2024-11-19.at.16.48.27.mp4

@veloce
Copy link
Contributor

veloce commented Nov 19, 2024

Yeah I think it's better like that! Thank you. Looks like the lint is failing.

@Jimima
Copy link
Contributor Author

Jimima commented Nov 19, 2024

It is. I have a bit of tidying up to do anyway so I will do that and let you know

@tom-anders
Copy link
Contributor

@veloce I thought I had the commit but apparently not, IDE local history had it though :-)

I have pushed up the animated version.

I had a quick look at how I might keep the rematch button but disable it and I couldn't work out how the enabled/disabled state was being managed. Can you enlighten me?

FYI for next time, in case your IDE does not have the code in its undo history: you can recover "lost" commits (they're not actually lost, just unreachable) via git reflog

@Boubou78000
Copy link

Actually never mind, I figured it out I think. Here is a version as requested (I think)

Simulator.Screen.Recording.-.iPhone.16.Pro.-.2024-11-19.at.16.48.27.mp4

I think there is a small padding problem between the rematch button and the accept rematch one... But I'm not sure...

@Jimima
Copy link
Contributor Author

Jimima commented Nov 19, 2024

Latest (possibly final 🙂) iteration

Edit: I should probably do a bit more testing of edge cases but here it is in the meantime

Screen.Recording.2024-11-19.at.21.00.05.mov

@Boubou78000
Copy link

Latest (possibly final 🙂) iteration

Edit: I should probably do a bit more testing of edge cases but here it is in the meantime

Screen.Recording.2024-11-19.at.21.00.05.mov

Again, it looks like there is extra space above the rematch button...

@Jimima
Copy link
Contributor Author

Jimima commented Nov 19, 2024

You're right I'll take a look at that tomorrow

@Jimima
Copy link
Contributor Author

Jimima commented Nov 19, 2024

Screenshot 2024-11-19 at 22 25 31

@@ -89,6 +89,7 @@ class _GameEndDialogState extends ConsumerState<GameResultDialog> {
Widget build(BuildContext context) {
final ctrlProvider = gameControllerProvider(widget.id);
final gameState = ref.watch(ctrlProvider).requireValue;
final ValueNotifier<bool> animationFinished = ValueNotifier(false);
Copy link
Contributor

Choose a reason for hiding this comment

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

A ValueNotifier should not be declared in build method I think. If you do that you cannot properly dispose it.

Rather than using ValueNotifier and ValueListenableBuilder you can directly declare a bool in the state object and use setState in onEnd.

visible: animationFinished.value,
child: Column(
children: [
if (gameState.game.opponent?.offeringRematch == true)
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of returning an empty column if gameState.game.opponent?.offeringRematch is false, you could use a ternary operator to return either the column or a Sizebox.shrink() if the opponent is not offering rematch.

@@ -98,6 +99,62 @@ class _GameEndDialogState extends ConsumerState<GameResultDialog> {
padding: const EdgeInsets.only(bottom: 16.0),
child: GameResult(game: gameState.game),
),
AnimatedSize(
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of using AnimatedSize with Visibility have you tried AnimatedCrossfade? This is higher level and the result may be better since it animates size and opacity.

AnimatedCrossFade(
  duration: const Duration(milliseconds: 400),
  firstChild: Sizedbox.shrink(),
  secondChild: RematchOfferDialog(...),
  crossFadeState: gameState.game.opponent?.offeringRematch == true ? CrossFadeState.showSecond : CrossFadeState.showFirst,
)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I wasn't aware of this, will take a look!

@Jimima Jimima force-pushed the 1148-accept-or-decline-rematch-request branch from 8fd87d8 to cff7251 Compare November 20, 2024 12:01
@Jimima
Copy link
Contributor Author

Jimima commented Nov 20, 2024

@veloce I think I addressed your comments. The AnimatedCrossfade works well. I used the curves to somewhat mimic the animation I had before but it's a little nicer, much nicer in code. You can play around with the curves to your hearts content. I think what I have is good but you (or anyone) might prefer a slightly different UX when fading in/out

Simulator.Screen.Recording.-.iPhone.16.Pro.-.2024-11-20.at.11.53.20.mp4

@Boubou78000
Copy link

Boubou78000 commented Nov 20, 2024

Again, there is extra space above the rematch button, maybe because of the box around accept rematch?

I mean that there is not the same distance between the accept rematch button (text) and the rematch button and between the rematch button the new opponent button...

@Jimima
Copy link
Contributor Author

Jimima commented Nov 20, 2024

I added some padding because otherwise the layout felt cramped. This looks well spaced to my eyes

@Boubou78000
Copy link

Ok. Maybe keep padding, but less?

Copy link
Contributor

@veloce veloce left a comment

Choose a reason for hiding this comment

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

Looks great! Thanks @Jimima

@veloce veloce merged commit 28cb95f into lichess-org:main Nov 20, 2024
1 check passed
@Boubou78000
Copy link

Boubou78000 commented Nov 27, 2024

@Jimima On android, the accept rematch and decline buttons aren’t good spaced: there is no horizontal padding...

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

Successfully merging this pull request may close these issues.

4 participants