In bottom half modal, transparent background also sliding along with modal in animationType = "slide" (React Native) - react-native

I implemented a bottom half modal view in react native, which is sliding in from the bottom . I set the background of the modal view to transparent so the previous view is still visible, but the modal view is in focus. This is working fine and once it is open it also looks how I want it to look. My problem is, that the transparent background is also sliding in from the background and this does not look like a native implementation at all. What I want to achieve is, that the transparent background just appears while the modal view slides in from the bottom. Any idea on how to solve this?
Note: Iam using Modal from inbuilt react native, hence not using any npm module or package.
My code:
import { View, Text, Modal } from 'react-native';
function DurationModal(props) {
<View>
<Modal
visible={props.isVisible}
transparent
animationType='slide'
statusBarTranslucent
>
<View>
<View style={{ backgroundColor: 'rgba(0,0,0,0.1)', height: hp('60%') }}></View>
<View style={{ backgroundColor: Colors.whiteBackgroundColor, height: hp('40%') }}>
<Text>Hello</Text>
</View>
</View>
</Modal>
</View>
);
}

Related

How do I make an absolut positioned touchable element on top of a FlatList catch only press events and let other events propagate to the FlatList?

I have a FlatList in React Native with fullscreen image and video items (with pagingEnabled). I want to have a short descriptive touchable text floating on top of the FlatList, to open up a view with some information about the image/video when pressed.
To make the user experience nice, I'd like to be able to scroll the FlatList through the touchable text as well. I.e. if the user happen to start their scrolling motion on top of the text, the FlatList would scroll but if it is a simple press event I'd like to open the view with details about the image/video.
No mater what I try I end up with either the text being able to react to the press OR the FlatList being able to scroll. I have tried different configurations with a custom PanResponder and pointerEvents but seem to always end up with a state were one thing does not work. Do you guys have any smart ideas? I am probably just stuck in the wrong train of thought.
This is a simplified view of my component structure:
<View>
<View style={{ position: 'absolute', bottom: 100, zIndex: 10 }}>
<TouchableOpacity onPress={() => console.log('press')}>
<Text>Some Descriptive Text</Text>
</TouchableOpacity>
</View>
<FlatList pagingEnabled horizontal {...otherFlatListProps} />
</View>

Keyboard and layout handling with React Native

I've been trying to figure out how to properly handle layout changes after keyboard opens up (At least on Android). I'm using latest Expo.
Example of my form:
<View style={{flex: 1}}>
<View style={{flex: 1}}></View>
<View style={{flex: 2}}>
<TextInput></TextInput>
<TextInput></TextInput>
<TextInput></TextInput>
<TextInput></TextInput>
<Button></Button>
</View>
</View>
The problem is, when i click on any TextInput, the keyboard squishes everything thats above it and it becomes unreachable until i close the keyboard.I've already tried using:
KeyboardAvoidingView + ScrollView inside
"softwareKeyboardLayoutMode": "pan" in app.json
KeyboardAwareScrollView - seems to be working, kinda, problem below
I also have a problem with "pan" setting, screen adjusts weirdly in a way that it will squish top elements when i click on a bottom TextInput, but wont when i click on a top TextInput, which breaks KeyboardAwareScrollView i guess (It adds different padding/height to the bottom of a screen depending on where i click to open a keyboard)
Does anybody have a better solution to this problem? I want it to simply enable scroll on view (add height ?) without squishing flexboxes or changing anything in my layout.
It's really tough to manage multiple inputs with help of the keyboard avoiding view from React Native Library.
To find the workaround for this, and fix the issues with the Multiple Inputs and Keyboard management in iOS, I have used an npm dependency known as react-native-keyboard-aware-scrollview
Which really helped me in achieving my goal.
You can also try the npm dependency, I hope it will surely help you in achieving your desired outcome.
Here I am attaching the HOC component, Using which I wrap my components in which I need to manage the input and keyboard avoiding.
HOC Component :
import * as React from "react"
import { View, TouchableWithoutFeedback, Keyboard } from "react-native"
import SafeAreaView from 'react-native-safe-area-view'
import { KeyboardAwareScrollView } from "react-native-keyboard-aware-scroll-view"
/**
* Root component for screen managing safe area view and keyboard avoiding view
*/
const Root = (props) => {
const { style, children } = props
return (
<SafeAreaView style={{ flex: 1, backgroundColor: 'white' }}>
<KeyboardAwareScrollView
keyboardShouldPersistTaps={'always'}
contentContainerStyle={{
flexGrow: 1 // this will fix scrollview scroll issue by passing parent view width and height to it
}}
>
<TouchableWithoutFeedback
onPress={Keyboard.dismiss}
style={{ flexGrow: 1 }}
>
<View style={{ flexGrow: 1 }}>
{children}
</View>
</TouchableWithoutFeedback>
</KeyboardAwareScrollView>
</SafeAreaView>
)
}
export default Root
Simply wrap it with ScrollView, as seen below.
<ScrollView>
<View style={{flex: 1}}>
<View style={{flex: 1}}></View>
<View style={{flex: 2}}>
<TextInput></TextInput>
<TextInput></TextInput>
<TextInput></TextInput>
<TextInput></TextInput>
<Button></Button>
</View>
</View>
</ScrollView>

React Native: Fix TextInput at the bottom of the screen with a ScrollView

I need to fix the input in the bottom of the screen, so that keyboard pushes this input (similar to instagram comments).
Here's an example():
https://snack.expo.io/LPRwoGpik
It's working fine, but if I put the FlatList inside the ScrollView the bottom input is dissapearing.
What's the right way to solve this problem?
try this
<View style={{flex: 1,}} >
<ScrollView>
{content}
</ScrollView>
<TextInput style={{position: "absolute", bottom :0}}/>
</View>

React Native Soft Keyboard Issue

I have TextInput at the bottom of the screen. When TextInput is focused then keyboard appears and due to this all the flex view gets shrink to the available screen. I want to achieve that page layout should not change and input should be visible to user.
<View style={MainView}>
<View style={subMain1}>
<View style={{flex:1,backgroundColor:'#add264'}}></View>
<View style={{flex:1,backgroundColor:'#b7d778'}}></View>
<View style={{flex:1,backgroundColor:'#c2dd8b'}}></View>
</View>
<View style={subMain2}>
<View style={{flex:1,backgroundColor:'#cce39f'}}></View>
<View style={{flex:1,backgroundColor:'#d6e9b3'}}></View>
<View style={{flex:1,backgroundColor:'#69ee9a'}}>
<TextInput placeholder="input field"/>
</View>
</View>
</View>
const Styles = {
MainView:{
flex:1,
backgroundColor:'green'
},
subMain1:{
flex:1,
backgroundColor:'blue'
},
subMain2:{
flex:1,
backgroundColor:'orange'
}
}
I just found an answer to this.
I just have to use fixed height for my main container and inside that I can use flex layout. And If keyboard is hiding the content then we can use Scrollview that will allow scrollable interface when user clicks on input.
This helped me hope it can help others. :)
I'm not quite sure I understand what the issue you're running into, but I recently struggled with keyboard avoiding views in my app - for some reason, the native component just wasn't working.
Check this package out - it did the trick for me, and offers some cool customization capabilities:
https://github.com/APSL/react-native-keyboard-aware-scroll-view
Use 'react-native-keyboard-aware-scroll-view' and keep this as parent view and put all view inside that view. This node module creates scrollview and it listens to keyboard show event and automatically scrolls your screen so user can see the input box without getting it hidden behind the soft keyboard.

How to show hidden view with translateX in React Native

Here is the code:
<View
style={{transform: [{translateX: this.state.translateX}], width: '120%'}}>
<View style={{width: '20%'}}>{someText}</View>
<View style={{width: '80%'}}>{someText}</View>
<View style={{width: '20%'}}>{someText}</View>
</View>
this.state.translateX was respond to swipe gesture which worked fine, the first two View did move but the last View was not visible (or not moved?). I want to show the last View when this.state.translateX changed. But it seems not being properly rendered?
It is because Android does not render element which is off screen. Solution is place the element in screen with position: 'absolute' and then use translateX to hide it from screen.