react-native-ui-kitten
react-native-ui-kitten copied to clipboard
Error while using third party icons
💬 Question
UI Kitten and Eva version
Package | Version |
---|---|
@eva-design/eva | ^2.1.1 |
@ui-kitten/components | ^5.1.2 |
Hello, I'm trying to implement a third party icons package (Feather/Fontawesome), I copied the exact example mentioned in the official documentation, and when I try to use the Icons I get this error :
TypeError: undefined is not an object (evaluating '_StyleSheet$flatten.height')
Here is my feather icons file :
import React from 'react';
import { StyleSheet } from 'react-native';
import Icon from 'react-native-vector-icons/Feather';
export const FeatherIconsPack = {
name: 'feather',
icons: createIconsMap(),
};
function createIconsMap() {
return new Proxy({}, {
get(target, name) {
return IconProvider(name);
},
});
}
const IconProvider = (name) => ({
toReactElement: (props) => FeatherIcon({ name, ...props }),
});
function FeatherIcon({ name, style }) {
const { tintColor, ...iconStyle } = StyleSheet.flatten(style);
return (
<Icon name={name} size={height} color={tintColor} style={iconStyle} />
);
}
And here is how I registered the icon pack :
<IconRegistry icons={[EvaIconsPack, FeatherIconsPack]}/>
My icon implementation example:
<Icon pack='feather' name='home' />
@soltaneben are you using an expo
stack or pure react-native
?
Because I have a feeling it's the same issue as #1601
@soltaneben can you please check your code snippet, I think height
is missing in destructuring expression. From what I see the issue appears because you're not passing style
prop to you Icon
(here <Icon pack='feather' name='home' />
).
so flattening undefined
value returns undefined
which you're trying to destructure. so you may want to make a null check or use default values in destructuring. the rest looks fine, check that style
prop thing, it should work
I move the ticket to closed due to low activity and the proposed option to help.
If the problem continues to occur, please indicate in the ticket we will reopen it and look for a solution.