Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Android support? #2

Closed
cmmouritsen opened this issue Nov 11, 2015 · 53 comments
Closed

Android support? #2

cmmouritsen opened this issue Nov 11, 2015 · 53 comments
Milestone

Comments

@cmmouritsen
Copy link

Should this work for Android? I was having an issue with a view in iOS and Android and I put this component in place. It seemed to fix the iOS version, but the Android version still behaves the same (the keyboard covers the content in the ScrollView).

@alvaromb
Copy link
Collaborator

Hello @cmmouritsen!

Yes, it should work for Android as long as the keyboard events are registered but I think that those events are not yet supported: facebook/react-native#3468

Have you tried to use KeyboardDidShow and KeyboardDidHide?

@cmmouritsen
Copy link
Author

Just changing the events to keyboardDidShow and keyboardDidHide didn't seem
to fix it. I'll have to dig into it a little more when I have some more
time to spend on it.

On Thu, Nov 12, 2015 at 6:28 AM Álvaro Medina Ballester <
notifications@github.com> wrote:

Hello @cmmouritsen https://github.com/cmmouritsen!

Yes, it should work for Android as long as the keyboard events are
registered but I think that those events are not yet supported:
facebook/react-native#3468
facebook/react-native#3468

Have you tried to use KeyboardDidShow and KeyboardDidHide?


Reply to this email directly or view it on GitHub
#2 (comment)
.

@alvaromb
Copy link
Collaborator

Ok, I would really like to have a PR for Android support.

Let me know if I can help you :)

@jblack10101
Copy link

I've started trying to add Android support: https://github.com/jblack10101/react-native-keyboard-aware-scroll-view. Android doesn't have handy events like keyboardDidShow and keyboardDidHide, so I'm extending the native ReactScrollView and checking if the keyboard is displayed in the onMeasure event.

I'm running into an issue where it says that "ScrollView can host only one direct child", but in my test project, I have only one direct child View of KeyboardAwareScrollView, e.g.:

<KeyboardAwareScrollView 
  style={ styles.container }
  contentContainerStyle={ styles.contentContainer }
  keyboardShouldPersistTaps={ true }
  keyboardDismissMode={ "on-drag" }>
  <View ref="wrapper" style={{ padding: 5 }}>
    <Text>Test</Text>
    <TextInput />
  </View>
</KeyboardAwareScrollView>

I'm using React Native 0.19.1 and here's the stack trace:

E/unknown:React﹕ Exception in native call from JS
    java.lang.IllegalStateException: ScrollView can host only one direct child
            at android.widget.ScrollView.addView(ScrollView.java:257)
            at com.facebook.react.uimanager.ViewGroupManager.addView(ViewGroupManager.java:36)
            at com.facebook.react.uimanager.NativeViewHierarchyManager.manageChildren(NativeViewHierarchyManager.java:366)
            at com.facebook.react.uimanager.UIViewOperationQueue$ManageChildrenOperation.execute(UIViewOperationQueue.java:174)
            at com.facebook.react.uimanager.UIViewOperationQueue$2.run(UIViewOperationQueue.java:673)
            at com.facebook.react.uimanager.UIViewOperationQueue$DispatchUIFrameCallback.doFrameGuarded(UIViewOperationQueue.java:723)
            at com.facebook.react.uimanager.GuardedChoreographerFrameCallback.doFrame(GuardedChoreographerFrameCallback.java:32)
            at com.facebook.react.uimanager.ReactChoreographer$ReactChoreographerDispatcher.doFrame(ReactChoreographer.java:120)
            at android.view.Choreographer$CallbackRecord.run(Choreographer.java:790)
            at android.view.Choreographer.doCallbacks(Choreographer.java:596)
            at android.view.Choreographer.doFrame(Choreographer.java:556)
            at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:778)
            at android.os.Handler.handleCallback(Handler.java:739)
            at android.os.Handler.dispatchMessage(Handler.java:95)
            at android.os.Looper.loop(Looper.java:155)
            at android.app.ActivityThread.main(ActivityThread.java:5696)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1028)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:823)

I'm posting this here in hopes that someone may have an idea, but I will continue to look into it.

@alvaromb
Copy link
Collaborator

alvaromb commented Feb 2, 2016

Hi @jblack10101! Which React Native version are you testing on? Under 0.19 I do get a resized scroll view in Android.

@jblack10101
Copy link

Hey @alvaromb, I'm getting this exception with react-native node version 0.19.0 and in Java, com.facebook.react:react-native:0.19.0 and 0.19.1. Which versions are you using?

@alvaromb
Copy link
Collaborator

alvaromb commented Feb 5, 2016

I'm using 0.19, it's strange! Are you sure you're using only one child? ScrollView can host only one direct child

@jblack10101
Copy link

Yea, I pulled the latest react-native from master last night and built using it. I added some log statements, and even though I have a View as the only child of the KeyboardAwareScrollView, it looks like it is adding the Text and TextInput elements as direct children of the ScrollView and ignoring the View. I'll continue investigating.

@alvaromb
Copy link
Collaborator

alvaromb commented Feb 5, 2016

That could be RN making some optimisations for you, IDK. Here https://github.com/APSL/react-native-keyboard-aware-scroll-view/blob/master/lib/KeyboardAwareScrollView.js#L25 you can see that this component just uses what you provide as children. Try to set some style into your container View, or set backgroundColor's to each of your views, it's useful to debug UI issues.

@karthickvkumar
Copy link

@jblack10101 How to register the react-native-keyboard-aware-scroll-view module in MainActivity.java for React Native 0.21

@jblack10101
Copy link

@karthickvkumar, sorry I've been on vacation and unable to respond, but the readme should have all of the information that you need to register the module. Please let me know if you have further questions.

@nickmaxwell10
Copy link

nickmaxwell10 commented Apr 22, 2016

This helped me the most - ptomasroos/react-native-tab-navigator#48

For Android, it is a good idea to read up on android:windowSoftInputMode when dealing with the keyboard. Docs - http://developer.android.com/guide/topics/manifest/activity-element.html

I struggled for a while getting a chat-style (sticky) keyboard bar along with the react-native-keyboard-aware-scroll-view module (version 0.0.6).

As soon as I changed windowSoftInputMode in my main AndroidManifest.xml, it worked!

<-- AndroidManifest.xml -->
<activity
        android:name=".MainActivity"
        android:label="@string/app_name"
        android:windowSoftInputMode="stateUnspecified|adjustResize">

Also make sure you are subscribing to keyboardDidShow and keyboardDidHide on Android, for now (React Native 0.23.0).

@burgalon
Copy link

I'm using RN 0.24 and it seems like NativeModules.ScrollViewManager is not available on Android.
Getting ReactNativeJS: undefined is not an object (evaluating 'ScrollViewManager.getContentSize')

@anthonywebb
Copy link

It appears there is a pull request for android functionality (#4) but I have not heard if it actually works or not? I assume if it worked it would have been merged by now as android support seems like a nice addition.

@iSimonWeb
Copy link

👍 up

@alvaromb
Copy link
Collaborator

alvaromb commented Jun 1, 2016

It's on the list @iSimonWeb, sorry for the delay :(

@alvaromb alvaromb added this to the 0.2.0 milestone Jun 1, 2016
@shukerullah
Copy link

+1

@abhishiv
Copy link

Just curious, why is it needed? Plain ScrollView works fine for me on android out of the box with android:configChanges="keyboard|keyboardHidden|orientation|screenSize" in my AndroidManifest.

@alvaromb
Copy link
Collaborator

I think there are some older Android versions that do not automatically scroll to the input fields @abhishiv. I've been very busy and I didn't had time yet to bring full Android support.

@lesniakania
Copy link

I have react-native 0.37.0 and react-native-keyboard-aware-scroll-view 0.2.6, basic scrolling functionality works for me, but neither extraScrollHeight nor extraHeight works for me.
Work on iOS version, though.

@brianinator
Copy link

brianinator commented Mar 8, 2017

I have the same issue as @lesniakania +1 about the extra space on Android. Should that be in another ticket?

@lesniakania
Copy link

ping @alvaromb ;]

@serranoarevalo
Copy link

@lesniakania How did you get the basic scrolling functionality to work? Mine just wont.

@lesniakania
Copy link

I just used README code, it just worked for me. What phone/android version you test on?

@alvaromb
Copy link
Collaborator

alvaromb commented Mar 9, 2017

Hi all!

I can't figure out what's the issue. Can you describe? :)

@lesniakania
Copy link

For me the issue is that I want to use extraScrollHeight and it does not work for me on Android.
I'm using it because I have buttons below input and I want to make them visible when the keyboard is present. I set extraScrollHeight to the buttons' height and it works for me on iOS but not on Android.

@alvaromb
Copy link
Collaborator

alvaromb commented Mar 9, 2017

Ok @lesniakania!

Let me check, we have several projects where we're using it in Android.

@lesniakania
Copy link

Awesome, thanks :)

@alvaromb
Copy link
Collaborator

alvaromb commented Mar 9, 2017

I just reproduced the issue @lesniakania.

Can you create a separate issue and we'll track it there? Thanks!

@lesniakania
Copy link

Sure: #107
Thanks for quick feedback!

@alexprice1
Copy link

Has anyone been able to get this to work with Exponent?

@serranoarevalo
Copy link

@alexprice91 Take a look at KeyboardAvoidingView, it might work for you. I was also trying to make it work with Expo but I had no luck with it. KeyboardAvoidingView did the trick in both iOS and Android.

@alexprice1
Copy link

This does the trick. Thanks!!

@OwenFlood
Copy link

Has android support been added? It's working fine on ios, but on android nothing happens when the keyboard is opened. 😕

@Swordsman-Inaction
Copy link
Collaborator

@OwenFlood I'll start the work after facebook/react-native#13129 is been merged.

@ms88privat
Copy link

@Swordsman-Inaction 🎉

@Palisand
Copy link

Palisand commented Jun 29, 2017

+1 Currently have to switch to RN's KeyboardAvoidingView on Android devices, but I still prefer this component over its equivalent in core. I can basically pop in KeyboardAwareScrollView it and it just works, while with KeyboardAvoidingView I have to set style, behavior, and a vertical offset.

@alvaromb
Copy link
Collaborator

Folks, keep in mind that in Android you can use softInputMode to handle the keyboard. Thanks to @Swordsman-Inaction, we'll have the resizing support with Android too, but for most cases softInputMode will be the best option.

@Swordsman-Inaction
Copy link
Collaborator

softInputMode is good enough for most cases, you guys can just use it.
For Android support, my PR is merged, but somehow it's not in 0.45, it's in master branch right now. I'll start working on it after 0.46(hopefully it will have my change) comes out.

@chirag04
Copy link

@Swordsman-Inaction did you get a chance to work on it? 46 is out now.

@Swordsman-Inaction
Copy link
Collaborator

@chirag04 I'm already working on it. 😀

@graphee-gabriel
Copy link

Hello, I'm new to react-native and exponent (but know pretty well android and ios native dev)
I can get it to work on Android, though it works perfect on iOS.
Am I missing something special to do for Android when using this lib with Expo?

@Palisand
Copy link

@graphee-gabriel Check out https://github.com/Palisand/kasv-expo. It's far from perfect, but it should help out.

@alvaromb
Copy link
Collaborator

@Palisand I don't know anything about expo, but do you want to stick a link to your lib in the docs? What's the difference between using this library with expo and yours?

@graphee-gabriel
Copy link

Hmmmm @alvaromb I tried your code, but it did not change anything, still no scrolling on android.

@alvaromb
Copy link
Collaborator

Ping @Swordsman-Inaction, who made the Android implementation.

@Swordsman-Inaction
Copy link
Collaborator

@graphee-gabriel Could you share more information? Which version? Code snippet? It's better to open an issue.

@rxb
Copy link

rxb commented Aug 11, 2017

For anyone looking for this scrolling behavior on Expo, you have to set the status bar to any solid color in app.json

"androidStatusBar": {
    "backgroundColor": "#eeeeee",
},

Not sure why, but it works.

@kazixma
Copy link

kazixma commented Aug 16, 2017

@rxb I work too , but Now I can use KeyboardAvoidingView and ScrollView together when I set
"androidStatusBar": { "backgroundColor": "#eeeeee", },

Thank

@davidroman0O
Copy link

@rxb Damn, thx you so much, i almost had a heart attack...

@graphee-gabriel
Copy link

graphee-gabriel commented Sep 14, 2017

The status bar thing did not work for me but i found a workaround making a component for it.
I use the Facebook KeyboardAvoidingView on android with behavior padding and a weird keyboardVerticalOffset at -1000, it was the only way to make it work on my android phone.

Just use this component and replace KeyboardAwareScrollView by KeyboardAwareScrollViewCompat

EDIT: well it does work perfectly on this app, but i tried copying this component to another app that had the same problem, implemented it, and it does not work on the other app... This is really confusing, they have the same app.json settings etc... slightly frustrating :-)

import React from 'react'
import { Platform, KeyboardAvoidingView, ScrollView } from 'react-native'
import { KeyboardAwareScrollView } from 'react-native-keyboard-aware-scroll-view'


export default class KeyboardAwareScrollViewCompat extends React.Component {

  render() {
    if (Platform.OS === 'ios') {
      return (
        <KeyboardAwareScrollView {...this.props}>
          {this.props.children}
        </KeyboardAwareScrollView>
      )
    }

     return (
       <KeyboardAvoidingView {...this.props} behavior="padding" keyboardVerticalOffset={-1000}>
         <ScrollView>
           {this.props.children}
         </ScrollView>
       </KeyboardAvoidingView>
     )
  }
}

@himelnagrana
Copy link

@graphee-gabriel that worked and solved my 3 months long keyboard toggle problem (where I have tried lots of hacks previously). Thanks.

@KellyHannemann
Copy link

adding enableOnAndroid worked for me without having to use the statusbar trick
<KeyboardAwareScrollView style={{flexGrow: 1}} enableOnAndroid>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests