小编Cod*_*Lim的帖子

如何通过节点ID获得真正的元素?反应母语

<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的数字,但我想得到真正的元素.我怎样才能做到这一点?

react-native

12
推荐指数
3
解决办法
1万
查看次数

如何在react-native中使用Animated制作svg动画

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)

但是这里的指南会谨慎地使用它,因为它可能会在将来产生性能影响.

那么最好的方法是什么?

svg react-native

10
推荐指数
2
解决办法
1万
查看次数

如何以编程方式在react-native中截取屏幕截图

如何在ReactNative中截取屏幕截图.我需要一个截图并将其放入Image组件中.我该怎么办?

screenshot react-native

10
推荐指数
2
解决办法
1万
查看次数

如何显示分页scrollView的当前页码?

滚动视图:

<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

5
推荐指数
2
解决办法
3753
查看次数

如何在终端启动android avd模拟器

当我想react-native run-android在终端执行时,我必须首先打开android studio并运行android模拟器,这很棘手.有人知道如何在终端中运行android模拟器吗?

android-virtual-device react-native

2
推荐指数
1
解决办法
1175
查看次数

如何在javascript中释放闭包的内存?

关闭:

function test() {
  var count = 0;

  return function() {
    count++;
  };
}
Run Code Online (Sandbox Code Playgroud)

众所周知,调用count后不会释放test(),现在如果闭包对我没用,我怎么能释放它的内存呢?

javascript memory

1
推荐指数
1
解决办法
1400
查看次数