One component at the left with defined width and another one at its right taking the rest of the horizontal...












0















I'm trying to make an component which has two TextInput's :




  • Number of the street

  • Name of the street


I want the first one to have a width of 35 and the second one to fill the remaining space horizontally.



How would you do that ?



My code:



import React from 'react';
import {StyleSheet, View} from 'react-native';
import FormInput from "./FormInput"

export default class NoStreetInput extends React.Component {
render() {
return(
<View style={{flex:1, flexDirection: 'row'}}>
<FormInput style={{container: {width: 35}}} placeholder="N°" defaultValue="4"/>
<FormInput style={{container: {flexGrow: 1}}} placeholder="Addresse" defaultValue="Chemin Du Moulin" />
</View>
);
}
}


My FormInput component (just in case) :



<View style={styles.container}>
<TextInput
style={styles.textInput}
autoCorrect={false}
defaultValue={this.props.defaultValue}
placeholder={this.props.placeholder}
secureTextEntry={secureTextEntry}
password={password}
keyboardType={keyboardType}
/>
</View>









share|improve this question



























    0















    I'm trying to make an component which has two TextInput's :




    • Number of the street

    • Name of the street


    I want the first one to have a width of 35 and the second one to fill the remaining space horizontally.



    How would you do that ?



    My code:



    import React from 'react';
    import {StyleSheet, View} from 'react-native';
    import FormInput from "./FormInput"

    export default class NoStreetInput extends React.Component {
    render() {
    return(
    <View style={{flex:1, flexDirection: 'row'}}>
    <FormInput style={{container: {width: 35}}} placeholder="N°" defaultValue="4"/>
    <FormInput style={{container: {flexGrow: 1}}} placeholder="Addresse" defaultValue="Chemin Du Moulin" />
    </View>
    );
    }
    }


    My FormInput component (just in case) :



    <View style={styles.container}>
    <TextInput
    style={styles.textInput}
    autoCorrect={false}
    defaultValue={this.props.defaultValue}
    placeholder={this.props.placeholder}
    secureTextEntry={secureTextEntry}
    password={password}
    keyboardType={keyboardType}
    />
    </View>









    share|improve this question

























      0












      0








      0








      I'm trying to make an component which has two TextInput's :




      • Number of the street

      • Name of the street


      I want the first one to have a width of 35 and the second one to fill the remaining space horizontally.



      How would you do that ?



      My code:



      import React from 'react';
      import {StyleSheet, View} from 'react-native';
      import FormInput from "./FormInput"

      export default class NoStreetInput extends React.Component {
      render() {
      return(
      <View style={{flex:1, flexDirection: 'row'}}>
      <FormInput style={{container: {width: 35}}} placeholder="N°" defaultValue="4"/>
      <FormInput style={{container: {flexGrow: 1}}} placeholder="Addresse" defaultValue="Chemin Du Moulin" />
      </View>
      );
      }
      }


      My FormInput component (just in case) :



      <View style={styles.container}>
      <TextInput
      style={styles.textInput}
      autoCorrect={false}
      defaultValue={this.props.defaultValue}
      placeholder={this.props.placeholder}
      secureTextEntry={secureTextEntry}
      password={password}
      keyboardType={keyboardType}
      />
      </View>









      share|improve this question














      I'm trying to make an component which has two TextInput's :




      • Number of the street

      • Name of the street


      I want the first one to have a width of 35 and the second one to fill the remaining space horizontally.



      How would you do that ?



      My code:



      import React from 'react';
      import {StyleSheet, View} from 'react-native';
      import FormInput from "./FormInput"

      export default class NoStreetInput extends React.Component {
      render() {
      return(
      <View style={{flex:1, flexDirection: 'row'}}>
      <FormInput style={{container: {width: 35}}} placeholder="N°" defaultValue="4"/>
      <FormInput style={{container: {flexGrow: 1}}} placeholder="Addresse" defaultValue="Chemin Du Moulin" />
      </View>
      );
      }
      }


      My FormInput component (just in case) :



      <View style={styles.container}>
      <TextInput
      style={styles.textInput}
      autoCorrect={false}
      defaultValue={this.props.defaultValue}
      placeholder={this.props.placeholder}
      secureTextEntry={secureTextEntry}
      password={password}
      keyboardType={keyboardType}
      />
      </View>






      react-native layout






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 24 '18 at 19:35









      davalresdavalres

      43




      43
























          2 Answers
          2






          active

          oldest

          votes


















          0














          To do this, you will simply need to have one TextInput's width set to 35 (which you did), and the other's TextInput with its flex attribute set to 1:



          <View 
          style={{
          flex: 1,
          flexDirection: 'row',
          justifyContent: 'center',
          alignItems: 'center',
          }}
          >
          <TextInput value="No" style={{ width: 35 }} />
          <TextInput value="Street Name" style={{ flex: 1 }} />
          </View>


          (obviously your styling should be kept inside a StyleSheet instead, but you get the point)



          Here's a working example






          share|improve this answer































            0














            Actually I found out what was missing. I begin with React Native and I thought I could access my children style properties of my custom component without adding a props.
            I forgot to create a props for my component so that it can take a style from outside.



            I finally made it like that :



            style={{..}} is now a props in my custom component (see 2nd code)



            export default class NoStreetInput extends React.Component {
            render() {
            return(
            <View style={{flex:1, flexDirection: 'row'}}>
            <FormInput style={{flex:0, width:35}} placeholder={this.props.placeholderNo}
            defaultValue={this.props.defaultValueNo} width="35" keyboardType="number-pad" upperLabel="No"/>
            <FormInput style={{flex:1}} placeholder={this.props.placeholderStree}
            defaultValue={this.props.defaultValueStreet} upperLabel="Rue" />
            </View>
            );
            }
            }


            My custom component (it's a bit different than before but the logic is the same) :



            <View style={[styles.container, this.props.style]}>
            <Text style={[styles.upperLabel, customStyle]}>{upperLabel}</Text>
            <TextInput
            style={[styles.textInput, this.props.textInputStyle]}
            autoCorrect={false}
            defaultValue={this.props.defaultValue}
            value={text}
            placeholder={this.props.placeholder}
            secureTextEntry={secureTextEntry}
            password={password}
            keyboardType={keyboardType}
            maxLength={maxLength}
            onChangeText={this.handleChangeText}
            onSubmitEditing={this.handleSubmitEditing}
            />
            </View>


            style={[styles.textInput, this.props.textInputStyle]} allows me to have a default style for my component, which can be overriden by this.props.textInputStyle :)






            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%2f53461709%2fone-component-at-the-left-with-defined-width-and-another-one-at-its-right-taking%23new-answer', 'question_page');
              }
              );

              Post as a guest















              Required, but never shown

























              2 Answers
              2






              active

              oldest

              votes








              2 Answers
              2






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              0














              To do this, you will simply need to have one TextInput's width set to 35 (which you did), and the other's TextInput with its flex attribute set to 1:



              <View 
              style={{
              flex: 1,
              flexDirection: 'row',
              justifyContent: 'center',
              alignItems: 'center',
              }}
              >
              <TextInput value="No" style={{ width: 35 }} />
              <TextInput value="Street Name" style={{ flex: 1 }} />
              </View>


              (obviously your styling should be kept inside a StyleSheet instead, but you get the point)



              Here's a working example






              share|improve this answer




























                0














                To do this, you will simply need to have one TextInput's width set to 35 (which you did), and the other's TextInput with its flex attribute set to 1:



                <View 
                style={{
                flex: 1,
                flexDirection: 'row',
                justifyContent: 'center',
                alignItems: 'center',
                }}
                >
                <TextInput value="No" style={{ width: 35 }} />
                <TextInput value="Street Name" style={{ flex: 1 }} />
                </View>


                (obviously your styling should be kept inside a StyleSheet instead, but you get the point)



                Here's a working example






                share|improve this answer


























                  0












                  0








                  0







                  To do this, you will simply need to have one TextInput's width set to 35 (which you did), and the other's TextInput with its flex attribute set to 1:



                  <View 
                  style={{
                  flex: 1,
                  flexDirection: 'row',
                  justifyContent: 'center',
                  alignItems: 'center',
                  }}
                  >
                  <TextInput value="No" style={{ width: 35 }} />
                  <TextInput value="Street Name" style={{ flex: 1 }} />
                  </View>


                  (obviously your styling should be kept inside a StyleSheet instead, but you get the point)



                  Here's a working example






                  share|improve this answer













                  To do this, you will simply need to have one TextInput's width set to 35 (which you did), and the other's TextInput with its flex attribute set to 1:



                  <View 
                  style={{
                  flex: 1,
                  flexDirection: 'row',
                  justifyContent: 'center',
                  alignItems: 'center',
                  }}
                  >
                  <TextInput value="No" style={{ width: 35 }} />
                  <TextInput value="Street Name" style={{ flex: 1 }} />
                  </View>


                  (obviously your styling should be kept inside a StyleSheet instead, but you get the point)



                  Here's a working example







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 24 '18 at 22:44









                  ArnaudArnaud

                  229210




                  229210

























                      0














                      Actually I found out what was missing. I begin with React Native and I thought I could access my children style properties of my custom component without adding a props.
                      I forgot to create a props for my component so that it can take a style from outside.



                      I finally made it like that :



                      style={{..}} is now a props in my custom component (see 2nd code)



                      export default class NoStreetInput extends React.Component {
                      render() {
                      return(
                      <View style={{flex:1, flexDirection: 'row'}}>
                      <FormInput style={{flex:0, width:35}} placeholder={this.props.placeholderNo}
                      defaultValue={this.props.defaultValueNo} width="35" keyboardType="number-pad" upperLabel="No"/>
                      <FormInput style={{flex:1}} placeholder={this.props.placeholderStree}
                      defaultValue={this.props.defaultValueStreet} upperLabel="Rue" />
                      </View>
                      );
                      }
                      }


                      My custom component (it's a bit different than before but the logic is the same) :



                      <View style={[styles.container, this.props.style]}>
                      <Text style={[styles.upperLabel, customStyle]}>{upperLabel}</Text>
                      <TextInput
                      style={[styles.textInput, this.props.textInputStyle]}
                      autoCorrect={false}
                      defaultValue={this.props.defaultValue}
                      value={text}
                      placeholder={this.props.placeholder}
                      secureTextEntry={secureTextEntry}
                      password={password}
                      keyboardType={keyboardType}
                      maxLength={maxLength}
                      onChangeText={this.handleChangeText}
                      onSubmitEditing={this.handleSubmitEditing}
                      />
                      </View>


                      style={[styles.textInput, this.props.textInputStyle]} allows me to have a default style for my component, which can be overriden by this.props.textInputStyle :)






                      share|improve this answer




























                        0














                        Actually I found out what was missing. I begin with React Native and I thought I could access my children style properties of my custom component without adding a props.
                        I forgot to create a props for my component so that it can take a style from outside.



                        I finally made it like that :



                        style={{..}} is now a props in my custom component (see 2nd code)



                        export default class NoStreetInput extends React.Component {
                        render() {
                        return(
                        <View style={{flex:1, flexDirection: 'row'}}>
                        <FormInput style={{flex:0, width:35}} placeholder={this.props.placeholderNo}
                        defaultValue={this.props.defaultValueNo} width="35" keyboardType="number-pad" upperLabel="No"/>
                        <FormInput style={{flex:1}} placeholder={this.props.placeholderStree}
                        defaultValue={this.props.defaultValueStreet} upperLabel="Rue" />
                        </View>
                        );
                        }
                        }


                        My custom component (it's a bit different than before but the logic is the same) :



                        <View style={[styles.container, this.props.style]}>
                        <Text style={[styles.upperLabel, customStyle]}>{upperLabel}</Text>
                        <TextInput
                        style={[styles.textInput, this.props.textInputStyle]}
                        autoCorrect={false}
                        defaultValue={this.props.defaultValue}
                        value={text}
                        placeholder={this.props.placeholder}
                        secureTextEntry={secureTextEntry}
                        password={password}
                        keyboardType={keyboardType}
                        maxLength={maxLength}
                        onChangeText={this.handleChangeText}
                        onSubmitEditing={this.handleSubmitEditing}
                        />
                        </View>


                        style={[styles.textInput, this.props.textInputStyle]} allows me to have a default style for my component, which can be overriden by this.props.textInputStyle :)






                        share|improve this answer


























                          0












                          0








                          0







                          Actually I found out what was missing. I begin with React Native and I thought I could access my children style properties of my custom component without adding a props.
                          I forgot to create a props for my component so that it can take a style from outside.



                          I finally made it like that :



                          style={{..}} is now a props in my custom component (see 2nd code)



                          export default class NoStreetInput extends React.Component {
                          render() {
                          return(
                          <View style={{flex:1, flexDirection: 'row'}}>
                          <FormInput style={{flex:0, width:35}} placeholder={this.props.placeholderNo}
                          defaultValue={this.props.defaultValueNo} width="35" keyboardType="number-pad" upperLabel="No"/>
                          <FormInput style={{flex:1}} placeholder={this.props.placeholderStree}
                          defaultValue={this.props.defaultValueStreet} upperLabel="Rue" />
                          </View>
                          );
                          }
                          }


                          My custom component (it's a bit different than before but the logic is the same) :



                          <View style={[styles.container, this.props.style]}>
                          <Text style={[styles.upperLabel, customStyle]}>{upperLabel}</Text>
                          <TextInput
                          style={[styles.textInput, this.props.textInputStyle]}
                          autoCorrect={false}
                          defaultValue={this.props.defaultValue}
                          value={text}
                          placeholder={this.props.placeholder}
                          secureTextEntry={secureTextEntry}
                          password={password}
                          keyboardType={keyboardType}
                          maxLength={maxLength}
                          onChangeText={this.handleChangeText}
                          onSubmitEditing={this.handleSubmitEditing}
                          />
                          </View>


                          style={[styles.textInput, this.props.textInputStyle]} allows me to have a default style for my component, which can be overriden by this.props.textInputStyle :)






                          share|improve this answer













                          Actually I found out what was missing. I begin with React Native and I thought I could access my children style properties of my custom component without adding a props.
                          I forgot to create a props for my component so that it can take a style from outside.



                          I finally made it like that :



                          style={{..}} is now a props in my custom component (see 2nd code)



                          export default class NoStreetInput extends React.Component {
                          render() {
                          return(
                          <View style={{flex:1, flexDirection: 'row'}}>
                          <FormInput style={{flex:0, width:35}} placeholder={this.props.placeholderNo}
                          defaultValue={this.props.defaultValueNo} width="35" keyboardType="number-pad" upperLabel="No"/>
                          <FormInput style={{flex:1}} placeholder={this.props.placeholderStree}
                          defaultValue={this.props.defaultValueStreet} upperLabel="Rue" />
                          </View>
                          );
                          }
                          }


                          My custom component (it's a bit different than before but the logic is the same) :



                          <View style={[styles.container, this.props.style]}>
                          <Text style={[styles.upperLabel, customStyle]}>{upperLabel}</Text>
                          <TextInput
                          style={[styles.textInput, this.props.textInputStyle]}
                          autoCorrect={false}
                          defaultValue={this.props.defaultValue}
                          value={text}
                          placeholder={this.props.placeholder}
                          secureTextEntry={secureTextEntry}
                          password={password}
                          keyboardType={keyboardType}
                          maxLength={maxLength}
                          onChangeText={this.handleChangeText}
                          onSubmitEditing={this.handleSubmitEditing}
                          />
                          </View>


                          style={[styles.textInput, this.props.textInputStyle]} allows me to have a default style for my component, which can be overriden by this.props.textInputStyle :)







                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Nov 25 '18 at 15:01









                          davalresdavalres

                          43




                          43






























                              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.




                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function () {
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53461709%2fone-component-at-the-left-with-defined-width-and-another-one-at-its-right-taking%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

                              A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks

                              Calculate evaluation metrics using cross_val_predict sklearn

                              Insert data from modal to MySQL (multiple modal on website)