我正在我的反应原生应用程序中实现相机.我希望在点击后在同一屏幕上的小图像视图中显示该相机最近拍摄的图像.但我没有得到如何访问最近点击的图像.每当通过手机点击任何新图像时,它都会被赋予一个默认的随机名称,我如何在图像视图的源代码中引用它?请告诉我一些方法.我的代码是
class Incident extends Component {
constructor(props)
{ super(props)
this.state= {path:"",show:false,video:Camera.constants.CaptureMode.video,camera:Camera.constants.CaptureMode.camera}
}
render() {
return (
<View style={styles.container}>
<View style={{flex:72}}>
<Camera
ref={(cam) => {
this.camera = cam;
}}
style={styles.preview}
aspect={Camera.constants.Aspect.fill}
captureMode={this.state.camera}>
</Camera>
</View>
<View style={{flex:8,opacity:0.5,backgroundColor:'black'}}>
{()=>this.showClickedImage()}
</View>
<View style={{flex:10,flexDirection:'row',justifyContent:'space-between',backgroundColor:'#f3396b'}}>
<TouchableOpacity style={{flex:33,flexDirection:'column', alignItems: 'center',paddingTop:10}}>
<Image style={styles.icon} source={require('./Images/menu.png')}/>
<Text>Home</Text>
</TouchableOpacity>
<TouchableOpacity style={{flex:34,flexDirection:'column', height:70,alignItems: 'center',borderColor:'#dd1e52',borderWidth:1,paddingTop:5}}
onPress={()=>this.takePicture()}>
<Image style={{width:50,height:50}} source={require('./Images/capture.png')}/>
</TouchableOpacity>
<TouchableOpacity style={{flex:33,flexDirection:'column', alignItems: 'center',paddingTop:10}}>
<Image style={styles.icon} source={require('./Images/profile.png')}/>
<Text>Profile</Text>
</TouchableOpacity>
</View>
</View>
);
}
showClickedImage()
{
return <View style={{flex:1,height:40,width:40, borderWidth:1,borderColor:'black'}}>
<Image style={{width:40,height:40}} source= {{uri: …Run Code Online (Sandbox Code Playgroud) 我有一个工作的iOS反应本机应用程序(反应本机v 0.38).我试图在android中运行相同的应用程序.
我手动链接了所有这些库(我现在在iOS中使用):
react-native-camera
react-native-code-push
react-native-device-info
react-native-google-analytics-bridge
react-native-i18n
react-native-push-notification
react-native-restart
react-native-sqlite-storage
Run Code Online (Sandbox Code Playgroud)
Settings.gradle:
include ':app'
include ':react-native-sqlite-storage'
project(':react-native-sqlite-storage').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-sqlite-storage/src/android')
include ':react-native-restart'
project(':react-native-restart').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-restart/android')
include ':react-native-push-notification'
project(':react-native-push-notification').projectDir = file('../node_modules/react-native-push-notification/android')
include ':app', ':react-native-i18n'
project(':react-native-i18n').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-i18n/android')
include ':react-native-google-analytics-bridge', ':app'
project(':react-native-google-analytics-bridge').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-google-analytics-bridge/android')
include ':react-native-device-info'
project(':react-native-device-info').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-device-info/android')
include ':app', ':react-native-code-push'
project(':react-native-code-push').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-code-push/android/app')
include ':react-native-camera'
project(':react-native-camera').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-camera/android')Run Code Online (Sandbox Code Playgroud)
build.gradle:
// Top-level build file where you can add …Run Code Online (Sandbox Code Playgroud)可能有人知道为什么"shadowColor"属性不适用于Android上的抽屉样式?(iOS看起来一切都好)
<Drawer
type="overlay"
...
styles={{
drawer: {shadowColor: 'black', shadowOpacity: 0.8, shadowRadius: 2}
...
}}
>
Run Code Online (Sandbox Code Playgroud)

react-native-drawer版本:2.3.0
React Native版本:0.41.2
平台(iOS,Android或两者兼而有之?):Android
设备信息模拟器/设备? - 模拟器Android 4.1(API16),模拟器Android 7.1.1(API25)
OS版本? - MacOS 10.12.3
调试/发布? - 调试
如何在react-native中调用其他组件的函数?
我有这个自定义组件,它在另一个地方呈现另一个组件和一个图像按钮.当点击图像时,我想从另一个组件调用一个函数.执行下面的示例时,我得到了undefined is not an object (evaluating this.otherComponent.doSomething')
export default class MainComponent extends Component {
_onPressButton() {
this.otherComponent.doSomething();
}
render() {
return (
<View style={styles.container}>
<TagContainer style={styles.flow_container} ref={(instance) => this.otherComponent = instance}>
</TagContainer>
<TouchableHighlight onPress={this._onPressButton}><Image source={require('./img/ic_add.png')} style={styles.add_tags_button_view} /></TouchableHighlight>
</View>
);
}
}
Run Code Online (Sandbox Code Playgroud)
和
export default class OtherComponent extends Component {
addTag() {
this.state.tags = this.state.tags.push("plm");
console.log('success..');
}
....
}
Run Code Online (Sandbox Code Playgroud) 我有一个使用react native的标签导航,react-navigation 我的5个标签在Android上太过于挤压但看起来很适合iOS.如何设置标签的样式以适应Android?我可以将标签水平滚动吗?我想我记得在某个地方看过 - 那是标准的android行为吗?
我想使用react-native更改最近的应用程序视图中的背景标题颜色(当您按下Android上的概述方形按钮时).
您可以在下面的图像中看到Facebook应用程序具有蓝色背景颜色,但我的比特币FOMO计算器应用程序具有默认的灰色.
谢谢
我开始弹出世博会,经过这么多的努力,我能够解决所有构建问题.当我使用'sudo react-native run-android'运行应用程序时,我开始收到以下错误
错误:
The development server returned response code 500
Bundling `index.android.js` [development, non-minified, hmr disabled]
0.0% (0/1), failed.
error: bundling failed: "TransformError:
/Development/SourceCode/MobileApp/index.android.js:
Couldn't find preset \"babel-preset-react-native-stage-0/decorator-support\" relative to directory \"/Development/SourceCode/MobileApp\""
Run Code Online (Sandbox Code Playgroud)
我尝试了在github和SO中给出的几乎所有可能的修复
.babelrc 文件看起来像这样
{
"presets": [
"react-native",
"babel-preset-react-native-stage-0/decorator-support"
],
"env": {
"development": {
"plugins": [
"transform-react-jsx-source"
]
}
}
}
Run Code Online (Sandbox Code Playgroud)
这些修复都不适合我.使用babel-preset-react-native@2.1.0也没有解决问题,因为这是主要的修复.
使用react-native时,我在启动命令时遇到错误.第63行的文件 projectName /node_modules/@babel/core/lib/transformation/file/file.js给出了错误
constructor(options, {
^
SyntaxError: Unexpected token {
at exports.runInThisContext (vm.js:53:16)
at Module._compile (module.js:374:25)
at Module._extensions..js (module.js:417:10)
at Object.require.extensions.(anonymous function) [as .js] (/home/cread/WHOOP-ReactNative/whoopApp/node_modules/babel-register/lib/node.js:152:7)
at Module.load (module.js:344:32)
at Function.Module._load (module.js:301:12)
at Module.require (module.js:354:17)
at require (internal/module.js:12:17)
at Object.<anonymous> (/home/cread/WHOOP-ReactNative/whoopApp/node_modules/@babel/core/lib/index.js:123:36)
at Module._compile (module.js:410:26)
Run Code Online (Sandbox Code Playgroud)
这是我的package.json文件
{
"name": *name*,
"version": "0.0.1",
"private": true,
"scripts": {
"start": "node node_modules/react-native/local-cli/cli.js start",
"test": "jest"
},
"dependencies": {
"react": "16.3.0-alpha.2",
"react-native": "0.54.2",
"react-native-elements": "^0.19.1",
"react-native-keyboard-aware-scroll-view": "^0.5.0",
"react-native-modal-dropdown": "^0.6.2",
"react-native-sound": "0.10.9",
"react-native-vector-icons": "^4.5.0",
"react-navigation": "^1.5.8"
},
"devDependencies": …Run Code Online (Sandbox Code Playgroud)