Adding a link to react-native checkbox value - react-native

I'm a brand new junior dev working on a react-native app for the first time. I have been searching for quite a while for a way to add a link to the text of a react-native checkbox's value text. If anyone has a link to documentation that might explain what I want to do, I would be super appreciative since I haven't found anything helpful yet. I saw that you can not add html elements into native after I tried a number of variations of anchors. I've tried adding Link to variations and attempted to add an onPress function to the label. I'm grasping at straws here... is this even possible to do?
To be clear, I want a user to be able to press the words "Terms of Service" and have it link to the page that has the terms
{this.props.isUser &&
<CheckBox
containerStyle={styles.checkbox}
onChange={(event, checked) => this.updateAttr('terms', checked)}
value={this.props.program.terms}
label="I have read and understand the Terms of Service"
labelLines={2}
/>
}

Instead of adding the "I accept...." as a label to checkbox, put the Check box without any label and the text 'I have read' as separate Text elements inside a view element and align them accordingly. Then inside the view, put the terms and conditions part inside a touchable and use React Native Linking to link the touchable to open a URL when touched.
https://facebook.github.io/react-native/docs/linking.html
React-Native Open Url in default web browser

Related

How to deal with react-native-multiple-select getSelectedItemsExt() function?

I'm building a react native application and found out the react-native-multiple-select library which i emplemented following the documentation https://www.npmjs.com/package/react-native-multiple-select . The view is being displayed but the selected items are not showing up, only the counter of selected items works. I think it's because I don't have the control over how its function getSelectedItemsExt() works and from my researchs on internet like React-native-multiple-select: Cannot read the property 'getSelectedItemsExt' of undefined I only found that I should be doing
<View>
{ this.multiselect
?
this.multiselect.getSelectedItemsExt()
:
null}
</View>
.
Though it helped get rid of the red screen, it doesn't display the items.
So can you please tell me how I can manage
this.multiselect.getSelectedItemsExt()
and get my items displayed.
Any help is much appreciated. Thanks in advance.
I can guess throughout the question that you are passing the hideTags props to the MultiSelect component i.e you are having inside the component <MultiSelect hideTags>. This hideTags was your problem because It does what it's name sounds, i.e it doesn't display the values you set in your FlatList or whatever component. If you want the values to be displayed then remove hideTags from inside the component and you should have your items displayed. Well you want also to customize the output of this library, it's colors and InputField style then head up to the root of your react native application, then go to node-module -> react-native-multiple-select -> Library there you will find the core file that you can customize at your leisure.

Quora-like expandable component in React Native

I'm trying to build a React Native app and would like to implement a component just like in Quora where upon clicking the question, the component expands and shows the remaining details (text/images of the question).
I tried using react-native-panel from https://github.com/dwicao/react-native-panel#readme, but it can only handle text in the panel before expanding. I'd like to implement a panel that has an image in it even before I press on the panel to expand. Would love it if anyone could refer me to any npm packages that use components to achieve this. Thank you!
Use this tutorial https://blog.theodo.com/2020/06/build-accordion-list-react-native/. Stick the desired image somewhere there in the code.

When should we use `accessibilityRole` in React Native?

Is this correct? I'm afraid it will read the word 'switch' twice to the user.
<Switch
accessible={true}
accessibilityLabel="Switch button"
accessibilityHint="Double tap to toggle setting"
accessibilityRole="switch"
/>
Many thanks in advance.
A couple notes on accessibility here:
As of 0.60, all interactive React Native components are accessible by default. (accessible=true)
Beware when using the accessible parameter. It will bundle any child elements into one accessible component and a screen reader will not allow users to select individual components when true. (You may need to override the default behavior because of this.)
Particularly with labels, remember to use full punctuation, or you may create unintended and overwhelming run-on sentences.
For UX, your label should read the purpose of the switch in a concise manner. Reading it without context, I have no idea what this toggle would actually do.
To answer your question:
You are correct that this setup would read out "switch button" twice, followed by the hint.
I tested the <Switch> component on an iPad just now with VoiceOver. By default, it is accessible and reads with a role of "button". Giving it a parameter of accessibilityRole='switch' reads with a role of "switch button" and automatically includes the "Double tap to toggle setting." hint.
The following component will read to the user as, "Airplane mode. switch button ... Double tap to toggle setting."
<Switch
accessibilityLabel="Airplane mode."
accessibilityRole="switch"
/>
accessibilityRole communicates the purpose of a component to the user of assistive technology.
For more information please find the below in official documentation
https://reactnative.dev/docs/accessibility#accessibilityrole-android-ios

React Native TextInput with editable=true and dataDetectorTypes

I'm trying to create a TextInput component that is both editable and has clickable urls. According to the react native docs, the dataDetectorTypes prop is only supported when editable={false}.
Determines the types of data converted to clickable URLs in the text input. Only valid if multiline={true} and editable={false}.
Has anyone found a way around this limitation? It seems like it should be possible. The behavior I want is...
Tapping on the url should open it in a browser
Tapping anywhere else should start editing at that position
It's ok if the link is no longer clickable when the TextInput currently has focus
The only thing I can think of to get around this is to store the editable value in state and then upon clicking some Edit button will change the state from editable to true.
onBlur would switch this state back to false
I haven't tried this before though so just a suggestion on attempting workarounds or finding some middle ground between the two.
My suggestion is to place the input field with the url centered inside a bigger div.
Make the input field not much bigger the text inside it and when you click it trigger some function that redirects to the page on your state.
And when you click on the outer div you trigger a function to focus on the input field and edit its value.

iOS10 Safari Keyboard Popup

I have a single page web app. The keyboard pops-up everytime I click on the screen.
There are no text input boxes in the DOM at all.
How can I debug why the keyboard is popping up.
You can see examples of this strange behaviour at https://blight.ironhelmet.com and https://np.ironhelmet.com
update with a clue: A user is now reporting that rather than the keyboard, a dropdown selection spiner is popping up all the time, long after that dropdown has been removed from the DOM.
For React users:
I had the same thing happen in a React single-page app with React-Router. I didn't write code to remove elements from the DOM, but of course React does that for you.
On my site, there are React components that contain one to four input fields. After any such component appears, and then is hidden (unmounted / not rendered anymore), then any time the user taps a link, the keyboard pops up. This makes the site unusable. The only way to make it stop was to reload the page.
The workaround: calling document.activeElement.blur() in componentWillUnmount for the wrapper component around my <input> fields did the trick.
componentWillUnmount()
{
if (document && document.activeElement)
{
document.activeElement.blur();
}
}
Note that calling window.activeElement.blur() did not seem to do anything.
There's a thread in the Apple support forums about this issue:
https://discussions.apple.com/thread/7692319
Looks like the keyboard was holding a reference to input after I had removed them from the DOM.
I added a test when removing element to see if it was the current activeElement, then, if so, calling document.activeElement.blur() before removing it. Seems to have solved the problem so far.