我正在使用react-native-sound模块但是当我启动声音并按下Home按钮退出应用程序时,声音仍然在播放.
当我重新加载应用程序时,它会再次启动声音并且我无法使用.stop()它来销毁它,因为它只会破坏加载到第一个上面的第二个.
我该怎么办呢?
class Home extends Component {
constructor(props) {
super(props);
this.props.actions.fetchScores();
}
componentWillReceiveProps(nextProps){
nextProps.music.backgroundMusic.stop()
setInterval( () => {
nextProps.music.backgroundMusic.play()
nextProps.music.backgroundMusic.setNumberOfLoops(-1)
}, 1000);
}
}
export default connect(store => ({
music: store.music
})
)(Home);
Run Code Online (Sandbox Code Playgroud) 尝试将功能传递给子组件时,该功能未定义。实际上,我什至不能在我的课堂上直接执行它。您认为有错字吗?
class FriendsPage extends Component {
constructor(props){
super(props);
this.mylog = this.mylog.bind(this);
}
mylog(){
console.log("test debug");
}
renderItem(item) {
return (<User friend={item} key={item.id} mylog={this.mylog}/>);
}
class User extends Component {
constructor(props){
super(props);
}
render() {
this.props.mylog(); // <== This is undefined
...
}
Run Code Online (Sandbox Code Playgroud) 我有一个基本的react-native应用程序,我在真正的Nexus 5上运行,我找不到一种方法来启用现有的开发人员菜单iOS和模拟设备.
https://facebook.github.io/react-native/docs/debugging.html
https://facebook.github.io/react-native/docs/running-on-device.html
方法1:使用adb reverse(推荐)
如果您的设备运行的是Android 5.0(Lollipop),它已启用USB调试,并且它通过USB连接到您的开发机器,则可以使用此方法.在命令提示符中运行以下命令:
$ adb reverse tcp:8081 tcp:8081您现在可以使用React Native in-app Developer菜单中的Reload JS而无需任何其他配置.
当我跑步时,react-native run-android我在终端看到这一行
Running adb -s 06adb216 reverse tcp:8081 tcp:8081
但我看到没有 React Native in-app Developer菜单
我在跑步:
Windows 10
react-native-cli: 2.0.1
react-native: 0.42.0
Run Code Online (Sandbox Code Playgroud)
我的index.android.js文件看起来像这样:
import { AppRegistry } from 'react-native';
import Welcome from './src/modules/onboarding/components/welcome';
AppRegistry.registerComponent('mobileapp', () => Welcome);
Run Code Online (Sandbox Code Playgroud) android nexus-5 windows-10 react-native react-native-android
看起来像react-native(React Native v0.23)无法连接到bintray.
FAILURE:构建因异常而失败.
无法解析配置':classpath'的所有依赖项.无法下载protobuf-java.jar(com.google.protobuf:protobuf-java:2.5 .0)无法获取资源' https://jcenter.bintray.com/com/google/protobuf/ protobuf-java/2.5. 0/protobuf的-java的2.5.0.jar".无法获取' https://jcenter.bintray.com/com/google/protobuf/protob uf-java/2.5.0/protobuf-java-2.5.0.jar'.akamai.bintray.com
类似的问题:https: //github.com/facebook/react-native/issues/5884
有没有人找到解决方案?
我遵循的
步骤是.
更新:立即获取以下错误:
配置项目':app'时出现问题.
无法下载imagepipeline.aar(com.facebook.fresco:imagepipeline:1.3.0)
无法获得资源' https://jcenter.bintray.com/com/facebook/fresco/ima gepipeline/1.3.0/imagepipeline-1.3.0.aar'.无法获取' https://jcenter.bintray.com/com/facebook/fresco/imagepipe line/1.3.0/imagepipeline-1.3.0.aar'.akamai.bintray.com
这是我得到的错误:
的package.json
{
"name": "LoginApp2",
"version": "0.0.1",
"private": true,
"scripts": {
"start": "node node_modules/react-native/local-cli/cli.js start",
"test": "jest"
},
"dependencies": {
"react": "16.0.0-alpha.12",
"react-native": "0.48.3"
},
"devDependencies": {
"babel-jest": "21.2.0",
"babel-preset-react-native": "4.0.0",
"jest": "21.2.1",
"react-test-renderer": "16.0.0-alpha.12"
},
"jest": {
"preset": "react-native"
}
}
Run Code Online (Sandbox Code Playgroud)
index.js
import React, { Component } from 'react';
import { AppRegistry,View,Text,StyleSheet } from 'react-native';
import UsersManager from './pages/app';
AppRegistry.registerComponent('LoginApp2', () => UsersManager);
Run Code Online (Sandbox Code Playgroud)
页/ app.js
import React, { Component } from 'react';
import { AppRegistry,View,Text,StyleSheet,ScrollView,TouchableOpacity } from 'react-native';
import …Run Code Online (Sandbox Code Playgroud) render() {
return(
<Card style={{ padding: 0 }}>
<CardItem listItemPadding={0} header style=styles.Card}>
<Text style={styles.cardText}>
{this.props.library.title}
</Text>
</CardItem>
</Card>
);
}
Run Code Online (Sandbox Code Playgroud)
文档说listItemPadding可以使用,但是不起作用,我试图将padding更改为0,但是也不起作用。
我正在构建具有一些本地android模块的react-native应用程序。
在MainApplication.java中,
protected List<ReactPackage> getPackages() {
return Arrays.<ReactPackage>asList(
new VectorIconsPackage(),
new MyCustomPackage()
);
}
Run Code Online (Sandbox Code Playgroud)
在我的MyCustomPackage中,
public class MyCustomPackage implements ReactPackage {
@Override
public List<ViewManager> createViewManagers(ReactApplicationContext reactContext) {
return Collections.emptyList();
}
@Override
public List<NativeModule> createNativeModules(
ReactApplicationContext reactContext) {
List<NativeModule> modules = new ArrayList<>();
modules.add(new MyCustomModule(reactContext));
return modules;
}
}
Run Code Online (Sandbox Code Playgroud)
我还有其他几个模块,但这只是一个例子。所有功能都运作良好。现在,我想向MyCustomModule Java类中的方法编写单元测试。我尝试使用Robolectric框架,但不知道它如何与react native一起工作。还有其他工具吗?谁能给我一些示例或指导,以编写本机原生Android代码的单元测试?
android unit-testing react-native react-native-android react-native-native-module
关闭应用程序后,我可以获得由单击的深层链接URL Linking.getInitialURL()。当应用程序处于后台状态时,则不会挂载任何内容。因此,即使通过,我也无法获取该网址Linking.addEventListener('url', method_name)。
如何做到这一点?
在facebook SDK的最新更新中,我在同步android项目中的gradle文件(react native)时遇到了这个问题。
error Failed to install the app. Make sure you have the Android development environment set up: https://facebook.github.io/react-native/docs/getting-started.html#android-development-environment. Run CLI with --verbose flag for more details. Error: Command failed: ./gradlew app:installDebug -PreactNativeDevServerPort=8081
Run Code Online (Sandbox Code Playgroud)
失败:构建失败,发生异常。
facebook-core:5.11.1无法解决。
react-native ×10
android ×5
javascript ×2
deep-linking ×1
facebook ×1
nexus-5 ×1
unit-testing ×1
windows-10 ×1