Styling react native components












0














When I run following code on my phone



render() {
return [
<View style={{ flex: 1, flexDirection: 'row' }}>
<Search />
</View>,
<View style={{ flex: 1, flexDirection: 'row' }}>
<FlatList
style={styles.list}
data={this.state.products}
renderItem={({ item }) => <ProductCard product={item} />}
keyExtractor={item => item.id}
/>
</View>,
];
}


I am getting screen split between Search and Productcard component. It feels like each one of them takes by default 50% of screen, but I want them to come one after each other.



Search component is just a dummy text:



export default function Search() {
return <Text>Hej</Text>;
}


But when I remove around them it looks good.










share|improve this question






















  • can you remove flex:1 from both the views in the above code and then check.
    – Ayush Nawani
    Nov 12 at 6:01
















0














When I run following code on my phone



render() {
return [
<View style={{ flex: 1, flexDirection: 'row' }}>
<Search />
</View>,
<View style={{ flex: 1, flexDirection: 'row' }}>
<FlatList
style={styles.list}
data={this.state.products}
renderItem={({ item }) => <ProductCard product={item} />}
keyExtractor={item => item.id}
/>
</View>,
];
}


I am getting screen split between Search and Productcard component. It feels like each one of them takes by default 50% of screen, but I want them to come one after each other.



Search component is just a dummy text:



export default function Search() {
return <Text>Hej</Text>;
}


But when I remove around them it looks good.










share|improve this question






















  • can you remove flex:1 from both the views in the above code and then check.
    – Ayush Nawani
    Nov 12 at 6:01














0












0








0







When I run following code on my phone



render() {
return [
<View style={{ flex: 1, flexDirection: 'row' }}>
<Search />
</View>,
<View style={{ flex: 1, flexDirection: 'row' }}>
<FlatList
style={styles.list}
data={this.state.products}
renderItem={({ item }) => <ProductCard product={item} />}
keyExtractor={item => item.id}
/>
</View>,
];
}


I am getting screen split between Search and Productcard component. It feels like each one of them takes by default 50% of screen, but I want them to come one after each other.



Search component is just a dummy text:



export default function Search() {
return <Text>Hej</Text>;
}


But when I remove around them it looks good.










share|improve this question













When I run following code on my phone



render() {
return [
<View style={{ flex: 1, flexDirection: 'row' }}>
<Search />
</View>,
<View style={{ flex: 1, flexDirection: 'row' }}>
<FlatList
style={styles.list}
data={this.state.products}
renderItem={({ item }) => <ProductCard product={item} />}
keyExtractor={item => item.id}
/>
</View>,
];
}


I am getting screen split between Search and Productcard component. It feels like each one of them takes by default 50% of screen, but I want them to come one after each other.



Search component is just a dummy text:



export default function Search() {
return <Text>Hej</Text>;
}


But when I remove around them it looks good.







react-native styling






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 12 at 5:37









Eldlabs

10110




10110












  • can you remove flex:1 from both the views in the above code and then check.
    – Ayush Nawani
    Nov 12 at 6:01


















  • can you remove flex:1 from both the views in the above code and then check.
    – Ayush Nawani
    Nov 12 at 6:01
















can you remove flex:1 from both the views in the above code and then check.
– Ayush Nawani
Nov 12 at 6:01




can you remove flex:1 from both the views in the above code and then check.
– Ayush Nawani
Nov 12 at 6:01












3 Answers
3






active

oldest

votes


















0














are you looking for something like this?



render() {
return(
<View style={{flex: 1, flexDirection: 'column'}}>
<View style={{flexDirection: 'row' }}>
<Search />
</View>,
<View style={{ flex: 1, flexDirection: 'row' }}>
<FlatList
style={styles.list}
data={this.state.products}
renderItem={({ item }) => <ProductCard product={item} />}
keyExtractor={item => item.id}
/>
</View>
</View>
);
}





share|improve this answer





























    0














    I suppose you want to make them scroll, if so you have to wrap them around a <ScrollView>.



    like so,



    render() {
    return (
    <ScrollView>
    <View style={{ flex: 1, flexDirection: 'row' }}>
    <Search />
    </View>,
    <View style={{ flex: 1, flexDirection: 'row' }}>
    <FlatList
    style={styles.list}
    data={this.state.products}
    renderItem={({ item }) => <ProductCard product={item} />}
    keyExtractor={item => item.id}
    />
    </View>
    </ScrollView>
    );
    }


    And in second case if you want only the second half to be scrollable just wrap that view inside a <ScrollView> tag.






    share|improve this answer





























      0














      Thx for helping, it got me in right direction but I got it working by code below:



           <View>
      <Search />,
      <FlatList
      style={styles.list}
      data={this.state.products}
      renderItem={({ item }) => <ProductCard product={item} />}
      keyExtractor={item => item.id}
      />
      ,
      </View>





      share|improve this answer





















        Your Answer






        StackExchange.ifUsing("editor", function () {
        StackExchange.using("externalEditor", function () {
        StackExchange.using("snippets", function () {
        StackExchange.snippets.init();
        });
        });
        }, "code-snippets");

        StackExchange.ready(function() {
        var channelOptions = {
        tags: "".split(" "),
        id: "1"
        };
        initTagRenderer("".split(" "), "".split(" "), channelOptions);

        StackExchange.using("externalEditor", function() {
        // Have to fire editor after snippets, if snippets enabled
        if (StackExchange.settings.snippets.snippetsEnabled) {
        StackExchange.using("snippets", function() {
        createEditor();
        });
        }
        else {
        createEditor();
        }
        });

        function createEditor() {
        StackExchange.prepareEditor({
        heartbeatType: 'answer',
        autoActivateHeartbeat: false,
        convertImagesToLinks: true,
        noModals: true,
        showLowRepImageUploadWarning: true,
        reputationToPostImages: 10,
        bindNavPrevention: true,
        postfix: "",
        imageUploader: {
        brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
        contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
        allowUrls: true
        },
        onDemand: true,
        discardSelector: ".discard-answer"
        ,immediatelyShowMarkdownHelp:true
        });


        }
        });














        draft saved

        draft discarded


















        StackExchange.ready(
        function () {
        StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53256434%2fstyling-react-native-components%23new-answer', 'question_page');
        }
        );

        Post as a guest















        Required, but never shown

























        3 Answers
        3






        active

        oldest

        votes








        3 Answers
        3






        active

        oldest

        votes









        active

        oldest

        votes






        active

        oldest

        votes









        0














        are you looking for something like this?



        render() {
        return(
        <View style={{flex: 1, flexDirection: 'column'}}>
        <View style={{flexDirection: 'row' }}>
        <Search />
        </View>,
        <View style={{ flex: 1, flexDirection: 'row' }}>
        <FlatList
        style={styles.list}
        data={this.state.products}
        renderItem={({ item }) => <ProductCard product={item} />}
        keyExtractor={item => item.id}
        />
        </View>
        </View>
        );
        }





        share|improve this answer


























          0














          are you looking for something like this?



          render() {
          return(
          <View style={{flex: 1, flexDirection: 'column'}}>
          <View style={{flexDirection: 'row' }}>
          <Search />
          </View>,
          <View style={{ flex: 1, flexDirection: 'row' }}>
          <FlatList
          style={styles.list}
          data={this.state.products}
          renderItem={({ item }) => <ProductCard product={item} />}
          keyExtractor={item => item.id}
          />
          </View>
          </View>
          );
          }





          share|improve this answer
























            0












            0








            0






            are you looking for something like this?



            render() {
            return(
            <View style={{flex: 1, flexDirection: 'column'}}>
            <View style={{flexDirection: 'row' }}>
            <Search />
            </View>,
            <View style={{ flex: 1, flexDirection: 'row' }}>
            <FlatList
            style={styles.list}
            data={this.state.products}
            renderItem={({ item }) => <ProductCard product={item} />}
            keyExtractor={item => item.id}
            />
            </View>
            </View>
            );
            }





            share|improve this answer












            are you looking for something like this?



            render() {
            return(
            <View style={{flex: 1, flexDirection: 'column'}}>
            <View style={{flexDirection: 'row' }}>
            <Search />
            </View>,
            <View style={{ flex: 1, flexDirection: 'row' }}>
            <FlatList
            style={styles.list}
            data={this.state.products}
            renderItem={({ item }) => <ProductCard product={item} />}
            keyExtractor={item => item.id}
            />
            </View>
            </View>
            );
            }






            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Nov 12 at 6:02









            DNA.h

            12910




            12910

























                0














                I suppose you want to make them scroll, if so you have to wrap them around a <ScrollView>.



                like so,



                render() {
                return (
                <ScrollView>
                <View style={{ flex: 1, flexDirection: 'row' }}>
                <Search />
                </View>,
                <View style={{ flex: 1, flexDirection: 'row' }}>
                <FlatList
                style={styles.list}
                data={this.state.products}
                renderItem={({ item }) => <ProductCard product={item} />}
                keyExtractor={item => item.id}
                />
                </View>
                </ScrollView>
                );
                }


                And in second case if you want only the second half to be scrollable just wrap that view inside a <ScrollView> tag.






                share|improve this answer


























                  0














                  I suppose you want to make them scroll, if so you have to wrap them around a <ScrollView>.



                  like so,



                  render() {
                  return (
                  <ScrollView>
                  <View style={{ flex: 1, flexDirection: 'row' }}>
                  <Search />
                  </View>,
                  <View style={{ flex: 1, flexDirection: 'row' }}>
                  <FlatList
                  style={styles.list}
                  data={this.state.products}
                  renderItem={({ item }) => <ProductCard product={item} />}
                  keyExtractor={item => item.id}
                  />
                  </View>
                  </ScrollView>
                  );
                  }


                  And in second case if you want only the second half to be scrollable just wrap that view inside a <ScrollView> tag.






                  share|improve this answer
























                    0












                    0








                    0






                    I suppose you want to make them scroll, if so you have to wrap them around a <ScrollView>.



                    like so,



                    render() {
                    return (
                    <ScrollView>
                    <View style={{ flex: 1, flexDirection: 'row' }}>
                    <Search />
                    </View>,
                    <View style={{ flex: 1, flexDirection: 'row' }}>
                    <FlatList
                    style={styles.list}
                    data={this.state.products}
                    renderItem={({ item }) => <ProductCard product={item} />}
                    keyExtractor={item => item.id}
                    />
                    </View>
                    </ScrollView>
                    );
                    }


                    And in second case if you want only the second half to be scrollable just wrap that view inside a <ScrollView> tag.






                    share|improve this answer












                    I suppose you want to make them scroll, if so you have to wrap them around a <ScrollView>.



                    like so,



                    render() {
                    return (
                    <ScrollView>
                    <View style={{ flex: 1, flexDirection: 'row' }}>
                    <Search />
                    </View>,
                    <View style={{ flex: 1, flexDirection: 'row' }}>
                    <FlatList
                    style={styles.list}
                    data={this.state.products}
                    renderItem={({ item }) => <ProductCard product={item} />}
                    keyExtractor={item => item.id}
                    />
                    </View>
                    </ScrollView>
                    );
                    }


                    And in second case if you want only the second half to be scrollable just wrap that view inside a <ScrollView> tag.







                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Nov 12 at 6:03









                    RuthenicEye

                    258




                    258























                        0














                        Thx for helping, it got me in right direction but I got it working by code below:



                             <View>
                        <Search />,
                        <FlatList
                        style={styles.list}
                        data={this.state.products}
                        renderItem={({ item }) => <ProductCard product={item} />}
                        keyExtractor={item => item.id}
                        />
                        ,
                        </View>





                        share|improve this answer


























                          0














                          Thx for helping, it got me in right direction but I got it working by code below:



                               <View>
                          <Search />,
                          <FlatList
                          style={styles.list}
                          data={this.state.products}
                          renderItem={({ item }) => <ProductCard product={item} />}
                          keyExtractor={item => item.id}
                          />
                          ,
                          </View>





                          share|improve this answer
























                            0












                            0








                            0






                            Thx for helping, it got me in right direction but I got it working by code below:



                                 <View>
                            <Search />,
                            <FlatList
                            style={styles.list}
                            data={this.state.products}
                            renderItem={({ item }) => <ProductCard product={item} />}
                            keyExtractor={item => item.id}
                            />
                            ,
                            </View>





                            share|improve this answer












                            Thx for helping, it got me in right direction but I got it working by code below:



                                 <View>
                            <Search />,
                            <FlatList
                            style={styles.list}
                            data={this.state.products}
                            renderItem={({ item }) => <ProductCard product={item} />}
                            keyExtractor={item => item.id}
                            />
                            ,
                            </View>






                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered Nov 13 at 4:54









                            Eldlabs

                            10110




                            10110






























                                draft saved

                                draft discarded




















































                                Thanks for contributing an answer to Stack Overflow!


                                • Please be sure to answer the question. Provide details and share your research!

                                But avoid



                                • Asking for help, clarification, or responding to other answers.

                                • Making statements based on opinion; back them up with references or personal experience.


                                To learn more, see our tips on writing great answers.





                                Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                                Please pay close attention to the following guidance:


                                • Please be sure to answer the question. Provide details and share your research!

                                But avoid



                                • Asking for help, clarification, or responding to other answers.

                                • Making statements based on opinion; back them up with references or personal experience.


                                To learn more, see our tips on writing great answers.




                                draft saved


                                draft discarded














                                StackExchange.ready(
                                function () {
                                StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53256434%2fstyling-react-native-components%23new-answer', 'question_page');
                                }
                                );

                                Post as a guest















                                Required, but never shown





















































                                Required, but never shown














                                Required, but never shown












                                Required, but never shown







                                Required, but never shown

































                                Required, but never shown














                                Required, but never shown












                                Required, but never shown







                                Required, but never shown







                                Popular posts from this blog

                                Florida Star v. B. J. F.

                                Error while running script in elastic search , gateway timeout

                                Adding quotations to stringified JSON object values