- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
很抱歉打扰您,但我正在努力学习 React-Native。我正在尝试制作一个天气应用程序,但出现此错误:
Text strings must be rendered within a <Text> component.
- node_modules\react-native\Libraries\Renderer\implementations\ReactNativeRenderer-dev.js:4137:8 in <anonymous>
- node_modules\react-native\Libraries\Renderer\implementations\ReactNativeRenderer-dev.js:4134:2 in createTextInstance
- ... 9 more stack frames from framework internal
这是我的两个代码文件:
天气卡.js
import React, {Component} from "react";
import {Animated, View, Text, PanResponder, Image} from "react-native";
import {
widthPercentageToDP as wp,
heightPercentageToDP as hp
} from "react-native-responsive-screen";
const CARD_INITIAL_POSITION_Y = hp("80%");
const CARD_INITIAL_POSITION_X = wp("5%");
const TRESHOLD_TO_TOP = hp("75%");
const TRESHOLD_TO_BOTTOM = hp("70%");
const CARD_OPEN_POSITION = hp("45%");
const MAX_DRAG_ZONE_WHEN_OPEN = hp("65%");
const ICON_URL = "http://openweathermap.org/img/w/";
class WeatherCard extends Component {
state = { panResponder : undefined, isOpen: false};
componentDidMount() {
this.position = new Animated.ValueXY();
this.position.setValue({x:CARD_INITIAL_POSITION_X, y: CARD_INITIAL_POSITION_Y});
const panResponder = PanResponder.create({
onStartShouldSetPanResponder:() => true,
onPanResponderMove:(e,gesture) => {
if(!(this.state.isOpen && gesture.y0 > MAX_DRAG_ZONE_WHEN_OPEN)) {
this.position.setValue({
x:CARD_INITIAL_POSITION_X,
y: gesture.moveY
});
}
},
onPanResponderRelease:(e, gesture) => {
if (!this.state.isOpen){
if(gesture.moveY <= TRESHOLD_TO_TOP) {
this.setOpenPosition(() => this.setState({isOpen: true}));
} else {
this.resetPosition();
}
} else {
if(gesture.moveY <= TRESHOLD_TO_BOTTOM){
this.setOpenPosition()
} else {
if(gesture.y0 < MAX_DRAG_ZONE_WHEN_OPEN){
this.resetPosition(() => this.setState({isOpen: false}))
}
}
}
}
});
this.setState({panResponder})
}
setOpenPosition = (done) => {
Animated.spring(this.position, {
toValue: {x: CARD_INITIAL_POSITION_X, y : CARD_OPEN_POSITION}
}).start(() => done && done());
};
resetPosition = (done) => {
Animated.spring(this.position, {
toValue: {x: CARD_INITIAL_POSITION_X, y : CARD_INITIAL_POSITION_Y}
}).start(() => done && done())
};
getCardStyle() {
return {
width: wp("90%"),
height: hp("110%"),
borderRadius: 10,
zIndex: 2,
backgroundColor: "white",
elevation: 1,
shadowColor: "black",
shadowOpacity: 0.2,
shadowOffset: { height: 2, width: 2 },
position: "absolute",
left: CARD_INITIAL_POSITION_X,
padding: hp("2%"),
...this.position.getLayout()
};
}
renderHeader(){
return (
<View
style={{
justifyContent: "center",
alignItems: "center"
}}
>
<Text style={{ fontSize: 30, marginBottom: hp("1%") }}>
{this.props.currentWeather.name}
</Text>
<View style={{ flexDirection: "row" }}>
<Text style={{ marginTop: hp("1%"), fontSize: 35 }}>
{this.props.currentWeather.main.temp}
</Text>
<Image
style={{ height: 60, width: 60 }}
source={{
uri: `${ICON_URL}${this.props.currentWeather.weather[0].icon}.png`
}}
/>
</View>
</View>
)
}
render() {
return this.state.panResponder ? <Animated.View {...this.state.panResponder.panHandlers} style={this.getCardStyle()}> {this.renderHeader()} </Animated.View> : <View />;
}
}
export default WeatherCard;
和 search-screen.js
import React from 'react';
import { StyleSheet, Text, View } from 'react-native';
import MapView from 'react-native-maps';
import {SearchBar} from "react-native-elements";
import {
widthPercentageToDP as wp,
heightPercentageToDP as hp
} from "react-native-responsive-screen";
import {connect} from "react-redux";
import {getCurrentWeatherByCity} from "../actions/index";
import WeatherCard from "../components/weather-card";
const DEFAULT_COORD = {
lat: 48.859268,
lng: 2.347060
};
class SearchScreen extends React.Component {
state={search: ""};
updateSearch = search => {
this.setState({search})
};
submitSearch = () => {
this.props.getCurrentWeatherByCity(this.state.search);
console.log(this.state.search)
};
render() {
console.log(this.props.currentWeather);
return (
<View style={styles.container}>
<MapView style={{flex : 1}}
region={{latitude : this.props.currentWeather ? this.props.currentWeather.coord.lat : DEFAULT_COORD.lat, longitude : this.props.currentWeather ? this.props.currentWeather.coord.lon : DEFAULT_COORD.lng, latitudeDelta: 0.2000, longitudeDelta: 0.1000}}
scrollEnabled={false}
liteMode={true} />
{this.props.currentWeather && <WeatherCard currentWeather={this.props.currentWeather} />}
<SearchBar
lightTheme
onChangeText={this.updateSearch}
value={this.state.search}
onSubmitEditing={this.submitSearch}
containerStyle={{
position: "absolute",
bottom: hp("50%"),
left: wp("5%"),
width: wp("90%")
}}/>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1
},
});
const mapStateToProps = (store) => {
return {
currentWeather : store.weather.currentWeather
}
};
const mapDispatchToProps = {
getCurrentWeatherByCity
};
export default connect(mapStateToProps, mapDispatchToProps)(SearchScreen)
我问自己问题是否可能是:
{this.props.currentWeather && <WeatherCard currentWeather={this.props.currentWeather} />}
因为它不在文本组件内...如果您能提供帮助,那就太好了:D
如果您需要其他资源,请不要犹豫!
提前致谢:)
最佳答案
可能是因为这个尝试这个:
改变
{this.props.currentWeather.name}
至
{this.props.currentWeather.name != undefined ? this.props.currentWeather.name : null}
对 {this.props.currentWeather.main.temp} 执行上述操作
希望这有帮助!
关于javascript - 不变违规文本字符串必须在 <Text> 组件内呈现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61193427/
我想澄清一些关于违反 MVVM 的问题。因此,我创建了一个解决方案,其中包含一些项目来演示这些案例。 这是解决方案的定义(项目): View (它是一个 WPF 类库,显然它有 View ) View
这个比较器方法有什么问题? 我已阅读: Java error: Comparison method violates its general contract 并理解,如果 c1 > c2,且 c2
public Integer getMaxCount(String id,String type) { String maxCount ="SELECT MAX(ID) AS COUNT FR
代码如下 #include int main() { auto [a] = std::make_tuple(1); return [a]() -> int { return a;
我正在尝试开发一个应用程序,该应用程序将显示缩放以适合屏幕大小的任意图像。但是,在 EDT 上缩放图像会显着降低 UI,因此我决定使用以下代码在后台线程中缩放图像。 final Runnabl
无论如何,是否可以在 Grails 项目中自动查找 I18N 违规?例如, Enabled: 应该被标记,因为它没有使用 获取标签值。 如果 codenarc 对此有规则,那就太好了,但我认为没有。
我想从 Sonar 中排除一些方法(用于分析目的)。 实际上是自动生成的equals()和hashCode()。没有使用大括号等,我并不总是想修复它们。有没有办法只排除某些方法的范围? 最佳答案 您可
我有一些看起来像这样的代码(我用通用变量替换了我的业务变量): Map map = new HashMap(); for (int i = 1; i < 10; i++) { String s
在使用 IList> 时作为方法声明中的参数类型发生 FXCop 违规 It doesnt nest generic type IList> 我该如何解决? 最佳答案 原因是: A nested ty
我有以下代码,我得到了 PMD 违规 SuspiciousEqualsMethodName。 我想知道为什么这会被视为违规? private boolean areEquals(final Objec
令我惊讶的是,Java 有时可以为您检查比较器契约。 例如,当你写一个不遵循传递性的顺序关系时,你得到 java.lang.IllegalArgumentException: Comparison m
我们有一个头文件,其中包含各种浮点精度的一些残差: template struct rsdTarget { static const double value; }; template <> c
我正在尝试更新一篇博客文章,但我从数据库部分收到了唯一的关键错误,然后我没有使用模型并直接访问 ORM,但又没有成功。 这是我具体要编辑的路线 Route::get('/getedit/{slug}'
需要帮助解决 Sonar 问题。我们正在使用一些在 Maven 公共(public)存储库中不存在的第三方 jar。我将它的依赖定义为: api
我开始使用 CheckThreadViolationRepaintManager 来检测 EDT 违规。 它提示: partner = getParameter("partner",generateP
我有 ViewState POJO 类,它们的构造函数带有许多参数。问题是 PMD 对它们抛出 ExcessiveParameterList 违规。 现在,我试图抑制所有以 ViewState.jav
PMD 失败:...规则:UnusedPrivateMethod 优先级:3 避免未使用的私有(private)方法,例如“printMyString(String)” private void an
我写了一个 lisp 程序,它有两个参数,一个目的地和一个 BST 形式的 map 。它在 BST 中搜索目标号码,如果找到目标则打印 (found: path)。如果未找到,则应该打印(未找到:目的
我有以下 Java 方法: private int calculate() { return (bytes[0] & 0xff) + ((bytes[1] & 0xff) << 8); } P
我一直在思考以下问题。考虑两个文件: A.cpp: template void g(T) {} inline void f() { g(1); } B.cpp: template void g(T)
我是一名优秀的程序员,十分优秀!