React Native TranslateX to Edge of Screen - react-native

I need some help determining how to use React Native's Animated view to perform a translateX to move the view to the left edge of the screen.
Currently, I have been able to translateX with a random number (-50) and the view will move, but I'm unsure how to correctly calculate the distance to move so that the element is right against the left side of the screen.
Ideas?

If the view you want to move is full width view you can use Dimensions API to get window width and translateX the amount of width.

I was actually able to solve this by creating another View component in front of the component I'm trying to move. Then using onLayout of the view to get its width, and finally -translateX using the width of the "hidden" View component.

Related

React Native SafeAreaView horizontal-only

Is it possible to use the react native SafeAreaView (react-native-safe-area-context) only horizontally (or remove the generated top padding)? When using it e.g. in a modal that slides from the bottom, the iPhone X spacing is added on the top although it's actually far away from the screen top. It should only add the necessary spacings to the left and right in landscape.
Does using the edges prop work for you?
<SafeAreaView edges={['left', 'right']} />
You can add bottom to the above array if you want it removed from the top only.

React Native pushing component in and out of screen dynamically

As shown in the attached gif, the navigation bar at the bottom and the URL bar at the top are pushed in and out(not just show/hide at once) of view as user scrolls. How can I achieve this 'hiding' effect in React Native? The key point is that the hiding speed of the component should correspond to the scrolling speed.
I have tried giving negative values to the top and bottom, like so:
style={{bottom:dynamicallyChangingScrolledValue()}}
although it does push the view out of the screen, space where the component used to remain in the blank, occupied.
Are they using animations here? or changing some offset value dynamically by incrementing a small amount?

Getting visible area of Image in React Native ScrollView

I have a scrollView with a single Image in it. Initially the Image has the same width & heigth as the ScrollView.
I am trying to crop this image based on how the user have zoomed and moved the image. Basically, I want to know what part of the image is visible, so that I can crop it accordingly.
Im using expo's ImageManipulator to crop it, so I have that part covered. But to get the dimensions of what part of the Image is visible after zoom/drag is whats bugging me.
Much appreciated!
The logic here is to first fill the Image component inside the size of the ScrollView. This way, the size of the image will be equal to the size of the ScrollView.
First, you need to set directionalLockEnabled prop to false and horizontal prop to true to make the ScrollView scroll horizontally.
Then, set maximumZoomScale and minimumZoomScale props to make your ScrollView zoomable. Now, every time you zoom and scroll in your ScrollView it will fire onMomentumScrollEnd and onScrollEndDrag with the event parameter from which you can get the visible part of your ScrollView which is usually,
event.nativeEvent.contentOffset
event.nativeEvent.contentSize
event.nativeEvent.layoutMeasurement
Since your Image Component size is same as that of the ScrollView Component, it will give you the exact visible area of the image in the ScrollView.
For Detailed implementation example, you can refer to this file of the react-native-community/react-native-image-editor repository

How to get the width of a Text component BEFORE it is rendered

I am trying to create a text slider that moves from right to left over certain period of time. A problem is that I need it to come from outside the display and appear as it moves slowly to the left side. So I cannot use onLayout event as it would briefly appear in the display before it is animated.
How do I calculate the width of text component before it is rendered on the screen in react native?
may be try UIManager.measure?
https://gist.github.com/johanneslumpe/e48acd0a820bb322790b

React Native Putting Fixed Component on top of Flatlist

As shown above, I want to create this two-part screen where I can click onto both the A component and B component on the first view provided here. When a user scrolls B component, it may take up the entire screen and move over the A component. (A component does not move with the FlatList).
I'm new to react native and was wondering how I could create such behavior? I tried using absolute positioning and ListHeaderComponent inside the FlatList but didn't really get anywhere. Let me know if anyone has an idea.
Thanks!
I would try something like the following screen structure:
View
Image
ScrollView w/ trans background that goes to the top of screen
FlatList with top padding to push it below the image
Items in list
/FlatList
/ScrollView
/View
You could also see if react-native-parallax-scroll-view works for you as it looks somewhat similar to what you describe
https://github.com/jaysoo/react-native-parallax-scroll-view