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

Integrate support for SVG icons and fix clear icon #15691

Merged
merged 11 commits into from
Apr 24, 2023
Merged

Conversation

ilmotta
Copy link
Contributor

@ilmotta ilmotta commented Apr 19, 2023

Fixes #15606

Summary

This PR solves the problem described in detail in the issue #15606, but in essence, it fixes the clear icon by integrating support for SVG icons.

  • Hopefully, if SVG icons prove to be a solid solution, we can easily and progressively migrate PNG icons to SVGs, but for the moment, it was aligned with @flexsurfer Clear icon is tinted incorrectly #15606 (comment) that we'll only use SVG icons on demand.
  • Note that it's possible to import SVGs directly via js/require by installing the library react-native-svg-transformer, but this approach is only good when we don't want/need color customization, which is rarely the case with icons where we want to change the foreground and/or background colors. I opted for rendering the SVG icon as hiccup to support color customization.
  • Since icons are fully memoized, I believe the app's performance is on the same ballpark as PNGs rendered with RN Image.
  • It's possible to trim down SVGs by using a tool such as https://github.com/svg/svgo, but this is obviously outside the scope of this PR.

1. Fix incorrect clear icon in the input chat image list

Before

After

2. Fix incorrect clear icon in the input component

3. Fix incorrect clear icon in the input search component

4. Fix incorrect clear icon in the URL preview component

Before

After

Platforms

  • Android
  • iOS

status: ready

@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
d2e891a #1 2023-04-19 22:08:59 ~2 min tests 📄log
✔️ d2e891a #1 2023-04-19 22:12:22 ~5 min android-e2e 🤖apk 📲
✔️ d2e891a #1 2023-04-19 22:12:24 ~5 min android 🤖apk 📲
✔️ d2e891a #1 2023-04-19 22:13:14 ~6 min ios 📱ipa 📲
✔️ d34ede9 #2 2023-04-19 22:19:50 ~5 min android 🤖apk 📲
✔️ d34ede9 #2 2023-04-19 22:20:32 ~6 min ios 📱ipa 📲
✔️ d34ede9 #2 2023-04-19 22:20:58 ~6 min android-e2e 🤖apk 📲
✔️ d34ede9 #2 2023-04-19 22:20:58 ~6 min tests 📄log
Commit #️⃣ Finished (UTC) Duration Platform Result
✔️ 2efc2f0 #3 2023-04-20 13:09:35 ~6 min android-e2e 🤖apk 📲
✔️ 2efc2f0 #3 2023-04-20 13:09:36 ~6 min android 🤖apk 📲
✔️ 2efc2f0 #3 2023-04-20 13:09:41 ~6 min tests 📄log
✔️ 2efc2f0 #3 2023-04-20 13:11:58 ~8 min ios 📱ipa 📲
✔️ 93dffbd #4 2023-04-24 15:14:34 ~6 min android 🤖apk 📲
✔️ 93dffbd #4 2023-04-24 15:14:42 ~6 min android-e2e 🤖apk 📲
✔️ 93dffbd #4 2023-04-24 15:15:04 ~6 min ios 📱ipa 📲
✔️ 93dffbd #4 2023-04-24 15:15:55 ~7 min tests 📄log

children))

(defn- clear-20
[{:keys [color color-2] :as props}]
Copy link
Contributor

Choose a reason for hiding this comment

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

color 2 is like a background color? 🤔

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 initially tried to name color-2 as background-color, just to realize it was more confusing for some icons, like mutual-contact, positive-state, etc, especially when/if we migrate more icons to SVGs I think color-2 is more future proof. It's really like a secondary color, but I didn't want to name it secondary-color or alternate-color, etc, so I ended up going for this simplistic name.

:fill :none}]
children))

(defn- clear-20
Copy link
Contributor

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 use hardcoded size here? Is it better to have a size options like in the container above?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ajayesivan, the SVG exported by Figma only works correctly with a specific dimension, 20 in this case. The SVG generated by Figma for size 12 is different and I checked other icons and it's the same story. So I chose to be as explicit as possible and name the var with the size. The only thing that was safe to generalize was the SVG viewbox, which I extracted into the container component.

Naming the var with the size was the way I found to tell other devs that this icon var should not be used for other sizes.

It is in fact possible to generalize the icons to different sizes by manipulating the path.d prop, but I felt this was out of scope for this issue.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's also good that all of these vars are private, and we can safely improve them in the future without causing breakage.

Copy link
Contributor

@ajayesivan ajayesivan Apr 19, 2023

Choose a reason for hiding this comment

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

Ideally, we should be able to use a single SVG for all size variations, and I think thats one of the major advantages of using SVG over PNG. Maybe we can discuss this with design team and come up with a better solution.

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 @ajayesivan, I think that the point of using vectorized icons is to use one resource for all sizes without loosing quality. Ideally we should export it once.

Also wondering if we add lots of icons how big this file will end up being.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Totally agree with you guys. If we want to replace PNGs with SVGs in the future, we'll need to coordinate with designers a bit of work, especially to optimize them for reusability for different sizes. The exported SVGs from Figma are fine, but not ideal.

Copy link
Contributor

@siddarthkay siddarthkay left a comment

Choose a reason for hiding this comment

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

happy to see SVGs being explored for icons @ilmotta 🚀

:fill :none}]
children))

(defn- clear-20
Copy link
Member

@flexsurfer flexsurfer Apr 20, 2023

Choose a reason for hiding this comment

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

i would suggest to move svg icons to a separate folder as js files with component, because no need in having hiccup , yes they are small, but still why, there are also tools for exporting svg as react components etc, it should make life easier later , on other hand we could have a macro in cljs and load svg file as we did this before, in that case we don't need to do any manuall manipulations with svg, just export same as png

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sounds good, but I think this is a bit of a next step @flexsurfer. Here in this issue my intention was not to create something that can evolve to replace all PNGs. This would be much bigger in scope and more risky as we discussed, since SVG icons may not work that well in all devices.

After this PR, my hope is that we'll explore SVG icons even more, and hopefully manipulating via hiccup won't be necessary as you said. Hopefully we'll be able to automate the work, just as we did with PNGs :)

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 are also tools for exporting svg as react components

I did use a tool to convert the SVG to hiccup automatically ;) Took me 1min http://html2hiccup.buttercloud.com/

i would suggest to move svg icons to a separate folder as js files with component, because no need in having hiccup , yes they are small, but still why, there are also tools for exporting svg as react components etc, it should make life easier later

If you don't mind too much, I prefer to keep the code as is, since there's only one icon now. If this grows, then sure, let's do something better and throw away the code I wrote in this PR.

Copy link
Member

Choose a reason for hiding this comment

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

yes sure, thank you

@ilmotta ilmotta merged commit 1e4a49f into develop Apr 24, 2023
@ilmotta ilmotta deleted the fix/clear-icon branch April 24, 2023 17:28
yqrashawn pushed a commit that referenced this pull request Apr 25, 2023
This commit solves the problem described in detail in issue #15606, but in
essence, it fixes the clear icon by integrating rudimentary support for SVG
icons.

Fixes #15606

- Hopefully, if SVG icons prove to be a solid solution, we can easily and
  progressively migrate PNG icons to SVGs, but for the moment, it was aligned
  with @flexsurfer
  #15606 (comment)
  that we'll only use SVG icons on demand.
- Note that it's possible to import SVGs directly via js/require by installing
  the library react-native-svg-transformer, but this approach is only good when
  we don't want/need color customization, which is rarely the case with icons
  where we want to change the foreground and/or background colors. I opted for
  rendering the SVG icon as hiccup to support color customization.
- Since icons are fully memoized, the app's performance is on the same ballpark
  as PNGs rendered with RN Image.
- It's possible to trim down SVGs by using a tool such as
  https://github.com/svg/svgo, but this is obviously outside the scope of this
  PR.
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.

Clear icon is tinted incorrectly