react-native-keyboard-aware-scroll-view icon indicating copy to clipboard operation
react-native-keyboard-aware-scroll-view copied to clipboard

Doesn't work on Android

Open outaTiME opened this issue 9 years ago • 14 comments

Hi guys, im running on Expo and doesn't work on android (running the last version of expo with react native 49), here the code:

import React, { Component } from 'react';
import {
  StyleSheet,
  Text,
  TextInput,
} from 'react-native';
import { KeyboardAwareScrollView } from 'react-native-keyboard-aware-scroll-view'

export default class App extends Component {
  render() {
    return (
        <KeyboardAwareScrollView enableOnAndroid>
          <TextInput style={styles.textInput} placeholder={'First Name'} ref={(r) => { this._firstNameTI = r; }} returnKeyType={'next'}
                     underlineColorAndroid="transparent" onSubmitEditing={(event) => this._lastNameTI.focus()}/>
          <TextInput style={styles.textInput} placeholder={'Last Name'} ref={(r) => { this._lastNameTI = r; }} returnKeyType={'next'}
                     underlineColorAndroid="transparent" onSubmitEditing={(event) => this._countryTI.focus()}/>
          <TextInput style={styles.textInput} placeholder={'Country'} ref={(r) => { this._countryTI = r; }} returnKeyType={'next'}
                     underlineColorAndroid="transparent" onSubmitEditing={(event) => this._stateTI.focus()}/>
          <TextInput style={styles.textInput} placeholder={'State'} ref={(r) => { this._stateTI = r; }} returnKeyType={'next'}
                     underlineColorAndroid="transparent" onSubmitEditing={(event) => this._addrTI.focus()}/>
          <TextInput style={styles.textInput} placeholder={'Address'} ref={(r) => { this._addrTI = r; }} returnKeyType={'next'}
                     underlineColorAndroid="transparent" onSubmitEditing={(event) => this._emailTI.focus()}/>
          <TextInput style={styles.textInput} keyboardType="email-address" placeholder={'Email'} ref={(r) => { this._emailTI = r; }}
                     underlineColorAndroid="transparent" returnKeyType={'next'} onSubmitEditing={(event) => this._msgTI.focus()}/>
          <TextInput style={styles.textInput} placeholder={'Message'} ref={(r) => { this._msgTI = r; }} returnKeyType={'next'}
                     underlineColorAndroid="transparent" onSubmitEditing={(event) => this._notesTI.focus()}/>
          <TextInput style={styles.textInput} placeholder={'Notes'} ref={(r) => { this._notesTI = r; }} returnKeyType={'go'}
                     underlineColorAndroid="transparent"  />
        </KeyboardAwareScrollView>
    );
  }
}

const styles = StyleSheet.create({
  mainTitle: {
    fontSize: 20,
    marginTop: 10,
    textAlign: 'center'
  },
  textInput: {
    height: 60,
    borderColor: 'gray',
    borderWidth: 1,
    marginBottom: 16,
    // paddingVertical: 4,
    // paddingHorizontal: 8,
  },
});

screen recording 2017-11-08 at 06 58 pm

Thanks !!!

outaTiME avatar Nov 08 '17 21:11 outaTiME

Android Support may not work with Expo. Check #190

To use Android Support you need to set windowSoftInputMode to adjustPan which you can't do on Expo projects.

Swordsman-Inaction avatar Nov 09 '17 09:11 Swordsman-Inaction

Yup @Swordsman-Inaction you are right expo apps use windowSoftInputMode with adjustResize any plan to support alternative way that works with adjustResize?

https://github.com/expo/expo/blob/master/exponent-view-template/android/app/src/main/AndroidManifest.xml#L14

outaTiME avatar Nov 09 '17 14:11 outaTiME

@outaTiME Sorry, currently I'm don't have much time to work on this. But you are welcome to send a PR.

Swordsman-Inaction avatar Nov 10 '17 07:11 Swordsman-Inaction

@outaTiME i found the same problem... @Swordsman-Inaction thanks for the info :) Expo confirmed indeed that it's adjustResize. One suggestion might be to update the docs of this repo so it's a bit clearer that the actual setting for windowSoftInputMode is adjustPan? And also potentially that it currently can't be used with Expo?

I'd gladly take a look at making a PR. any pointers on where to look first?

lucastobrazil avatar Nov 10 '17 21:11 lucastobrazil

@outaTiME have you tried adding extraScrollHeight={100}? I'm using both android and expo and it works fine for me like this <KeyboardAwareScrollView extraScrollHeight={100} enableOnAndroid={true} keyboardShouldPersistTaps='handled'>

Spoof14 avatar Nov 17 '17 13:11 Spoof14

Not working on XT890 (Kitkat) - Tested in Genymotion. Just IOS works. Expo* "sdkVersion": "26.0.0"

<KeyboardAwareScrollView
// resetScrollToCoords={{ x: 0, y: 0 }}
contentContainerStyle={styles.contentContainerStyler}
// scrollEnabled={true}
extraScrollHeight={100}
enableOnAndroid={true}
keyboardShouldPersistTaps="handled">

MichelDiz avatar Apr 06 '18 21:04 MichelDiz

@MichelDiz might be a problem with your styles sheet. Can you try sharing that too?

Spoof14 avatar Apr 09 '18 09:04 Spoof14

I think it's far more likely that the problem is in react-native-onboarding-swiper. I'm using it to create a simple form in steps. But the interesting thing is that all "KeyboardAware" I tested worked on IOS. Only on Android that does not work.

MichelDiz avatar Apr 09 '18 13:04 MichelDiz

Please, read the thread. Android support comes from windowSoftInputMode, it's not the same behaviour as iOS.

alvaromb avatar Apr 09 '18 13:04 alvaromb

Well, even the Expo "Keyboard Aware" worked on Android. So, my problem must be something with react-native-onboarding-swiper.

MichelDiz avatar Apr 09 '18 13:04 MichelDiz

@Spoof14 I've been dealing with this issue for HOURS, thank you so much!

JesseAReyes1996 avatar Apr 23 '19 08:04 JesseAReyes1996

It doesn't work for components that have position: 'absolute' in their style, better prepare the UI with relative positioning.

pythonsmerchant avatar Apr 24 '19 15:04 pythonsmerchant

Unable to make any events. Getting offset error in android emulator. Any solution for this?

nihp avatar Nov 04 '19 12:11 nihp

for me I was facing this issue on Android (react-native 0.62.2). iOS was working perfectly. I found that adjustResize flag in Android manifest was the culprit. I removed it and it started working

Before

android:windowSoftInputMode="stateAlwaysHidden|adjustPan|adjustResize"

After

android:windowSoftInputMode="stateAlwaysHidden|adjustPan"

Warning

I don't know what side effects it will cause in future.

maulikdhameliya avatar May 12 '20 12:05 maulikdhameliya