我正在尝试在React Native中的卡片顶部显示一张卡片,并设置zIndex = 1
为顶部卡片和zIndex = 0
底部卡片,并将它们放置在如下视图中:
<View style={{paddingVertical: MARGIN_1, justifyContent: 'center'}}>
{this.props.subscribed ? (
<CardSubscribe
style={{zIndex: 2}}
/>
) : (null)}
{this._renderTextItems()}
</View>
Run Code Online (Sandbox Code Playgroud)
但是,两张牌之间没有重叠.底卡从顶卡开始:
我也尝试使用检查器进行调试,它显示顶部卡具有以下属性zIndex = 1
:
底卡具有以下属性zIndex = 0
:
我也尝试将顶部卡放在底部卡之后,但它只是显示在底部卡的下方,就像zIndex
没有做任何事情一样.我该怎么解决这个问题?
我有一个TextInput
用backgroundColor
的'rgba(255,255,255,0.16)'
,如下:
小吃示例:https://snack.expo.io/rkEhXn6Nr
import * as React from 'react';
import { TextInput, View, StyleSheet } from 'react-native';
export default class App extends React.Component {
render() {
return (
<View style={styles.container}>
<TextInput
style={styles.paragraph}
value={"bleep bleep bleep bleep"}
/>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
backgroundColor: 'green',
},
paragraph: {
padding: 24,
margin: 24,
fontSize: 24,
textAlign: 'center',
backgroundColor: 'rgba(255,255,255,0.16)',
},
});
Run Code Online (Sandbox Code Playgroud)
看起来好像有一个具有该背景色的视图(THERE IS N'T)和一个文本元素,其内部也包裹了该背景色。我怎样才能只有“视图”才能具有该背景色?在android上看起来还不错:
当我尝试使用okhttp进行HTTP调用时,我收到以下错误:
W/System.err: java.io.EOFException: source exhausted prematurely
W/System.err: at okio.InflaterSource.read(InflaterSource.java:83)
W/System.err: at okio.GzipSource.read(GzipSource.java:80)
W/System.err: at okio.Buffer.writeAll(Buffer.java:1135)
W/System.err: at okio.RealBufferedSource.readString(RealBufferedSource.java:199)
W/System.err: at okhttp3.ResponseBody.string(ResponseBody.java:176)
W/System.err: at com.ethanwang.andplay.OKHttpTaskTag.doInBackground(OKHttpTaskTag.java:41)
W/System.err: at com.ethanwang.andplay.OKHttpTaskTag.doInBackground(OKHttpTaskTag.java:20)
W/System.err: at android.os.AsyncTask$2.call(AsyncTask.java:295)
W/System.err: at java.util.concurrent.FutureTask.run(FutureTask.java:237)
W/System.err: at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:234)
W/System.err: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
W/System.err: at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
W/System.err: at java.lang.Thread.run(Thread.java:818)
Run Code Online (Sandbox Code Playgroud)
我只能找到这个相关的问题:https://github.com/square/okhttp/issues/2193但我确保这Content-Length
是响应正文的正确长度.这是我记录的okhttp请求和响应:
请求:
I/System.out: INFO: Sending request http://test.essaybot.com/msg/tag_search on Connection{test.essaybot.com:80, proxy=DIRECT@ hostAddress=test.essaybot.com/34.208.145.50:80 cipherSuite=none protocol=http/1.1}
I/System.out: Content-Type: application/x-www-form-urlencoded
I/System.out: Content-Length: 33
I/System.out: Host: test.essaybot.com
I/System.out: Connection: Keep-Alive
I/System.out: Accept-Encoding: gzip
I/System.out: …
Run Code Online (Sandbox Code Playgroud) 我试图在react native fetch API中更改用户代理:
const URLENCODED_HEADER = {
'Accept': 'application/json',
'Content-Type': 'application/json',
'User-Agent': Platform.OS + "/" + DeviceInfo.getUniqueID().toString()
}
export async function doRegister(secureInfo) {
formBody = encodeParameters(secureInfo)
try {
let response = await fetch(SERVER_URL+'/user/register', {
method: "POST",
headers: URLENCODED_HEADER,
body: formBody,
credentials: 'include'
});
let responseJson = await response.json();
return responseJson;
} catch(error) {
console.error(error);
throw error;
}
}
Run Code Online (Sandbox Code Playgroud)
它显示了我想要的正确信息.
但是,在服务器端,ua
仍然是android和ios设备的默认设置:
Mozilla/5.0 (iPad; CPU OS 11_2_6 like Mac OS X) AppleWebKit/604.5.6 (KHTML, like Gecko) Version/11.0 Mobile/15D100 Safari/604.1 …
我有一个简单的代码TextInput
,我希望它在首次渲染和提交时得到关注。但是,它根本没有得到关注。
render() {
return (
<TextInput
ref={(c) => this._input = c}
style={[styles.item, this.props.style]}
placeholder={"New Skill"}
onChangeText={(text) => {
this.setState({text})
}}
onSubmitEditing={(event) => {
this.props.onSubmitEditing(this.state.text);
this._input.clear();
this._input.focus();
}}
/>
);
}
componentDidMount() {
this._input.focus();
}
Run Code Online (Sandbox Code Playgroud) 我想在 React Native iOS 项目的发布版本中看到一些 console.log。我四处搜索,但没有找到任何东西,我也不熟悉 xcode。有谁知道如何做到这一点?
标题完美居中,左侧同一行中有一个返回按钮。
我尝试使用右侧justifyContent: 'space-between'
的空白View
,但标题将偏右一些。我应该如何处理?
我的renderHeader
功能:
_renderHeader = () => {
return (
<View style={styles.headerAbsolute}>
<View style={styles.bar}>
<ButtonBack
text={"Resumes"}
onPress={() => this._onNavBackHandler()}
/>
{true ? (
<Text style={styles.headingFixed}>{this.state.title}</Text>
) : ( null )}
<View/>
</View>
</View>
)
}
Run Code Online (Sandbox Code Playgroud)
这些是样式:
bar: {
height: 55,
flexDirection: "row",
alignItems: 'flex-end',
justifyContent: 'space-between',
paddingHorizontal: 10,
paddingBottom: 5,
},
headingFixed: {
fontSize: TITLE_TERTIARY,
fontWeight: 'bold',
color: COLOR_DARK_SECONDARY,
backgroundColor: 'transparent',
},
Run Code Online (Sandbox Code Playgroud) 我试图为列表中的第一项和最后一项设置不同的样式,如下图所示:
第一张卡的右上角为圆角,而最后一张卡的右下角为圆角。我仍在想办法。
有什么方法可以将列表中某个项目的位置传递给该项目本身,以便可以将其应用于其他样式?还是还有其他更好的方法?
另外,如果只有一张卡,我希望该卡的右上角和下角均为圆形,如下所示:
我遵循了此React Native灵活框后对齐图标和文本,以创建一个标题如下的按钮:
<View style={styles.sectionHeaderContainer}>
<Text style={styles.heading}>Work</Text>
<TouchableOpacity
style = {{width: 40, flex: 1, flexDirection: 'row', justifyContent: 'center', alignItems: 'center'}}
onPress={() => {
this.setState(previousState => {
Alert.alert('You tapped the button!')
});
}}>
<Image source={addIcon}/>
<Text style={styles.tertirayTitleDark}>Add Work</Text>
</TouchableOpacity>
</View>
Run Code Online (Sandbox Code Playgroud)
样式表如下:
sectionHeaderContainer: {
flexDirection: 'row',
justifyContent: 'space-between',
alignItems: 'flex-end',
paddingHorizontal: "6%",
paddingTop: "12%",
},
heading: {
fontSize: TITLE,
fontWeight: 'bold',
color: THEME_COLOR,
backgroundColor:'transparent',
},
tertirayTitleDark: {
fontSize: CONTENT_LARGE,
fontWeight: 'bold',
color: COLOR_DARK_PRIMARY,
},
Run Code Online (Sandbox Code Playgroud)
但是,该按钮占用了标题剩余的所有可用水平空间:
我尝试了许多不同的设置,但仍然无法弄清楚我在做什么错。