小编rik*_*san的帖子

React Native仅适用于UI组件

我有一个非常简单的ViewController,用Swift编写,其内置在Storyboard中.当有人按下按钮时,它只会更改标签的文本.

class ViewController: UIViewController {
    @IBOutlet weak var label: UILabel!

    @IBAction func changeText() {
        switch label.text! {
            case "Old Text":
                label.text = "New Text"
            case "New Text":
                label.text = "Old Text"
            default:
                break
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

我想为我的项目使用React Native,但只处理UI组件,而不是app逻辑本身.我该怎么做?我已经布置了按钮和文本的反应.

var Button = require('react-native-button');

class TestProject extends Component {
  render() {
    return (
      <View style={styles.container}>
        <Button style={styles.button}>Change Text</Button>
        <Text style={styles.text}>
          Text to be changed
        </Text>
      </View>
    );
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor: …
Run Code Online (Sandbox Code Playgroud)

native ios reactjs swift react-native

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

长按React Native可以不断增加计数器

我旁边有一个按钮TextInput,按下该按钮可增加其计数器。

   <TouchableWithoutFeedback onPress={() => {this.increaseAmount(step, rowID)}}>
      <View style={styles.amountPlusButtonContainer}>
        <Text style={styles.amountButtonText}>+</Text>
      </View>
    </TouchableWithoutFeedback>
Run Code Online (Sandbox Code Playgroud)

当前,每当我点击按钮时,它就会增加1。我要实现的是只要用户按下计数器,就不断增加计数器。

我曾尝试使用它,setInterval()但我不知道确切何时停止它,也不是解决此问题的正确方法。

javascript android ios react-native

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

标签 统计

ios ×2

react-native ×2

android ×1

javascript ×1

native ×1

reactjs ×1

swift ×1