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

update guidlines #15686

Merged
merged 2 commits into from
Apr 24, 2023
Merged

update guidlines #15686

merged 2 commits into from
Apr 24, 2023

Conversation

flexsurfer
Copy link
Member

@flexsurfer flexsurfer commented Apr 19, 2023

fixes #15552

  1. added part for inline functions usage in hiccup
  2. relaxed styles rule
  3. changed ### Always apply animated styles in the style file to Never
    because there is no real reason to mix animated styles and hide animated function inside styles namespace , better to just simplify reanimated function
  4. don't mix props and styles in styles ns

@status-im-auto
Copy link
Member

status-im-auto commented Apr 19, 2023

Jenkins Builds

Click to see older builds (8)
Commit #️⃣ Finished (UTC) Duration Platform Result
✔️ 9b9d1e1 #5 2023-04-19 10:16:17 ~6 min android 🤖apk 📲
✔️ 9b9d1e1 #5 2023-04-19 10:16:42 ~6 min android-e2e 🤖apk 📲
✔️ 9b9d1e1 #5 2023-04-19 10:16:47 ~6 min ios 📱ipa 📲
✔️ 9b9d1e1 #5 2023-04-19 10:16:49 ~6 min tests 📄log
✔️ b7438ff #6 2023-04-19 10:30:07 ~6 min android 🤖apk 📲
✔️ b7438ff #6 2023-04-19 10:30:39 ~6 min ios 📱ipa 📲
✔️ b7438ff #6 2023-04-19 10:30:46 ~6 min android-e2e 🤖apk 📲
✔️ b7438ff #6 2023-04-19 10:30:49 ~6 min tests 📄log
Commit #️⃣ Finished (UTC) Duration Platform Result
✔️ edf850a #7 2023-04-19 12:16:22 ~6 min android 🤖apk 📲
✔️ edf850a #7 2023-04-19 12:16:27 ~6 min android-e2e 🤖apk 📲
✔️ edf850a #7 2023-04-19 12:16:42 ~6 min tests 📄log
✔️ edf850a #7 2023-04-19 12:17:48 ~7 min ios 📱ipa 📲
✔️ 4ab086c #9 2023-04-24 12:33:49 ~6 min tests 📄log
✔️ 4ab086c #9 2023-04-24 12:34:04 ~6 min android 🤖apk 📲
✔️ 4ab086c #9 2023-04-24 12:34:04 ~6 min android-e2e 🤖apk 📲
✔️ 4ab086c #9 2023-04-24 12:34:55 ~7 min ios 📱ipa 📲

Comment on lines 100 to 179
;; bad
;; good
(defn circle
[]
(let [opacity (reanimated/use-shared-value 1)]
[reanimated/view {:style (reanimated/apply-animations-to-style
{:opacity opacity}
style/circle-container)}]))

;; good
;; bad
Copy link
Contributor

Choose a reason for hiding this comment

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

I personally don't agree with this. Like that we would be mixing styles with view. Animation styles are still styles. There are animation styles that have 5+ style props, I don't think we should be having these in the view file.

Copy link
Member Author

@flexsurfer flexsurfer Apr 19, 2023

Choose a reason for hiding this comment

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

but its not like static styles right? its not about that you open styles ns and change style, its about defining which styles will be animated (dynamic) if you don't like map in your view you always can move it in a separate function with no problem, if you have 5+ style props it will look like (style/circle-container something-prop1 something-prop2 something-prop3 something-prop4 something-prop5 ) so it doesn't look good anyway, and better to have somethingl like

(let [opacity (reanimated/use-shared-value 1)
       ra-styles  {:opacity opacity}]
    [ra/view (ra/apply-styles style/static ra-styles)])

Copy link
Contributor

Choose a reason for hiding this comment

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

At first I was on @flexsurfer's camp, then a comment from @briansztamfater convinced me to move to @OmarBasem camp, and I was cool there ;) I think styles in general don't look good anyway, but I tend to agree with Omar a little bit more.

Copy link
Member Author

Choose a reason for hiding this comment

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

could you pls share comment from @briansztamfater

Copy link
Member Author

Choose a reason for hiding this comment

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

I think styles in general don't look good anyway

could you elaborate?

Copy link
Member Author

Choose a reason for hiding this comment

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

i feel bad merging without @OmarBasem and @briansztamfater approves :(

Copy link
Member

@briansztamfater briansztamfater Apr 20, 2023

Choose a reason for hiding this comment

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

@flexsurfer sorry I somehow skipped this PR, will check it now :)

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, so we discussed this some time ago, then the discussion leaded to update the guideline as it currently is. The link to the last time we defined this is #15489 (comment)

In general terms, I agree with @OmarBasem and @ilmotta. One of the problems of not declaring animated styles in the styles file, is that it would make our components to have lot of boilerplate code for merging styles with animated styles, when we can abstract the responsibility to the style definition in the styles file and make our components look cleaner.
Also we could end up maintaining a same style for the same view on two different files, making it a bit more difficult to maintain and understand.
Regarding the naming, in the past I proposed renaming apply-animations-to-style to merge-style, the reason behind this is here #15275 (comment). But I assume that is another topic

In conclusion I don't agree with this guideline change but I can adapt, the important thing IMO is to have a guideline to follow and make it immutable at least for a long time :P

Copy link
Member

@briansztamfater briansztamfater Apr 20, 2023

Choose a reason for hiding this comment

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

Also, regarding his example

but its not like static styles right? its not about that you open styles ns and change style, its about defining which styles will be animated (dynamic) if you don't like map in your view you always can move it in a separate function with no problem, if you have 5+ style props it will look like (style/circle-container something-prop1 something-prop2 something-prop3 something-prop4 something-prop5 ) so it doesn't look good anyway, and better to have somethingl like

(let [opacity (reanimated/use-shared-value 1)
       ra-styles  {:opacity opacity}]
    [ra/view (ra/apply-styles style/static ra-styles)])

I feel that as more complex or big the animated style is, the more boilerplate the component will have just to set a style. And if we have many reanimated views in the same component, it might be worse.

(let [opacity (reanimated/use-shared-value 1)
      width (reanimated/use-shared-value 100)
      ra-styles {:opacity opacity
                 :width   width
                 :height  width}]
    [ra/view {:style (ra/apply-styles style/static ra-styles)}])

vs

(let [opacity (reanimated/use-shared-value 1)
      width (reanimated/use-shared-value 100)]
    [ra/view {:style (style/square opacity width)}])

So now let's add a new view to the component that moves horizontally

 (let [opacity (reanimated/use-shared-value 1)
       width (reanimated/use-shared-value 100)
       translate-x (reanimated/use-shared-value 0)
       ra-styles-square {:opacity opacity
                         :width   width
                         :height  width}
       ra-styles-moving {:transform [{:translateX translate-x}]
                         :opacity   opacity}]
     [rn/view
       [ra/view {:style (ra/apply-styles style/static-square ra-styles-square)}]
       [ra/view {:style (ra/apply-styles style/static-moving ra-styles-moving)}]])

vs

(let [opacity (reanimated/use-shared-value 1)
      width (reanimated/use-shared-value 100)
      translate-x (reanimated/use-shared-value 0)]
    [rn/view
      [ra/view {:style (style/square opacity width)}]
      [ra/view {:style (style/moving opacity translate-x)}]])

It just feels more natural and understandable with both animated and static styles in the styles file, also a simpler guideline to follow for contributors.

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't like the idea of having animated styles in the style namespace, but it's true that doing this makes the view code more clean and easier to read, so I vote for having them in the style ns.


```clojure
;; ok
[rn/view {:flex 1 :padding-top 5}]
Copy link
Contributor

Choose a reason for hiding this comment

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

Please, add this style map inside a :style key in a map:

{:style {:flex 1 :padding-top 5}}

just to make sure it's clear that we always want that style key.

Copy link
Contributor

@ilmotta ilmotta left a comment

Choose a reason for hiding this comment

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

I don't agree with the changes proposed for reanimated styles, but if the rest of the crew is okay I'm fine with that as well.

(defn functional-comp [atom]
[rn/text atom])


Copy link
Contributor

Choose a reason for hiding this comment

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

Extra line

@flexsurfer flexsurfer force-pushed the feature/update_guidlined branch from b7438ff to edf850a Compare April 19, 2023 12:09
doc/new-guidelines.md Outdated Show resolved Hide resolved
[rn/view {:style {:flex 1 :padding-top 5}}]
```

### Don't define properties in styles ns
Copy link
Member

Choose a reason for hiding this comment

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

Agree with this one

@flexsurfer flexsurfer force-pushed the feature/update_guidlined branch from edf850a to ec432c6 Compare April 24, 2023 12:26
@flexsurfer flexsurfer merged commit 4a42d20 into develop Apr 24, 2023
@flexsurfer flexsurfer deleted the feature/update_guidlined branch April 24, 2023 12:38
yqrashawn pushed a commit that referenced this pull request Apr 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Archived in project
Development

Successfully merging this pull request may close these issues.

proper usage of :f>
10 participants