I have a React Native View
containing a Text
field, and I'm using the onLayout prop to do some positional calculations which rely on the data it provides.
<View onLayout={this.calculateDimensions}>
<Text>{this.props.content}</Text>
</View>
This works well, but there is a scenario where the content
prop updates to a different string with the same character size. This results in the layout not changing and onLayout
not triggering.
These positional calculations must occur each time the content
prop updates.
Note: I am aware there are numerous ways to make the component update. Updating is not the same as laying out and sadly does not trigger onLayout
.
Currently, React-Native doesn't provide a way, to out-of-the-box, traverse the view tree and get the first focusable element to set the focus for it. So you need to use AccessibilityInfo. setAccessibilityFocus passing a reactTag case by case.
You have have to use position:'absolute' and put the circle element as the last element of the elements list so it comes to top (no need to use zIndex). also the container div must have styles for child elements to be centered.
react-native-on-layout is an npm package that you can include in your app using npm i react-native-on-layout or with yarn add react-native-on-layout . It is a View component that will do this onLayout dance for you and then passes the layout values as parameters to a render prop.
The equivalent of the document. getElementById() method in React is using refs. To select an element, set the ref prop on it to the return value of calling the useRef() hook and access the dom element using the current property on the ref , e.g. ref. current .
You can have a unique key based on the content. whenever a key attribute of a component changes it is forcing a re-render.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With