简体   繁体   English

如何在 React Native 中实现想要的 UI

[英]How to achieve the desired UI in react native

I am trying to acheive a styling as shown in the image attached below我正在尝试实现如下图所示的样式在此处输入图像描述

See how here the fingerprint icon happens to be inside the border of the Textinput field but instead I am getting the output as shown below看看这里的指纹图标是如何恰好在 Textinput 字段的边框内,但我得到的是 output,如下所示

在此处输入图像描述

PS:- ignore the left and right side black color borders it happens to be the simulator body just focus on the UI. PS:-忽略左右两侧的黑色边框,它恰好是模拟器主体,只关注用户界面。

Here's my code:-这是我的代码:-

import { View, Text, TextInput, StyleSheet } from 'react-native'
import React from 'react'
import  Icon  from 'react-native-vector-icons/MaterialCommunityIcons'

const TestAtom = () => {
  return (
   <View style={styles.searchSection}>
    
    <TextInput style={styles.input} placeholder='User' onChangeText={(searchString) => {this.setState({searchString})}}
        underlineColorAndroid="transparent"/> 
         <Icon style={styles.searchIcon} name='fingerprint' size={20} color= '#000' />
   </View>
  )
}

const styles = StyleSheet.create({
    searchSection: {
        flex: 1,
        flexDirection: 'row',
        justifyContent: 'center',
        alignItems: 'center',
        backgroundColor: '#fff',
    },
    searchIcon: {
        // padding: 10
        paddingRight: 10
    },
    input: {
        flex: 1,
        paddingTop: 10,
        paddingRight: 10,
        paddingBottom: 10,
        paddingLeft: 0,
        backgroundColor: '#fff',
        color: '#424242',
        borderBottomColor: '#000',
        borderBottomWidth: 1
    }
});

export default TestAtom

Can anyone help me with it.任何人都可以帮助我。

You should make a View and place the Text Input and Fingerprint icon inside.您应该制作一个视图并将文本输入和指纹图标放入其中。

A small example of how it will look like.它的外观的一个小例子。

<View style={{
 borderWidth:1,
 flex:1,
 flexDirection:'row',
 alignItems:'center'
}}>
  <TextInput/>
  <FingerIcon/>
</View>

Have the Textinput and the fingerprint icon as two components in the same view styled as flex-direction:row.将 Textinput 和指纹图标作为同一视图中的两个组件,样式设置为 flex-direction:row。 Have the bottom ruler part as a separate item which draws under the View of Textinput and the Icon.将底部标尺部分作为单独的项目绘制在 Textinput 视图和图标下。

在此处输入图像描述

import { View, StyleSheet,SafeAreaView,TextInput } from 'react-native'

import MaterialCommunityIcons from 'react-native-vector-icons/MaterialCommunityIcons';

function UIComponent(){

<View style={styles.container}>

<View style={styles.componentWrapper}>
  
  <View style={styles.passwordFieldWrapper}>
  <TextInput style={styles.textInput} placeholder='umana Password'>
  </TextInput>
  <MaterialCommunityIcons name="fingerprint" color='green' size={24} />
  </View>

  <View style={styles.bottomPart}>

  </View>
</View>    

</View>
}

export default UIComponent

const styles = StyleSheet.create({

container:{
 backgroundColor:'#ffffff',
 flex:1
},
componentWrapper:{
 alignItems:'center',
 justifyContent:'center'
},
passwordFieldWrapper:{
 flexDirection:'row'
},
textInput:{
 width:'50%'
},
bottomPart:{
 marginTop:3,
 borderBottomColor:'gray',
 borderBottomWidth:1,
 width:'60%'
}


})

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM