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

Request: Expose getImageSource() #26

Closed
andrioid opened this issue Oct 13, 2017 · 36 comments
Closed

Request: Expose getImageSource() #26

andrioid opened this issue Oct 13, 2017 · 36 comments
Labels

Comments

@andrioid
Copy link

andrioid commented Oct 13, 2017

Is it possible to expose getImageSource on the icon-set components?

I've tried adding it myself, but no luck yet.
Seems like the NativeIconAPI is not available, so I can't just add the method.

I would really appreciate a clarification and hopefully a fix.

I'll leave the doc link in the rnvi readme.
https://github.com/oblador/react-native-vector-icons#usage-as-png-imagesource-object

@brentvatne
Copy link
Member

I can be convinced for why this is needed, but the only reason I can see is to use it with ToolBarAndroid or TabBarIOS, and I don't recommend using either of those, so we'll need more than that. Tagged as wontfix until then!

@andrioid
Copy link
Author

Just for arguments sake, I'd like to hear why you wouldn't recommend using standard components from the react-native project. Some of us try to strive for that "native look" and that's just easier with actual native components..

My use-case is, as you mentioned TabBarIOS and ToolBarAndroid.

As for the 'wontfix' tag - that's fair. I imagine that the more native stuff you guys support, the more native code there is to maintain and most stuff can be done in JS anyway.

Can I suggest a little foot-note to the icon-documentation mentioning that getImageSource is not supported and that you recommend against using TabBarIOS and ToolbarAndroid?

@brentvatne
Copy link
Member

@andrioid - sure. I don't recommend using them because they are not cross-platform and can be easily re-created using react-native components, and they are less flexible even on the platform they do work on than just using a rebuilt one with react-native components. Is there some particular behavior you see in TabBarIOS and ToolBarAndroid that you don't get with just using the react-navigation tab bar and navigation bar? If so, we should improve react-navigation accordingly

@brentvatne
Copy link
Member

Oops, forgot to mention the footnote -- yeah we should do this. I have had an open issue here for a while to warn or throw an error with TabBarIOS and vector-icons, if you could add a note to README and/or add some warning/error at runtime and send a PR this would be very helpful!

@dannin
Copy link

dannin commented Aug 5, 2018

How do we use the icons in a MapView without getImageSource @brentvatne?

@brentvatne
Copy link
Member

@dannin - use images i suppose

@oxyii
Copy link

oxyii commented Mar 16, 2019

+1, I need getImageSource

@klase
Copy link

klase commented Nov 6, 2019

Why is this tagged wontfix? How else would you use the icons on a map view?

@brentvatne
Copy link
Member

use a static image @klase, i don't see why this needs to be done at runtime

@klase
Copy link

klase commented Nov 7, 2019

@brentvatne In our case we load the markers from a json file and since only local image resources are allowed to be used in react-native-maps, it seems odd to include assets twice when we already reference the icon set elsewhere (for tab navigation for example).

@brentvatne
Copy link
Member

@klase - you can make it a remote image local by downloading it with FileSystem.downloadAsync :) so there is a workaround for now.

i definitely empathize with what you're saying from an ergonomics point of view though - it seems easier to just get the image source from the font at runtime. i'd be open to a proposal for a more generic module in expo to do this, but i don't think we should add it to the vector-icons lib and make it inherently coupled to icons.

@oxyii
Copy link

oxyii commented Nov 7, 2019

Looks like @expo/vector-icons does not include react-native-vector-icons NATIVE modules, so @expo/vector-icons cannot expose RNVI native methods... But babel-preset-expo trying to tell us that this is a complete analogue. Unfortunately, it is not. And I don't think that we will be able to convince expo members of the opposite

@brentvatne
Copy link
Member

brentvatne commented Nov 7, 2019

i think the best approach is to extract those native methods from react-native-vector-icons into another library that is specific to the functionality that they provide.

we don't like to include native modules when the api is designed as a grab bag of assorted functionality - we prefer if they are broken down into general purpose primitives. if we don't do this then the api surface area becomes a mess of slightly overlapping functionality in different libraries with a burden of maintaining ad-hoc implementations of the same thing in different places resting on us.

@oxyii - as for why we map react-native-vector-icons directly to @expo/vector-icons, this is very important for compatibility with the ecosystem of libraries such as react-native-paper and react-native-elements that depend on react-native-vector-icons. they do not use the getImageSource native method

@brentvatne
Copy link
Member

perhaps a good place to include this method could be on expo-font - named something like extractGlyph - then we could expose getImageSource but have it depend on that implementation instead, and people can use the more generic Font.extractGlyph elsewhere too

@klase
Copy link

klase commented Nov 8, 2019

@brentvatne FileSystem.downloadAsync is not really a practical solution for us as it would require a network connection initially, but I do see your point about the api surface. +1 for adding it to expo-font.

@oxyii
Copy link

oxyii commented Nov 8, 2019

I still think it should be here. react-native-vector-icons have a documented behavior, @expo/vector-icons forced (via babel) react-native-vector-icons requests to @expo/vector-icons... According to my logic, native methods should be implemented here

@brentvatne
Copy link
Member

@klase - if the image is already bundled in your app (via assetBundlePatterns) then you can use it just fine w/o FileSystem.downloadAsync, so that could be an option for you for now.

@oxyii - i updated the readme for you so that the documented behavior in @expo/vector-icons is clear 233adbb

@oxyii
Copy link

oxyii commented Nov 8, 2019

@brentvatne ha-ha, thank you. But this is just escape from the problem. babel-preset-expo is still forced RNVI requests to @expo/vector-icons and @expo/vector-icons still does not contain RNVI documented functionality.

Look, I don’t really care anymore. Expo - is a BEST, really best way to learn react-native. And I am really very grateful to expo... Also I noticed that expo is moving towards modularity and it's great! But compatibility with native modules ceased to be enough for me... So I went to pure react-native.

But it seems that this question will still rise before you. Good luck to all!

@oxyii
Copy link

oxyii commented Nov 9, 2019

@iddan can you join this discussion? I think your react-native-canvas lib with merged react-native-canvas#109 can help workaround this... especially since WebView is already included in expo

@iddan
Copy link

iddan commented Nov 9, 2019

I'm sorry @oxyii but I'm not sure how can I help here. Would you mind giving me some context?

@oxyii
Copy link

oxyii commented Nov 9, 2019

@iddan @expo/vector-icons cannot provide RNVI method getImageSource because this method is native. But this method just create 2d context, print one symbol (with specific font) into it and then get base64 string with png MIME...
We need to this method because native components (such a maps of bottom tabbar) cannot use vector

This is android implementation for example https://github.com/oblador/react-native-vector-icons/blob/master/android/src/main/java/com/oblador/vectoricons/VectorIconsModule.java#L43

@iddan
Copy link

iddan commented Nov 9, 2019

I'm not sure creating a canvas for this would be the right approach. But I was intending to use Skia's Canvas Kit in React Native Canvas instead of a WebView. Maybe it can help you achieve what you want: https://skia.org/user/modules/canvaskit

@oxyii
Copy link

oxyii commented Nov 9, 2019

@iddan Very interesting... but looks like WebAssembly is not yet supported on RN... at least not on all platforms and simulators react-native-community/jsc-android-buildscripts#113

Seems that this issue can not be resolved without a WebView. Sorry guys.

react-native-canvas lib with merged react-native-canvas#109 can help workaround this...

Looks like this is the only solution for now

@oxyii
Copy link

oxyii commented Nov 10, 2019

Despite the fact that this functionality is not relevant for me, I could not help but think about it.
@andrioid @klase @dannin @robksawyer @foreleven the only thing I could do for you was server-side conversion https://github.com/oxyii/getimagesource

if the expo does not plan to include RNVI native module then I think this issue can be closed

@iddan
Copy link

iddan commented Nov 10, 2019

@oxyii you can compile WASM to asm.js to support JSC

@oxyii
Copy link

oxyii commented Nov 10, 2019

@iddan I'm not an expert on emsdk compilation tuning... Pre-built wasm have a size about 7Mb. My asm version - more that 13Mb... too expensive for this issue in both cases.. even if it will work )))
Plus asm status "very experimental" (I know that it's another module), plus asm.js performance issues...

@nandorojo
Copy link

nandorojo commented Nov 8, 2021

I want the image source so that I can render it in a native iOS menu component. There's no way to render JSX inside of this component. Is the solution to just copy the image file into my assets?

@oxyii
Copy link

oxyii commented Nov 8, 2021

@nandorojo a lot of time has passed since then. I'm sure you can use pre-caching. But I do not recommend using my deployments of getImageSource repo. I do not guarantee that the resources will work. Feel free to clone repo and create your own deployment. But it's easier to copy the image files into assets

@brentvatne
Copy link
Member

using eas build you can use the getImageSource function from react-native-vector-icons

@mpinkard
Copy link

mpinkard commented Feb 9, 2022

using eas build you can use the getImageSource function from react-native-vector-icons

@brentvatne Would you mind elaborating on your comment?

@brentvatne
Copy link
Member

you can learn more about eas build vs expo build in these blog posts:

https://blog.expo.dev/expo-managed-workflow-in-2021-5b887bbf7dbb
https://blog.expo.dev/expo-managed-workflow-in-2021-d1c9b68aa10

tl;dr expo build doesn't let you include custom native code, eas build does. you can also get a similar experience to expo go by using expo-dev-client

@artsnr1
Copy link

artsnr1 commented Sep 5, 2023

I need getImageSource to use as a thumb image in slider

@nandorojo
Copy link

probably best to just download and import the image of the icon itself

@artsnr1
Copy link

artsnr1 commented Sep 5, 2023

How to do that? except using Filesystem.download...? Like if I want to keep it in my assets folder

@nandorojo
Copy link

just download the icon from figma or your icon maker’s website

@kevindetry
Copy link

Looks like react-native-bottom-tabs needs this: https://okwasniewski.github.io/react-native-bottom-tabs/docs/guides/usage-with-vector-icons.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

10 participants