react-native-linear-gradient: Gradient not working as expected

On OS X El Capitan version 10.11.5 (15F34)

node --version v6.0.0 nam --v v6.2.2 react-native-cli: 1.0.0 react-native: 0.28.0 watchman --v 4.5.0 xcode 7.3.1

I have this code using linear gradient copied from the code given in the examples section:

import LinearGradient from 'react-native-linear-gradient';

const styles = StyleSheet.create({
  parent: {
    flex: 1,
    backgroundColor: colors.MAIN_BACKGROUND_COLOR
  },
  container: {
    flex: 1,
    alignItems: 'center',
    justifyContent: 'center',
  },
  linearGradient: {
    paddingLeft: 15,
    paddingRight: 15,
    borderRadius: 5
  },
  buttonText: {
    fontSize: 18,
    fontFamily: 'Gill Sans',
    textAlign: 'center',
    margin: 10,
    color: '#ffffff',
    backgroundColor: 'transparent',
  },
});
render() {
  return (
      <View style={styles.parent}>
        <View style={styles.container}>
          <LinearGradient colors={['#4c669f', '#3b5998', '#192f6a']} style={styles.linearGradient}>
            <Text style={styles.buttonText}>
              Sign in with Facebook
            </Text>
          </LinearGradient>
        </View>
      </View>);
}

And this is the result that I wasn’t expecting:

gradient

Does someone know the problem with my code and why is it not applying in the proper way? Thank you

About this issue

  • Original URL
  • State: open
  • Created 8 years ago
  • Reactions: 26
  • Comments: 20

Most upvoted comments

@stovmascript What would be the exact steps to properly configure react-native-linear-gradient? Would this be enough for it to work on iOS?

$ npm install react-native-linear-gradient --save
$ rnpm link react-native-linear-gradient
# in XCode, Product -> Clean
# in XCode, Product -> Build

Thanks!

@laura-chacon I also had to do step 3 of https://github.com/brentvatne/react-native-linear-gradient#android manually and rebuild for Android. I used rnpm to link the project, but it evidently doesn’t link things in MainApplication.java, but still does it in MainActivity.java.

@laura-chacon Did you rebuild your project? I just rebuilt mine and it works. Also mentioned in #82.

I noticed that this component is not working with the Navigation component created by wix.

This is on Android. For iOS however, it’s working just fine.

@stovmascript how do I rebuild my React Native project? This is what I have done:

  1. kill simulator
  2. rm -fr $TMPDIR/react-*
  3. in XCode, Product -> Clean
  4. restart computer
  5. in XCode, Product -> Build

@hj1980 I restarted the simulator and also the packager. For restarting the packager I killed the packager from terminal and typed npm start.