react-native-check-box icon indicating copy to clipboard operation
react-native-check-box copied to clipboard

Proptype warning when using StyleSheet on rightTextStyle

Open danielforsberg opened this issue 8 years ago • 3 comments

Hi,

So if I use StyleSheet to apply the style like this:

const AppCheckBox = ({onClick, rightText}) => {
  return (
    <CheckBox
      onClick={onClick} rightText={rightText}
      rightTextStyle={styles.rightText} />
  )
}

const styles = StyleSheet.create({
  rightText: {flex: 0, color: '#FFF', fontFamily: 'Arial', fontSize: 20}
})

I get this warning:

Warning: Failed prop type: Invalid prop rightTextStyleof typenumbersupplied toCheckBox, expected object.

But this works:

const AppCheckBox = ({onClick, rightText}) => {
  return (
    <CheckBox
      onClick={onClick} rightText={rightText}
      rightTextStyle={{flex: 0, color: '#FFF', fontFamily: 'Arial', fontSize: 20}} />
  )
}

danielforsberg avatar Oct 29 '17 10:10 danielforsberg

I'm get the same error

charleycesar avatar Nov 26 '17 21:11 charleycesar

@danielforsberg @charleycesar Problem is that you applied View props to Text props, and therefore you get this error.

Remove flex from style, should be fine.

ziyafenn avatar Dec 02 '17 13:12 ziyafenn

@danielforsberg @charleycesar

To fix this problem, we can try to fix some ways:

1. Flatten style

use StyleSheet.flatten(styles.rightText)

2. Change propTypes object in this checkbox component

static propTypes = {
    ...
    rightTextStyle: PropTypes.instanceOf(StyleSheet)
    ...
}

Today, I found to use instanceOf emit warning message into log. but it seems no problem to use.

Jaewoook avatar Dec 11 '17 11:12 Jaewoook