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

Improve behavior for animated graph with gesture #14

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

foyarash
Copy link

@foyarash foyarash commented May 24, 2022

Animated graph with gestures enabled had some improvements in my opinion.

This PR adds the following:

  • Allows to highlight the graph partially thanks to an initialIndex prop. This will basically give an initial position to the circle. The old behavior was not really appropriate: the whole graph had a translucent color. With this prop, this gives the possibility to highlight the whole graph.
  • Add the possibility to pass a custom duration for the gesture long press gesture
  • Currently, when releasing the gesture, the circle goes back to the end of the graph. The PR introduces a resetPositionOnRelease prop. Passing true as a value will keep the old behavior, while passing false will keep the circle at the last position where the gesture was released.

@mrousavy
Copy link
Member

Hey! Thanks for your PR!

Allows to highlight the graph partially thanks to an initialIndex prop. This will basically give an initial position to the circle. The old behavior was not really appropriate: the whole graph had a translucent color. With this prop, this gives the possibility to highlight the whole graph.

I don't really understand this, could you maybe elaborate a bit? Do you have a screenshot/GIF to compare before/after?

src/AnimatedLineGraph.tsx Outdated Show resolved Hide resolved
Comment on lines -204 to +220
() => x.value,
(fingerX) => {
runOnJS(setFingerX)(fingerX)
() => [x.value, isActive.value],
([fingerX, isActiveValue]) => {
if (isActiveValue) {
runOnJS(setFingerX)(fingerX as number)
}
Copy link
Member

Choose a reason for hiding this comment

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

Why this change? Afaik it worked fine before

Copy link
Author

Choose a reason for hiding this comment

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

This goes with the idea of the graph highlight & the initialIndex. On the initial render, the setFingerX function is executed, but as there is no gesture, the highlight path starts at 0.

src/AnimatedLineGraph.tsx Outdated Show resolved Hide resolved
src/AnimatedLineGraph.tsx Outdated Show resolved Hide resolved
src/AnimatedLineGraph.tsx Outdated Show resolved Hide resolved
src/AnimatedLineGraph.tsx Outdated Show resolved Hide resolved
src/AnimatedLineGraph.tsx Outdated Show resolved Hide resolved
@foyarash
Copy link
Author

Hello

Sorry for the misunderstanding.

So basically, this is the look we have when the graph renders initially on the current version:

Simulator Screen Shot - iPhone 13 - 2022-05-27 at 12 01 48

With the initialIndex prop (here i set it to 35 in the example app):

Simulator Screen Shot - iPhone 13 - 2022-05-27 at 12 02 00

The highlight part i am talking about is the opaque blue part, at the left part of the graph in the second screenshot.

The initial goal was to be able to have the opaque blue part going all the way to the end of the graph. But i thought giving more flexibility to put it until a certain index might be better.

Let me know if that is more clear for you

@mrousavy
Copy link
Member

Let me know if that is more clear for you

Got it, but I can't think of a use-case for this feature atm. - why would you want to have the path hard-stop at a given point? This whole thing is built as an interactive gesture for the user

@foyarash
Copy link
Author

Let me know if that is more clear for you

Got it, but I can't think of a use-case for this feature atm. - why would you want to have the path hard-stop at a given point? This whole thing is built as an interactive gesture for the user

Taking the coinbase app as a reference, the graph is fully highlighted in the initial render. Maybe the case of highlighting the graph partially is a bad idea, but i dont think its a bad idea to highlight the whole graph

@foyarash foyarash requested a review from mrousavy May 27, 2022 11:44
@foyarash
Copy link
Author

Hello @mrousavy have you had a chance to look at the latest changes ? Thank you 🙂

@Lexical-Luke
Copy link

@mrousavy This is a really great idea when visualizing past and forecasted data!
This way you could plot the current time moving on the graph.

Can this PR be approved? I'd like to use this feature.

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.

None yet

3 participants