<TouchableHighlight onPress={this._onPress.bind(this)}>
<Text style={{color: 'white'}}>CLOSE</Text>
</TouchableHighlight>
_onPress(e) {
console.log(e.nativeEvent.target);
}
Run Code Online (Sandbox Code Playgroud)
如上所述,这target
只是一个名为node id的数字,但我想得到真正的元素.我怎样才能做到这一点?
ReactNative:
<ScrollView style={styles.container}>
<Svg
height="100"
width="100">
<Circle
cx="50"
cy="50"
r="50"
stroke="blue"
strokeWidth="2.5"
fill="green"/>
</Svg>
</ScrollView>
Run Code Online (Sandbox Code Playgroud)
我想用Animated.Value制作Circle比例.我试过这个:
let AnimatedScrollView = Animated.createAnimatedComponent(ScrollView);
let AnimatedCircle = Animated.createAnimatedComponent(Circle);
<ScrollView style={styles.container}>
<Svg
height="100"
width="100">
<AnimatedCircle
cx="50"
cy="50"
r={this.state.animator}
stroke="blue"
strokeWidth="2.5"
fill="green"/>
</Svg>
</ScrollView>
Run Code Online (Sandbox Code Playgroud)
然后闪回,没有错误.
我能怎么做?
更新2016.8.24
我发现了一种新方法而不是requestAnimationFrame:
构造函数:
this.state = {
animator: new Animated.Value(0),
radius: 1,
};
this.state.animator.addListener((p) => {
this.setState({
radius: p.value,
});
});
Run Code Online (Sandbox Code Playgroud)
渲染:
<Circle
cx="50"
cy="50"
r={this.state.radius}
stroke="blue"
strokeWidth="2.5"
fill="green"/>
Run Code Online (Sandbox Code Playgroud)
但是这里的指南会谨慎地使用它,因为它可能会在将来产生性能影响.
那么最好的方法是什么?
如何在ReactNative中截取屏幕截图.我需要一个截图并将其放入Image
组件中.我该怎么办?
滚动视图:
<View style={{flex:1}}>
<ScrollView
ref={(component) => {this._scrollView = component}}
scrollEventThrottle={15}
removeClippedSubviews={true}
pagingEnabled={true}
horizontal={true}
onScroll={this._onScroll.bind(this)}>
{items}
</ScrollView>
<Text style={styles.legend}>{this.state.currentPage}/{9}</Text
</View>
Run Code Online (Sandbox Code Playgroud)
_onScroll
:这个方法计算当前页号是多少
<View style={{flex:1}}>
<ScrollView
ref={(component) => {this._scrollView = component}}
scrollEventThrottle={15}
removeClippedSubviews={true}
pagingEnabled={true}
horizontal={true}
onScroll={this._onScroll.bind(this)}>
{items}
</ScrollView>
<Text style={styles.legend}>{this.state.currentPage}/{9}</Text
</View>
Run Code Online (Sandbox Code Playgroud)
我认为代码行没问题,但是当我平移到scrollView
下一页时,它会向后滚动。一旦我删除 中的代码行_onScroll
,问题就可以解决,但我无法计算当前页码。
当我想react-native run-android
在终端执行时,我必须首先打开android studio并运行android模拟器,这很棘手.有人知道如何在终端中运行android模拟器吗?
关闭:
function test() {
var count = 0;
return function() {
count++;
};
}
Run Code Online (Sandbox Code Playgroud)
众所周知,调用count
后不会释放test()
,现在如果闭包对我没用,我怎么能释放它的内存呢?