8

I was making my custom bottom Navbar for which I am unable to Apply styles on my View component

This is what I am importing

import React, {PureComponent} from 'react';
import {StyleSheet, View, Text} from 'react-native';
import Icon from 'react-native-vector-icons/FontAwesome';

And then in return of render, I am calling it like this (this.something are icons here)

  <View styles={headerContainer1}> 
            <Text> {this.News}</Text>
            <Text>{this.home}</Text>
            <Text> {this.Exchange}</Text>
            <Text> {this.about}</Text>
            </View>

Here my Header container looks/and is coming from here

const styles = StyleSheet.create({
    headerContainer1 : {
      display: "flex",
      flexDirection: "row",
      alignItems: 'center',
      backgroundColor: "red",
      borderBottomLeftRadius: 0,
      borderBottomRightRadius: 0
    }
  })

  const { 
    headerContainer1
  } = styles;

Here, I have done two things. flexDirection: "row",and backgroundColor: "red" but unfortunately I can't see any of the changes being Applied.

[Question:] What am I missing or doing wrong? I am attaching the image below for reference

enter image description here

1
  • 3
    try export default styles in the style file. And import styles from 'style file path', in the view, do <View style={styles.headerContainer1}>.... Also, the prop for view should be singular, so style=, not styles= Commented Sep 25, 2018 at 22:32

3 Answers 3

12

First thing in your view you have styles where it should be style. A quick questions, why are you setting a const to the style sheet? Perhaps try bypassing the const and use:

  <View style={styles.headerContainer1}> 
        <Text> {this.News}</Text>
        <Text>{this.home}</Text>
        <Text> {this.Exchange}</Text>
        <Text> {this.about}</Text>
        </View>

Or perhaps just fix the view to change styles to style

  <View style={headerContainer1}> 
        <Text> {this.News}</Text>
        <Text>{this.home}</Text>
        <Text> {this.Exchange}</Text>
        <Text> {this.about}</Text>
        </View>

I'm not sure why you would do it like this, but I'm sure you have your reasons :>

Sign up to request clarification or add additional context in comments.

2 Comments

That (s) was causing the problem. Thanks :)
I had styles and not style. Simple answer that solved my problem.
1

Just use your Stylesheet like this:

        <View style={styles.headerContainer1}> 
          <Text> {this.News}</Text>
          <Text>{this.home}</Text>
          <Text> {this.Exchange}</Text>
          <Text> {this.about}</Text>
        </View>

You just need to reference the Stylesheet, you wouldn't need the second one.

3 Comments

Thanks a lot for your answer but that isn't working as well. Also, For some reason I find second approach sort of clean (just personal preference here)
Can you post the full component?
Thanks a lot JRK. There was a stupid s I added in styles which was causing the problem.
0

You need to add style={styles.name} in your desire components

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.