question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cannot pass PlatformColor or DynamicColorIOS as fill prop

See original GitHub issue

Description

Hi,

I’ve been using the library for quite a while now, and I’m in the process of implementing Dark Mode on the app.

However, it seems that the transformer won’t accept fill props with colors that came from the new PlatformColor or DynamicColorIOS React Native APIs.

Not sure exactly if the culprit is the transformer or the underlying SVGR.

Any ideas on how we can add support for these new color APIs?

Error logged

[Fri Nov 13 2020 20:04:35.610]  WARN     "[object Object]" is not a valid color or brush 
G@http://localhost:8081/index.bundle?platform=ios&dev=true&minify=false:123276:36
RNSVGSvgView
Svg@http://localhost:8081/index.bundle?platform=ios&dev=true&minify=false:122985:36
SvgComponent

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
rosskhanascommented, Dec 15, 2020

I’m not sure what you are doing exactly, but as a workaround something like this could be done:

import { useColorScheme } from 'react-native';
const colorScheme = useColorScheme();
const fillColor = DynamicColorIOS({ light: '#ff00ff', dark: '#00ffff'})
<LocationIcon width={20} height={20} fill={fillColor.dynamic[colorScheme]} />

Unfortunately, this workaround does not work with PlatformColor 😢

1reaction
kristerkaricommented, Nov 16, 2020

I’m not sure what you are doing exactly, but as a workaround something like this could be done:

import { useColorScheme } from 'react-native';
const colorScheme = useColorScheme();
const fillColor = DynamicColorIOS({ light: '#ff00ff', dark: '#00ffff'})
<LocationIcon width={20} height={20} fill={fillColor.dynamic[colorScheme]} />
Read more comments on GitHub >

github_iconTop Results From Across the Web

How to pass a color prop in React Native - Stack Overflow
Simple case. The only thing that you need to do is mark the property with color type, on IOS. RCT_EXPORT_VIEW_PROPERTY(myMagicColorProp, UIColor).
Read more >
react-native-sfsymbols - npm
In XCode, in the project navigator, right click Libraries ➜ Add Files to [your project's name] · Go to node_modules ➜ react-native-sfsymbols ...
Read more >
types/react-native/index.d.ts - UNPKG
* A navigator is an object of navigation functions that a view can call. 2762, * It is passed as a prop to...
Read more >
How to Manage Dynamic Fill with React Native Svg - ADocLib
However it seems that the transformer won't accept fill props with colors that came from the new PlatformColor or DynamicColorIOS React Native APIs....
Read more >
https://cdn.jsdelivr.net/npm/@types/react-native@0...
The data arguments * emitted will be passed to the listener function. ... Either children or a render prop that receives a boolean...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found