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

Keyboard automatically closes when a textinput is focused inside the modal #58

Closed
karanpratapsingh opened this issue Aug 25, 2019 · 12 comments
Labels
🤕 Valid issue Something isn't working

Comments

@karanpratapsingh
Copy link

Issue:

Keyboard automatically closes after typing a single character on iOS (haven't tested android) when a text input inside the modal is focused

Modal:

<Modalize
                ref={this.modal}
                adjustToContentHeight
                keyboardAvoidingBehavior={'padding'}
                onClosed={this.onClosed}
                modalStyle={{ marginTop: 32 }}
                flatListProps={{
                    stickyHeaderIndices: [0],
                    ListHeaderComponent: () => this._listHeaderComponent(),
                    data: this.data,
                    renderItem: this.renderItem,
                    keyExtractor: item => item.email,
                    showsVerticalScrollIndicator: false,
                }}
            />
        );

ListHeader component:

_listHeaderComponent = () => (
        <View style={{flex: 1, justifyContent: 'center', height: 60, width: '100%', backgroundColor: 'salmon' }}>
            <TextInput
                style={{ fontSize: 20, backgroundColor: 'yellow' }}
                value={this.state.searchQuery}
                onChangeText={searchQuery => this.setState({ searchQuery })}
            />
        </View>
    );

EXPO SNACK: https://snack.expo.io/HkZULlxSB

@karanpratapsingh
Copy link
Author

@jeremybarbet It would be great if you could help me, Thanks

@jeremybarbet
Copy link
Owner

Hi!

Have you been able to figure it out? It's a known issue but I don't have time to work on it unfortunately.

@karanpratapsingh
Copy link
Author

Yes, to prevent this issue you need to render the list header using good ol' if-else logic 🤣

@jeremybarbet
Copy link
Owner

Definitely not ideal. I'll do my best to work on this when I have downtime!

@gamingumar
Copy link

Have you tried blurOnSubmit={false} in your TextInput?

@jeremybarbet
Copy link
Owner

It's because the ListHeaderComponent from the FlatList is being re-render each time you change the state. I'm not sure to see a quick solution to fix in this context of usage.

Even though if you have the possibility to use HeaderComponent instead I would recommend you do that: https://snack.expo.io/@jeremdsgn/modalize-issue

I'm closing this issue

@maartenvandillen
Copy link

This fixed it for me: callstack/react-native-paper#736 (comment)

I needed to change the header prop from a function to an element.

@AdarshJais
Copy link

Is this solved in a proper way?

@nharis7
Copy link

nharis7 commented Sep 1, 2020

If you use FlatList for rendering view without inputting data, you need to set removeClippedSubviews={true} or use the default option for optimizing rendering view. For your case (render with input) you should set removeClippedSubviews={false} to prevent the keyboard hide/show.

<FlatList .... removeClippedSubviews={false} ... />

@cerdonmez
Copy link

Thanks for the good explanation. It worked for me also.

@sanjaykochrekar
Copy link

If you use FlatList for rendering view without inputting data, you need to set removeClippedSubviews={true} or use the default option for optimizing rendering view. For your case (render with input) you should set removeClippedSubviews={false} to prevent the keyboard hide/show.

<FlatList .... removeClippedSubviews={false} ... />

it worked for me
Thanks

@sanjaykochrekar
Copy link

If you use FlatList for rendering view without inputting data, you need to set removeClippedSubviews={true} or use the default option for optimizing rendering view. For your case (render with input) you should set removeClippedSubviews={false} to prevent the keyboard hide/show.

<FlatList .... removeClippedSubviews={false} ... />

its working

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🤕 Valid issue Something isn't working
Projects
None yet
Development

No branches or pull requests

8 participants