我想在 React Native 中创建网格中心菜单,我刚刚阅读了文档并且看起来不错,但是我在为每个网格菜单创建行时遇到了问题
我已经使用复制粘贴代码创建了 3x3 网格 flexbox:
<View style={{
flexDirection: 'row',
flex: 1,
justifyContent: 'center',
alignItems: 'center',
}}>
<View>
<View style={{width: DeviceWidth*0.2, height: DeviceWidth*0.2, marginBottom:10, marginLeft:10, backgroundColor: 'powderblue'}} />
<View style={{width: DeviceWidth*0.2, height: DeviceWidth*0.2, marginBottom:10, marginLeft:10, backgroundColor: 'skyblue'}} />
<View style={{width: DeviceWidth*0.2, height: DeviceWidth*0.2, marginBottom:10, marginLeft:10, backgroundColor: 'steelblue'}} />
</View>
<View>
<View style={{width: DeviceWidth*0.2, height: DeviceWidth*0.2, marginBottom:10, marginLeft:10, backgroundColor: 'powderblue'}} />
<View style={{width: DeviceWidth*0.2, height: DeviceWidth*0.2, marginBottom:10, marginLeft:10, backgroundColor: 'skyblue'}} />
<View style={{width: DeviceWidth*0.2, height: DeviceWidth*0.2, marginBottom:10, …
Run Code Online (Sandbox Code Playgroud) 我试图在Android上运行我的React Native,从其余API获取数据时一切看起来都不错,
但是我不知道为什么当我想将数据发送到REST API时,控制台日志告诉我
W/unknown:InspectorPackagerConnection: Couldn't connect to packager, will silently retry
这是我尝试过的代码:
try {
console.log(Constants.APILink + `DoAudit/PostCompleteAuditSchedulev1`, header + `token`)
axios.post(Constants.APILink + `DoAudit/PostCompleteAuditSchedulev1`, header, {
headers: {
"Accept": "application/json",
"Content-Type": "application/json",
"Authorization": "Bearer " + Queries.getPersistentData('token')
}
})
// NEVER RUN TO THIS STATEMENT OR SHOWING ME AN ERROR IN LOGCAT
.then(res => {
if (res.data == 0) {
console.log("Upload success HEADER");
var path = '/storage/emulated/0/Documents' + '/testx.txt';
RNFS.writeFile(path, JSON.stringify(mediaListFinding + auditid), 'ascii')
.then((success) => {
console.log('FILE WRITTEN!');
let …
Run Code Online (Sandbox Code Playgroud) 我有一个在 React Native 中使用文本输入的搜索功能,但是搜索需要调用一个 API,所以我想onChangeText
在用户完成输入 2 秒后保持运行,
我试过使用setInterval
,setTimeout
但这些都不起作用,
这是我试过的代码:
<TextInput
placeholder="search"
onChangeText={(text) => {
setTimeout(() => {
console.log(text)
console.log("Kepanggil TimeOUTNYAA")
params.onSearchText(text)
}, 2000);
}
}
//function onSearchText
onSearchText(searchText){
this.setState({text:searchText},()=>{
this._loadMore() // here's a function to call the API
})
}
Run Code Online (Sandbox Code Playgroud)
实际行为:
当我键入am
在TextInput
日志显示我:
预期行为:
我希望日志只 显示我am
不 a
和am
有可能做到吗?
I want to know why i can use this.props
directly but i can't use this.props
from string into function
.
the error is:
undefined is not an object (evaluating 'this.props.navigation')
here a sample code i've tried:
state={
stringToFn="this.props.navigation.navigate(\'otherscreen\')",
stringToFn2="alert(\'otherscreen\')"
}
renderThis(){
let nyobaFunc = new Function("return " + "()=>{"+this.state.stringToFn+"}")();
return(
<TouchableOpacity onPress={nyobaFunc} style={styles.flatListButton}>
<CustomText style={styles.flatListSubTitle}>{'HitMe!'}</CustomText>
</TouchableOpacity>
)
}
render(){
return(
{this.renderThis()}
)
}
Run Code Online (Sandbox Code Playgroud)
but if i put stringToFn
value into onPress
directly or if i change this.state.stringToFn
to this.state.stringToFn2
in …
我是 React Native 的新手,当我阅读有关Alert组件的内容时,我看到了有关alert
方法static alert(title, message?, buttons?, options?, type?)
facebook 给出的例子:
Alert.alert(
//Title
'Alert Title',
//Message
'My Alert Msg',
//Button
[
{text: 'Ask me later', onPress: () => console.log('Ask me later pressed')},
{text: 'Cancel', onPress: () => console.log('Cancel Pressed'), style: 'cancel'},
{text: 'OK', onPress: () => console.log('OK Pressed')},
],
//Options
{ cancelable: false }
)
Run Code Online (Sandbox Code Playgroud)
并且没有关于做什么的例子type
,有人可以告诉我这些是什么type
?
有没有办法显示Alert
没有Title
?
假设我有这样的代码
var a, b;
b = 1;
var c = b > 0 ? a = 1 /*and c = 2*/ : a = 0 /*and c = 1*/;
console.log(a + c);
Run Code Online (Sandbox Code Playgroud)
有没有办法制作c = 2
和a = 1
使用上面的代码?
我刚刚开始学习flutter,我很好奇如何setState()
动态地在flutter中
我React Native
通常使用这样的函数来setState
动态地:
class foo extends React.Component{
state={
username:null,
password:null
}
toggleSetState(whatState, value){
this.setState({ [whatState]: value })
}
render() {
return (
<View>
<TextInput
value={this.state.username}
onChangeText={(text)=>{toggleSetState(username, text)}
/>
<TextInput
value={this.state.password}
onChangeText={(text)=>{toggleSetState(password, text)}
/>
</View>
);
}
}
Run Code Online (Sandbox Code Playgroud)
与上面的代码等效的是什么Flutter
?
我已经尝试过,Flutter
但似乎不起作用
class _LoginFormState extends State<LoginForm> {
String username, password;
void ToogleState(typedata, text){
setState(() {
typedata = text;
});
}
//Widget
TextField(
onChanged: (text){ToogleState(username, text); print(username);},
decoration: InputDecoration(
hintText: 'input username', labelText: 'Username' …
Run Code Online (Sandbox Code Playgroud) 我有一个AppBar
输入main.dart
,我想将它定义为它的孩子的主要内容,但是AppBar
当我在孩子的页面上时,我想更改它自己的标题,我该如何正确地做到这一点?
void main() => runApp(MyApp());
class MyApp extends StatelessWidget{
@override
Widget build(BuildContext context) {
return MaterialApp(
title: "Flutter App",
theme: ThemeData(
primaryColor: Colors.cyan,
brightness: Brightness.dark
),
home: Scaffold(
appBar: AppBar(
title: Text("Main Dart"),
),
body: HomeScreen(),
),
routes: <String, WidgetBuilder>{
'/homeScreen': (buildContext)=>HomeScreen(),
'/second': (buildContext)=>Second()
},
);
}
}
//HomeScreen or Second Widget on different dart file
class HomeScreen extends StatelessWidget {
@override
Widget build(BuildContext context) {
//here I want to change the title …
Run Code Online (Sandbox Code Playgroud) 参考react native padding top doc
paddingTop 的工作方式类似于 CSS 中的 padding-top。有关更多详细信息,请参阅https://developer.mozilla.org/en-US/docs/Web/CSS/padding-top。
在css 链接上,padding-top 有一些百分比,但它在本机反应中不起作用,
如何在 paddingTop 反应原生中添加百分比?
react-native ×7
javascript ×4
dart ×2
flutter ×2
alert ×1
appbar ×1
css ×1
ecmascript-6 ×1
grid-layout ×1
if-statement ×1
image ×1
reactjs ×1
textinput ×1
whatsapp ×1