andrew-levy / sweet-sfsymbols

SF Symbols brought to you by Expo's Module API
61 stars 2 forks source link

Fix cross-platform usage #6

Closed dlindenkreuz closed 7 months ago

dlindenkreuz commented 7 months ago

Sweet-SFSymbols is currently not usable across multiple platforms.

On Android, it produces this warning:

 WARN  The native view manager required by name (SweetSFSymbols) from NativeViewManagerAdapter isn't exported by expo-modules-core. Views of this type may not render correctly. Exported view managers: [ExpoLinearGradient].

On web, it crashes the app:

Uncaught Error
The method or property expo-modules-core.requireNativeViewManager is not available on web, are you sure you've linked all the native dependencies properly?

Call Stack
<global>
node_modules/expo-modules-core/build/errors/CodedError.js:1
constructor
node_modules/expo-modules-core/build/errors/CodedError.js:11:26
<global>
node_modules/expo-modules-core/build/errors/UnavailabilityError.js:3
UnavailabilityError
node_modules/expo-modules-core/build/errors/UnavailabilityError.js:11:6
<global>
node_modules/expo-modules-core/build/NativeViewManagerAdapter.js:7:2
SweetSFSymbol
node_modules/sweet-sfsymbols/build/SweetSFSymbolsView.js:4:35
<global>
components/Icon.tsx:5:39

These issues occur when the module is merely imported — bypassing renders with Platform.OS === "ios" does not help.

This PR simply adds platform-specific filename extensions and a no-op fallback component.

This fixes both the warning and the error and allows devs to pick an alternate component by the usual methods.

andrew-levy commented 7 months ago

Thank you! This looks great, just going to run it and deploy a new version at some point this weekend.

andrew-levy commented 7 months ago

@dlindenkreuz just published sweet-sfsymbols@0.3.0 thanks again for the contribution! When you get some time, can you let me know if its working well for you after upgrading?