我按照了here指示,但它仍然不起作用。
我正在尝试这个外部组件:https://www.npmjs.com/package/react-native-typewriter
所以,我已经安装了它:
npm install --save react-native-typewriter
然后我写了这段代码:
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"
]
}
}
但我收到以下错误:
似乎你正试图从中获取'ReactNative.Component' 'react-native'包。也许你打算访问'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
答案 0 :(得分:1)
好的,我终于得到了react-native-typewriter
包问题的解决方案。
导航到node_modules&gt;反应天然-打字机&GT; index.js 从
编辑以下标题import React, {
Component,
Text,
PropTypes,
} from 'react'
以强>
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