- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我创建了一个通用按钮,我希望它具有圆形边缘而不是方形。我的按钮组件是这样的:
const Button = ({ onPress, children }) => {
const { buttonStyle, textStyle } = styles;
return (
<TouchableOpacity onPress={onPress} style={buttonStyle}>
<Text style={textStyle}>
{children}
</Text>
</TouchableOpacity>
);
};
const styles = {
textStyle: {
alignSelf: 'center',
color: colors.primaryTeal,
fontSize: 16,
fontWeight: '600',
paddingTop: 10,
paddingBottom: 10,
},
buttonStyle: {
flex: 1,
backgroundColor: colors.whiteText,
marginLeft: 5,
marginRight: 5,
borderRadius: 50
}
};
borderRadius
根本。
<Button onPress={this.onButtonPress.bind(this)}>
Log in
</Button>
render() {
return (
<Card>
<CardSection>
<Input
placeholder="user@gmail.com"
label="Email"
value={this.state.email}
onChangeText={email => this.setState({ email })}
/>
</CardSection>
<CardSection>
<Input
secureTextEntry
placeholder="password"
label="Password"
value={this.state.password}
onChangeText={password => this.setState({ password })}
/>
</CardSection>
<View style={styles.btnWrapper}>
<CardSection>
{this.state.loading ?
<Spinner size="small" /> :
<Button onPress={this.onButtonPress.bind(this)}>
Log in
</Button>}
</CardSection>
</View>
<Text style={styles.errorTextStyle} disabled={this.state.error !== null}>
{this.state.error}
</Text>
</Card>
const CardSection = (props) => {
return (
<View style={styles.containerStyle}>
{props.children}
</View>
);
};
const styles = {
containerStyle: {
borderBottomWidth: 1,
padding: 5,
backgroundColor: '#fff',
justifyContent: 'flex-start',
flexDirection: 'row',
borderColor: '#ddd',
position: 'relative'
}
};
最佳答案
工作得很好。只要确保使用 react native 的 StyleSheet.create
获取缓存的样式。
也许您的按钮容器 View 背景是白色的,而您没有看到圆角。
这是我的工作 snack
我使用的代码片段,但请引用小吃,因为您会看到它在运行中。
import React, { Component } from 'react';
import { Text, View, StyleSheet, TouchableOpacity } from 'react-native';
const Button = ({ onPress, children }) => {
return (
<TouchableOpacity onPress={onPress} style={styles.buttonStyle}>
<Text style={styles.textStyle}>
{children}
</Text>
</TouchableOpacity>
);
};
export default class App extends Component {
render() {
return (
<View style={styles.container}>
<Button>
Log in
</Button>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex:1,
backgroundColor: 'black',
},
textStyle: {
alignSelf: 'center',
color: 'teal',
fontSize: 16,
fontWeight: '600',
paddingTop: 10,
paddingBottom: 10,
},
buttonStyle: {
flex: 1,
backgroundColor: 'white',
marginLeft: 5,
marginRight: 5,
borderRadius: 50
},
});
关于React-native TouchableOpacity 按钮不尊重边界/边界半径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47677454/
即使此文档 ( https://facebook.github.io/react-native/docs/gesture-responder-system.html ) 指出,触摸事件会传递给子级并且
我目前正在尝试在 TouchableOpacity 中设置图像。它没有显示,我坚持为什么会这样。如果你能帮忙,请告诉我。 TIA! 我基本上复制了这个:https://facebook.github.
Actions.portfoy()}> %{this.state.ana
Actions.portfoy()}> %{this.state.ana
(仅限iOS)如果在内部,则不响应: 它可以在模拟器中正常运行,但不能在真实设备中运行 keyboardShouldPersistTaps="always"没有任何区别 部分代码: this._on
我有以下组件 { console.log("Hello World }}> Hello World 然后我想将此组件包装在一个 HoC 中,它将 WrappedComponent 包装在一个
我正在制作约会应用程序,我在某一天有 6 个时间段。组件加载后,选定的插槽将存储到名为“notAvailableSlots”的常量中。如果“notAvailableSlots”中有相应的值,这意味着有
我正在使用 TouchableOpacity在我学习 react-native 时制作一个按钮。 但问题是,TouchableOpacity占据屏幕的 100% 宽度。但是,我想利用其中存在的组件来调
我试图调用一个在单击 onPress 时使用 props 传递的函数。下面是我的自定义组件。 DrawerItem.js import React from 'react'; import { V
在我的应用程序中,我有一行文本,同一行的副手是一个开关。单击开关会更改其值,但我希望整行都可以单击并更改其值。 我使用 TouchableOpacity 结束了这段代码: {this.setStat
我关注了这篇文章- React Native flex-box align icon and text制作一个标题如下的按钮: Work { this.setState(previ
我有一个应用程序,我想在其中将图像列表显示为网格,列表中的第一个元素是“添加”按钮。我还需要每个图像都是可触摸的。目前我的代码如下所示: class RNtest extends Component
如何在侧边菜单中实现到其他页面的 Activity 链接? 我正在使用这个例子https://github.com/react-native-fellowship/react-native-side-
我在 React Native 中有一个带有 onPress 事件的按钮。 我想要全类同学都这样 这是我的代码: Sign In wit
我有一个登录按钮,我想在按钮的中心放置一个登录文本,并在按钮的右边缘放置一个图像(适当缩放),远离文本。 目前我通过以下方式使用 Vector Icons 库中的图标: L
我正在制作一个 React Native 应用程序,其中有 2 个按钮/TouchableOpacity。在设置这些按钮的样式时,即使在各自的样式表中明确声明“纯色”边框样式,它们也会获得双边框。 (
我正在尝试在 TouchableOpacity 组件内设置一个水平的 ScrollView(出于必要的原因)。然而,TouchableOpacity 会覆盖任何水平滚动功能并执行 onPress,即使
我试图在纯文本旁边附上一些可触摸不透明度,但是,两个可触摸之间的纯文本与可触摸文本不一致。请指导如何解决这个问题。 By clicking Sign up, you agree to Company'
我正在关注 this教程并陷入动态 TouchableOpacity元素。出于某种原因,没有应用 flex 属性。当我使用 chrome 的开发工具查看元素时,我可以看到它们,但它们没有 flex 属
我创建了一个通用按钮,我希望它具有圆形边缘而不是方形。我的按钮组件是这样的: const Button = ({ onPress, children }) => { const { buttonS
我是一名优秀的程序员,十分优秀!