I create Header
and Gifted Chat
in React Native
.
return (
<View style={{ flex: 1, backgroundColor: '#fff' }}>
<StatusBar
backgroundColor="#4A43EC"
barStyle="light-content"
/>
{/* Header */}
<KeyboardAvoidingView >
<View style={{ flexDirection: 'row', justifyContent: 'space-between', alignItems: 'center', width: '100%', paddingVertical: 16, backgroundColor: '#4A43EC',}}>
<View style={{ flexDirection: 'row', alignItems: 'center', marginLeft: 24, }}>
<TouchableOpacity
onPress={() => navigation.goBack()}>
<Image
style={{ height: 22, width: 22, marginRight: 13 }}
source={require("../Assets/Icons/EventDetailsLeftArrow.png")}
/>
</TouchableOpacity>
<Text style={{ color: '#fff', fontSize: 24, fontWeight: '400', }}>{item.name} Id: {item.id}</Text>
</View>
</View>
</KeyboardAvoidingView>
{/* Body */}
<View style={{ flex: 1 }}>
<GiftedChat
messages={messages}
onSend={messages => onSend(messages)}
user={{
_id: rid,
}}
alwaysShowSend
renderBubble={renderBubble}
// renderSend={renderSend}
/>
</View>
</View>
)
When I open `Keyboard` for typing, the `Header` hide.
I don't want this, I want that `header` always show while typing.
2
Answers
It behaves in this manner because your header is wrapped in KeyboardAvoidingView remove it and it will work normally.
Your chat component should be wrapped in KeyboardAvoidingView.
Take your
header
bar from thescrollview
and useKeyboardAwareScrollView
instead of KeyboardAvoidingViewKeyboardAwareScrollView handles both scroll and keyboard behavior. KeyboardAvoidingView should only be used on screens where the user shouldn’t scroll.
Example:
KeyboardAwareScrollView.js
import {
ImageBackground,
TextInput,
} from "react-native";
import React from "react";
import KeyboardAvoidingView from ‘./keyboardAvoidingView’
Usage