我在此处遵循的构造,但仍然不起作用。
我正在尝试此外部组件:https://www.npmjs.com/package/react-native-typewriter
所以,我已经安装了以下方式:
npm安装-Save反应型型型
然后我写了此代码:
index.android.js
'use strict';
import {AppRegistry} from 'react-native';
import TypingText from './app/textanimation.js';
AppRegistry.registerComponent('AwesomeProject', () => TypingText );
textAnimation.js
import React, {Component} from 'react'
import TypeWriter from 'react-native-typewriter';
class TypingText extends Component {
render() {
return <TypeWriter typing={1}>Hello World!</TypeWriter>
}
}
export default TypingText;
package.json
{
"name": "AwesomeProject",
"version": "0.0.1",
"private": true,
"scripts": {
"start": "node node_modules/react-native/local-cli/cli.js start",
"test": "jest"
},
"dependencies": {
"react": "15.4.2",
"react-native": "0.41.2",
"react-native-push-notification": "^2.2.1",
"react-native-sound": "^0.9.0",
"react-native-typewriter": "^0.3.0",
"react-native-vector-icons": "^4.0.0"
},
"devDependencies": {
"babel-jest": "18.0.0",
"babel-preset-react-native": "1.9.1",
"jest": "18.1.0",
"react-test-renderer": "15.4.2"
},
"jest": {
"preset": "react-native"
},
"rnpm": {
"assets": [
"assets/fonts/04b03"
]
}
}
但我在下面收到错误:
似乎您正在尝试从 "反应态"包。也许您打算访问" react.component" 从" React"软件包中?
For example, instead of: import React, { Component, View } from 'react-native'; You should now do: import React, { Component } from 'react'; import { View } from 'react-native'; Check the release notes on how to upgrade your code - https://github.com/facebook/react-native/releases/tag/v0.25.1
好吧,我终于找到了有关react-native-typewriter
软件包问题的解决方案。
导航到node_modules> react-native-typewriter> index.js从
编辑以下标题import React, {
Component,
Text,
PropTypes,
} from 'react'
to
import React, {
Component,
PropTypes,
} from 'react'
import {
Text,
} from 'react-native'
工作简短示例
import React,{Component} from 'react';
import{AppRegistry,} from 'react-native';
import TypeWriter from 'react-native-typewriter';
export default class HelloWorld extends Component{
constructor(){
super();
}
render() {
return <TypeWriter typing={1}>Hello World!</TypeWriter>
}
}
AppRegistry.registerComponent('HelloWorld', () => HelloWorld);
R-N 0.42.0