Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Android version works #51

Open
kinoko8587 opened this issue Jun 28, 2019 · 0 comments
Open

Android version works #51

kinoko8587 opened this issue Jun 28, 2019 · 0 comments

Comments

@kinoko8587
Copy link

kinoko8587 commented Jun 28, 2019

npm install react-native-smart-barcode --save
react-native link

#43
/node_modules/react-native-smart-barcode/android/src/main/java/com/reactnativecomponent/barcode/RCTCapturePackage.java
// @Override
public List<Class<? extends JavaScriptModule>> createJSModules() {
return Collections.emptyList();
}

#41
/node_modules/react-native-smart-barcode/Barcode.js
npm install prop-types --save
import React, {Component,} from 'react';
import PropTypes from 'prop-types';

App.js

import React, {
Component
} from 'react';
import {
View,
StyleSheet,
Alert,
} from 'react-native';

import Barcode from 'react-native-smart-barcode';

export default class App extends Component {
// 构造
constructor(props) {
super(props);
// 初始状态
this.state = {
viewAppear: false,
};
}

render() {
return (
<View style={{ flex: 1, backgroundColor: 'black', }}>
<Barcode style={{ flex: 1, }}
ref={component => this._barCode = component}
barCodeTypes={['org.iso.QRCode']} // add this prop
onBarCodeRead={this._onBarCodeRead} />

)
}

componentDidMount() {
let viewAppearCallBack = (event) => {
this.setTimeout(() => {
this.setState({
viewAppear: true,
})
}, 255)
}
this._listeners = [
// this.props.navigator.navigationContext.addListener('didfocus', viewAppearCallBack)
]
}

componentWillUnmount() {
this._listeners && this._listeners.forEach(listener => listener.remove());
}

_onBarCodeRead = (e) => {
console.log('e.nativeEvent.data.type = ${e.nativeEvent.data.type}, e.nativeEvent.data.code = ${e.nativeEvent.data.code}')
this._stopScan()
Alert.alert(e.nativeEvent.data.type, e.nativeEvent.data.code, [
{ text: 'OK', onPress: () => this._startScan() },
])
}

_startScan = (e) => {
this._barCode.startScan()
}

_stopScan = (e) => {
this._barCode.stopScan()
}

}

const styles = StyleSheet.create({
centerText: {
flex: 1,
fontSize: 18,
padding: 32,
color: '#777',
},
textBold: {
fontWeight: '500',
color: '#000',
},
buttonText: {
fontSize: 21,
color: 'rgb(0,122,255)',
},
buttonTouchable: {
padding: 16,
},
});

work now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant