I have a react native project (react native for macOS) I am using the input component but notice there is a blue outline. Not sure how to remove it. I am using Native base input component which I am told it's using the react native input component. How can I remove the ugly blue outline when focus. I am mainly trying to remove the one that is square
import React from 'react';
import {Icon, Input} from 'native-base';
import Ionicons from 'react-native-vector-icons/Ionicons';
const SearchBar = () => {
return (
<Input
variant="rounded"
size="xs"
// w={{
// base: '75%',
// md: '25%',
// }}
InputLeftElement={
<Icon
as={<Ionicons name="ios-search" />}
size={5}
ml="2"
color="muted.400"
/>
}
placeholder="Search"
/>
);
};
export default SearchBar;
When using a React native TextInput component the css styling outline: "none" can be used to remove the outline on focus. This can be done by passing it directly into the style prop.
<View style={styles.body}>
<TextInput
style={{ outline: "none" }}
placeholder="Text"
onChangeText={(newText) => setText(newText)}
value={text}
/>
</View>
);
}
However since you are using a custom component you will need to make sure that the styles are passed to the component.
Related
I am new to React Native and i am having trouble with the following error message:
text string must be rendered within a <Text> component
This is my component:
import React from "react";
import { Text, StyleSheet, View, Button } from "react-native";
const HomeScreen = () => {
return (
<View>
<Text style={styles.text}>Hey!</Text>
<Button title='Go components demo'/>
</View>
);
};
const styles = StyleSheet.create({
text: {
fontSize: 30,
},
});
export default HomeScreen;
My strings are wrapped within a Text component and the error message persists. Any typo am i not seeing or doing anything wrong?
Your error is likely somewhere else in your app. one way to test this is to comment out the component inside of your App component or wherever your Homescreen component is being called. It's more likely that wherever you're mounting HomeScreen, there is extraneous text. Perhaps something you missed when deleting the boilerplate code.
Give some width and height to your view ,or try give a flex of 1 :
Hope it helps.
<View style = {{flex:1}}>
<Text style={styles.text}>Hey!</Text>
<Button title='Go components demo'/>
</View>
or
<View style = {{width:'100%',height:'100%'}}>
<Text style={styles.text}>Hey!</Text>
<Button title='Go components demo'/>
</View>
I am using "react-native-paper": "^4.12.5" & "react-native": "0.70.4"
I want to transform the layout on the left to the one on the right using react-native-paper. But I have found a problem. I don't know how to center the input, and the placeholder of a TextInput. I would also like to hide the cursor.
I have tried to inject "textAlign" using the style prop of the paper component, but it does not seem to work, and the native props of paper do not allow this transformation.
Do you know how I can adapt the paper component, or do you think I have to design my own?
import * as React from 'react';
import {StyleSheet} from 'react-native';
import {TextInput} from 'react-native-paper';
import {useTheme} from 'react-native-paper';
type textInputProps = {
placeholder: string;
style: object;
};
const CustomInput = ({placeholder, style}: textInputProps) => {
const {colors} = useTheme();
return (
<TextInput
mode="outlined"
placeholder={placeholder}
outlineColor={colors.border}
style={(styles.custom, style)} // Here is the error!
// style={[styles.custom, style]} This is how to do it
theme={{roundness: 30}}
/>
);
};
const styles = StyleSheet.create({
custom: {
textAlign: 'center',
},
});
export default CustomInput;
----- Edit -----
As pointed out by Vu and Nitin, it is perfectly possible to style a paper TextInput to center the cursor using the style prop and the textAlign property. My error was in the way I was passing the style prop, not the style itself.
Syntax error found: style={(styles.custom, style)}
textAlign still work.
Change to: style={[styles.custom, style]} or style={{...styles.custom, ...style}} to resolve.
Firstly to get TextInput and its placeholder to centre you have to modify your TextInput style:
//remove () bracket and style from style
<TextInput
mode="outlined"
placeholder={placeholder}
outlineColor={colors.border}
style={styles.custom}
theme={{roundness: 30}}
/>
or you can directly add inLine style
<TextInput
mode="outlined"
placeholder={placeholder}
outlineColor={colors.border}
style={{
textAlign: 'center'
}}
Second, to hide the cursor from textInput
you have to add to TextInput
caretHidden={true}
which will look like:
<TextInput
mode="outlined"
placeholder={placeholder}
outlineColor={colors.border}
style={styles.custom}
theme={{roundness: 30}}
caretHidden={true}
/>
This is how you will achieve you desired results
maybe you can use this code on your style css
textAlignHorizontal : 'right'
I am having a very peculiar issue with React Native Elements Text Input along with using touchable opacity.
import React, { useState } from 'react';
import { TouchableOpacity, View, Dimensions } from 'react-native';
import { Input } from 'react-native-elements';
const test = () => (
<TouchableOpacity onPress={() => console.log('we hit here')}>
<Input disabled>
{children}
</Input>
</TouchableOpacity>
)
export default test;
So the outer rim of the input field is completely clickable, however, the center of the component, it cannot be clicked.
This works perfectly for android however.
Any ideas
if anyone has this issue, then the you need to supply a pointerEvents to 'none' for the entire component to be clickable:
<View pointerEvents='none'>
<Input disabled>
{children}
</Input>
</View>
Mubeen hussain answer is correct, but to be more precise it's like this
<TouchableOpacity onPress={() => console.log('we hit here')}>
<View pointerEvents="none">
<Input disabled>{children}</Input>
</View>
</TouchableOpacity>
I'm using react-native-paper and I want to get an Icon component but without any link with Button Component. I went through the doc and I didn't found an Icon Component. I want something similar than react-native-elements one
import { Icon } from 'react-native-elements'
<Icon
name='g-translate'
color='#00aced' />
So please help me to achieve this.
you can use "react-native-vector-icons" library because the icon in react-native-paper is from react-native-vector-icons.
here is code:
import Icon from 'react-native-vector-icons/FontAwesome';
const myIcon = <Icon name="rocket" size={30} color="#900" />;
You can use Avtar.Icon. By default, it has some margin around the icon. You can create your own component by modifying the Avtar.Icon. Here is an example:
const iconSize = 34
const customAvtardimension = 0.6 * iconSize
<Avatar.Icon
size={iconSize}
icon="bell-ring-outline"
color={Colors.redA700}
style={{
backgroundColor: Colors.transparent,
width: customAvtardimension,
height: customAvtardimension,
}}
/>
I was following React Native basic tutorial. Then after it ended, I tried to add a button in the code used in TextInput tutorial, following example in Button page
import React, { Component } from 'react';
import { AppRegistry, Text, TextInput, Button, View } from 'react-native';
class AwsumProjek extends Component {
constructor(props) {
super(props);
this.state = {tiText: ''};
}
render() {
return (
<View style={{padding: 10}}>
<TextInput
style={{height: 40}}
placeholder="Type here to translate!"
onChangeText={(tiText) => this.setState({tiText})}
/>
<Text style={{padding: 10, fontSize: 42}}>
{this.state.tiText.split(' ').map((word) => word && 'WA').join(' ')}
</Text>
<Button
title="Press Purple"
color="#841584"
accessibilityLabel="Learn more about purple"
/>
</View>
);
}
}
AppRegistry.registerComponent('AwsumProjek', () => AwsumProjek);
Instead I got this error
Element type is invalid: expected a string (for built-in components)
or a class/function (for composite components) but got: undefined.
Check the render method of 'AwsumProjek'.
What did I do wrong? Seeing other answer, is it something related to importing something?
I'm native android developer trying to learn React Native, and as me now, Javascript is totally unfamiliar for me.
Make sure you are using correct version of React Native. Button component was introduced in React Native version 0.37