-
Notifications
You must be signed in to change notification settings - Fork 127
Apply hideCaret to LayoutTree when indent changes #2657
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
Apply hideCaret to LayoutTree when indent changes #2657
Conversation
@raineorshine This isn't quite working because |
I like the idea of using the css transition to control the visibility and not messing with js timers. But I haven't really used this technique before, so I'm unsure exactly what will trigger it at the right time. Another option is something like AnimationEnd event, though I haven't used that either. |
|
@raineorshine Is it possible/OK to write custom CSS classes? I know we're trying to avoid doing that, but I think that adding a class like |
There should be a PandaCSS way to accomplish that. The App.css has been fully deprecated at this point. That doesn't means that css can't be applied... it just needs to be applied through the typesafe way of Panda recipes. |
Here is a CSS animation-based solution that uses 2 identical animations to trick the element into replaying the animation whenever the indent level changes. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! Very clever and elegant.
Let's apply this only on iOS Safari since that is where the problem occurs.
isTouch && isSafari()
The only problem with the even/odd distinction is that it doesn't work when tapping two thoughts down.
trim.720E70DC-C232-4A37-8908-6BB638841551.MOV
Hmm, yeah, that is a problem with the entire named animation approach. Is there a modulo that you think will cover the entire visible area? Maybe 10 or 16 different named animations? I would love to think of something a little less hacky, but I haven't been able to do so. The other option is to try to remove the animation after it completes, and then add it back when the indent changes again. Challenges include: 1 getting |
It looks like it will show a maximum of 12 one-line thoughts at a time? Maybe that depends on screen height? |
The number of thoughts on the screen will depend on screen height and font size. Practically speaking, trees don't usually exceed a depth of 12–15. That said, if we're creating a named animation for each depth anyway, then there's not much downside to defining enough to cover all reasonable cases. I think 16 would be fine. I agree that removing + re-adding the animation is likely to lead to other troubles. |
src/components/LayoutTree.tsx
Outdated
@@ -881,6 +881,41 @@ const LayoutTree = () => { | |||
return ( | |||
<div | |||
className={css({ | |||
// the hideCaret animation must run every time the indent changes on iOS Safari, which necessitates replacing the animation with an identical substitute with a different name | |||
animation: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@raineorshine This works, but is pretty unpleasant to look at. Any attempt that I made to package this code or make it dynamic (including an inlined IIFE) broke Panda's static analysis. I'll try to poke at it some more later to see if I can get it to work better. If you have a preferred way to abstract logic like this while keeping static analysis, please share.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, good point. I'm thinking either a recipe with variants would work (possibly programmatically generated), or switching to a style
attribute and accessing the animation through token
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@yangchristina Could I get your input on this? Would recipe variants be able to select on the indentation level at runtime?
We have to trick the browser into thinking the animation has changed at each indentation level, so that's why each animation has its own name.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@raineorshine Yes, recipes should be fine to use, just make sure you add staticCss: ['*']
. You can also use cva
since this is only used in one place, and you won't need staticCss: ['*']
for cva
(it'll automatically generate all variants)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@yangchristina Great, thanks for confirming!
@ethan-james Would you mind looking into cva as a way to clean this up? Reach out to me personally if this looks like a lot of trouble, as I want to be respectful of your time.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@yangchristina @raineorshine Thanks for your guidance! The latest commit represents how I think I want it to work, but it still doesn't seem to be generating the classes for the recipe variant. If you think there's a specific piece that I can tweak to make it work, please let me know.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now it's no longer the most recent commit. Better to just look at the whole diff.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hideCaretAnimationNames
must be in the same file as cva
. hideCaret
might also have to be directly in LayoutTree.tsx
instead of imported.
I tried with both hideCaret
and hideCaretAnimationNames
in LayoutTree.tsx
and it did generate the classes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can check whether the classes have been generated with npx panda debug src/components/LayoutTree.tsx
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@yangchristina Thanks! Keeping them in a separate file seems to work, with the only issue being that Panda's config can't pull the constants from getHideCaretAnimationName.ts
. It says ERROR: Could not resolve "../../styled-system/css"
so I guess there are different stages of the toolchain or something like that. Duplicating the constants in getCaret.config.ts
& getHideCaretAnimationName.ts
seems like a relatively small price to pay.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is looking better, but I'm not quite satisfied. While the duplication is small in terms of lines of code, it reflects a lack of understanding of the tools. I have a strong feeling that there is a better way. There must be something we are missing.
The fact that both hideCaret.config.ts
and getHideCaretAnimationNames
both export the same value adds to the confusion.
If you feel that you have made all reasonable attempts and are not sure how to simplify it further, just let me know and I will take over.
@raineorshine I tried to use The only thing I can think of that might fit Panda's ethos more closely would be to do away with the abstracted list and simply define all of the keyframes by key in |
This comment was marked as outdated.
This comment was marked as outdated.
@raineorshine have you tested this on safari? From panda debug it doesn't look like the classes are being generated. |
3160752
to
ee28809
Compare
Sadly, I'm running into some difficulties testing changes, because either vite or the browser is caching the styles. This throws into question my whole refactor. I reverted my changes and am happy to move forward with your implementation. @ethan-james The only problem is that it the solution does not work after rebasing on |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Of course, the duration token! Thanks :)
@raineorshine That's OK, hopefully I can figure out a cleaner fix if I have some time left over during future milestones. For now, I fixed |
Fixes #4
Animating transform doesn't update the caret position correctly in iOS Safari. Hiding the caret during the animation will prevent this visual bug.