tcomb-form-native icon indicating copy to clipboard operation
tcomb-form-native copied to clipboard

keyboard hides the textInput field

Open harikanammi opened this issue 6 years ago • 10 comments

I am running sample example using this module. My question is i am focusing on input field..... keyboard is displaying but textInput field is hiding. This problem comes only for android. Please give any suggestions. Thank you in advance.

here is my code:

initFormValues = () => {
    const Email = Tcomb.refinement(Tcomb.String, s => Validator.checkEmail(s) === undefined)
    Email.getValidationErrorMessage = s => Validator.checkEmail(s)
    const Phone = Tcomb.refinement(Tcomb.String, s => Validator.checkPhone(s) === undefined)
    Phone.getValidationErrorMessage = s => Validator.checkPhone(s)
    this.Customer = Tcomb.struct({
      first_name: Tcomb.String,
      last_name: Tcomb.String,
      address_1: Tcomb.String,
      suburb: Tcomb.String,
      country: Tcomb.String,
      state: Tcomb.String,
      postcode: Tcomb.String,
      email: Email,
      phone: Phone,
      note: Tcomb.maybe(Tcomb.String) //maybe = optional
    })
    this.options = {
      auto: 'none', 
      fields: {
        first_name: {
          label: Languages.FirstName,
          placeholder: Languages.TypeFirstName,
          error: Languages.EmptyError, //for simple empty error warning.
          underlineColorAndroid: 'transparent',
          stylesheet: labelStyle
        },
        last_name: {
          label: Languages.LastName,
          placeholder: Languages.TypeLastName,
          error: Languages.EmptyError,
          underlineColorAndroid: 'transparent',
          stylesheet: labelStyle
        },
        address_1: {
          label: Languages.Address,
          placeholder: Languages.TypeAddress,
          error: Languages.EmptyError,
          underlineColorAndroid: 'transparent',
          stylesheet: labelStyle
        },
        city: {
          label: Languages.City,
          placeholder: Languages.TypeCity,
          error: Languages.EmptyError,
          editable: false,
          underlineColorAndroid: 'transparent',
          stylesheet: labelStyle
        },
        state: {
          label: Languages.State,
          placeholder: Languages.TypeState,
          editable: false,
          error: Languages.EmptyError,
          underlineColorAndroid: 'transparent',
          stylesheet: labelStyle
        },
        postcode: {
          label: Languages.Postcode,
          placeholder: Languages.TypePostcode,
          error: Languages.EmptyError,
          underlineColorAndroid: 'transparent',
          stylesheet: labelStyle
        },
        country: {
          label: Languages.TypeCountry,
          nullOption: { value: '', text: Languages.Country },
          editable: false,
          error: Languages.NotSelectedError,
          styles: {
            borderColor: 'black',
            borderWidth: 1
          },
          stylesheet: labelStyle,
          underlineColorAndroid: 'transparent'
        },
        email: {
          label: Languages.Email,
          placeholder: Languages.TypeEmail,
          keyboardType: 'email-address',
          underlineColorAndroid: 'transparent',
          stylesheet: labelStyle
        },
        phone: {
          label: Languages.Phone,
          placeholder: Languages.TypePhone,
          keyboardType: 'phone-pad',
          underlineColorAndroid: 'transparent',
          stylesheet: labelStyle,
          returnKeyType: 'next'
        },
        note: {
          label: Languages.Note,
          placeholder: Languages.TypeNote,
          underlineColorAndroid: 'transparent',
          multiline: true,
          onFocus: () => this.inputFocused(),
          stylesheet: customStyle
        },
        suburb: {
          label: Languages.Suburb,
          placeholder: Languages.TypeSuburb,
          underlineColorAndroid: 'transparent',
          stylesheet: labelStyle
        }
      }
    }
  }

inputFocused() {
    this.refs.scrollView.scrollTo({ y: windowSize.height })
  }

render(){
return(
<View style={{flex:1}}>
  <ScrollView style={styles.form} ref="scrollView">
<Form ref="form" type={this.Customer} options={this.options} value={this.state.value} onChange={this.onChange.bind(this)} />
 </ScrollView >
</View>
)
}

Here is my screenshot: screen shot 2018-03-28 at 12 06 18 pm

harikanammi avatar Mar 28 '18 06:03 harikanammi

I used the react-native-keyboard-aware-scroll-view library to circumvent this issue. Just import the library and replace your scrollview with the KeyboardAwareScrollView component. Make sure to give it a flexGrow style of 1.

I hope this helps!

AustinKostelansky avatar Apr 02 '18 14:04 AustinKostelansky

react-native-keyboard-aware-scroll-view itself doesn't solve this issue If you are using expo : https://github.com/APSL/react-native-keyboard-aware-scroll-view/issues/2#issuecomment-321719250

else https://github.com/APSL/react-native-keyboard-aware-scroll-view/issues/2#issuecomment-213318096

abdifardin avatar Apr 10 '18 07:04 abdifardin

For those this is what my solution would be it works and scrolls automatically on focus input. I tried this on expo hope this helps.

<KeyboardAvoidingView style={{ flex: 1, flexDirection: 'column',justifyContent: 'center',}} behavior="padding" enabled   keyboardVerticalOffset={100}>
	<ScrollView>
		<View style={Styles.row}>
				//your view
		</View>
	</ScrollView>
</KeyboardAvoidingView>

abhiburk avatar Nov 14 '18 17:11 abhiburk

@abhiburk your solution worked for me

raheemazeezabiodun avatar Dec 13 '18 17:12 raheemazeezabiodun

@abhiburk you just saved my life man. Thanks a lot.

Zoha131 avatar Dec 13 '19 18:12 Zoha131

@abhiburk your solution works for me. Thanks Alot man!

kamilamin avatar Jan 18 '20 14:01 kamilamin

worked for me

butagreeza avatar Jan 28 '20 15:01 butagreeza

@abhiburk Thanks a lot man.

rajendrabhole avatar Apr 15 '20 07:04 rajendrabhole

@abhiburk can you share Styles.row please?

ChindrisSebilix avatar May 25 '20 20:05 ChindrisSebilix

@ChindrisSebilix Styles.row can be anything you define

for example

const styles = StyleSheet.create({ row: { flexDirection: 'row', alignItems: 'flex-start', backgroundColor: '#fff', justifyContent: 'center', }, });

depending on what you want..

butagreeza avatar May 25 '20 21:05 butagreeza