-
Notifications
You must be signed in to change notification settings - Fork 32
#1712 | [DMP 2025] Implement QR scanner and add support for QR data type #1733
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
base: master
Are you sure you want to change the base?
Changes from 1 commit
171d731
46f59d4
6a274a4
e28aa48
e1e5e92
16a7a9b
e5a20f8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,138 @@ | ||||||||||||||||||||||||||||
| import {Text, TouchableNativeFeedback, View, Modal, StyleSheet} from "react-native"; | ||||||||||||||||||||||||||||
| import PropTypes from 'prop-types'; | ||||||||||||||||||||||||||||
| import React from "react"; | ||||||||||||||||||||||||||||
| import AbstractFormElement from "./AbstractFormElement"; | ||||||||||||||||||||||||||||
| import ValidationErrorMessage from "../ValidationErrorMessage"; | ||||||||||||||||||||||||||||
| import Colors from "../../primitives/Colors"; | ||||||||||||||||||||||||||||
| import Fonts from "../../primitives/Fonts"; | ||||||||||||||||||||||||||||
| import FormElementLabelWithDocumentation from "../../common/FormElementLabelWithDocumentation"; | ||||||||||||||||||||||||||||
| import Icon from 'react-native-vector-icons/MaterialCommunityIcons'; | ||||||||||||||||||||||||||||
| import QRScanner from "./QRScanner"; | ||||||||||||||||||||||||||||
| import _ from "lodash"; | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| class QRFormElement extends AbstractFormElement { | ||||||||||||||||||||||||||||
| static propTypes = { | ||||||||||||||||||||||||||||
| element: PropTypes.object.isRequired, | ||||||||||||||||||||||||||||
| actionName: PropTypes.string.isRequired, | ||||||||||||||||||||||||||||
| value: PropTypes.object, | ||||||||||||||||||||||||||||
| validationResult: PropTypes.object | ||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| constructor(props, context) { | ||||||||||||||||||||||||||||
| super(props, context); | ||||||||||||||||||||||||||||
| this.state = { | ||||||||||||||||||||||||||||
| showQRScanner: false | ||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| displayValue() { | ||||||||||||||||||||||||||||
| const value = this.props.value.getValue(); | ||||||||||||||||||||||||||||
| return _.isNil(value) || value === '' | ||||||||||||||||||||||||||||
| ? this.I18n.t('tapToScanQR') | ||||||||||||||||||||||||||||
| : value; | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| openQRScanner() { | ||||||||||||||||||||||||||||
| this.setState({ showQRScanner: true }); | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| onQRRead(qrValue) { | ||||||||||||||||||||||||||||
| this.setState({ showQRScanner: false }); | ||||||||||||||||||||||||||||
| if (qrValue) { | ||||||||||||||||||||||||||||
| this.notifyChange(qrValue); | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
|
Comment on lines
+39
to
+44
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Normalize scanned value; avoid dropping valid “0” and whitespace-only scans Handle strings safely and ignore empty-after-trim. - onQRRead(qrValue) {
- this.setState({ showQRScanner: false });
- if (qrValue) {
- this.notifyChange(qrValue);
- }
- }
+ onQRRead(qrValue) {
+ this.setState({ showQRScanner: false });
+ const normalized = _.isString(qrValue) ? qrValue.trim() : qrValue;
+ if (!_.isNil(normalized) && normalized !== '') {
+ this.notifyChange(normalized);
+ }
+ }📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| notifyChange(value) { | ||||||||||||||||||||||||||||
| this.props.value.answer = value; | ||||||||||||||||||||||||||||
| this.dispatchAction(this.props.actionName, { | ||||||||||||||||||||||||||||
| formElement: this.props.element, | ||||||||||||||||||||||||||||
| parentFormElement: this.props.parentElement, | ||||||||||||||||||||||||||||
| questionGroupIndex: this.props.questionGroupIndex, | ||||||||||||||||||||||||||||
| value: value | ||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| removeValue() { | ||||||||||||||||||||||||||||
| this.notifyChange(null); | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| renderRemoveButton() { | ||||||||||||||||||||||||||||
| const hasValue = !_.isNil(this.props.value.getValue()) && this.props.value.getValue() !== ''; | ||||||||||||||||||||||||||||
| if (hasValue) { | ||||||||||||||||||||||||||||
| return ( | ||||||||||||||||||||||||||||
| <TouchableNativeFeedback onPress={() => this.removeValue()} | ||||||||||||||||||||||||||||
| background={TouchableNativeFeedback.SelectableBackgroundBorderless()} | ||||||||||||||||||||||||||||
| useForeground> | ||||||||||||||||||||||||||||
| <Icon name="backspace" | ||||||||||||||||||||||||||||
| style={{marginLeft: 8, fontSize: 20, color: Colors.AccentColor}}/> | ||||||||||||||||||||||||||||
| </TouchableNativeFeedback> | ||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
| return null; | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| renderFormElement() { | ||||||||||||||||||||||||||||
| const hasValue = !_.isNil(this.props.value.getValue()) && this.props.value.getValue() !== ''; | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| return ( | ||||||||||||||||||||||||||||
| <View> | ||||||||||||||||||||||||||||
| <FormElementLabelWithDocumentation element={this.props.element}/> | ||||||||||||||||||||||||||||
| <View style={{flexDirection: 'row', justifyContent: 'flex-start', alignItems: 'center'}}> | ||||||||||||||||||||||||||||
| <TouchableNativeFeedback onPress={() => this.openQRScanner()} | ||||||||||||||||||||||||||||
| background={TouchableNativeFeedback.SelectableBackground()}> | ||||||||||||||||||||||||||||
| <View style={styles.qrInputContainer}> | ||||||||||||||||||||||||||||
| <Icon name="qrcode-scan" | ||||||||||||||||||||||||||||
| style={[styles.qrIcon, {color: hasValue ? Colors.AccentColor : Colors.InputBorderNormal}]}/> | ||||||||||||||||||||||||||||
| <Text style={[ | ||||||||||||||||||||||||||||
| styles.qrText, | ||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||
| color: _.isNil(this.props.validationResult) ? | ||||||||||||||||||||||||||||
| (hasValue ? Colors.InputNormal : Colors.InputBorderNormal) : | ||||||||||||||||||||||||||||
| Colors.ValidationError, | ||||||||||||||||||||||||||||
| fontStyle: hasValue ? 'normal' : 'italic' | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
| ]}> | ||||||||||||||||||||||||||||
| {this.displayValue()} | ||||||||||||||||||||||||||||
| </Text> | ||||||||||||||||||||||||||||
| </View> | ||||||||||||||||||||||||||||
| </TouchableNativeFeedback> | ||||||||||||||||||||||||||||
| {this.renderRemoveButton()} | ||||||||||||||||||||||||||||
| </View> | ||||||||||||||||||||||||||||
| <ValidationErrorMessage validationResult={this.props.validationResult}/> | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| <Modal | ||||||||||||||||||||||||||||
| visible={this.state.showQRScanner} | ||||||||||||||||||||||||||||
| animationType="slide" | ||||||||||||||||||||||||||||
| onRequestClose={() => this.onQRRead(null)}> | ||||||||||||||||||||||||||||
| <QRScanner onRead={(qrValue) => this.onQRRead(qrValue)} /> | ||||||||||||||||||||||||||||
| </Modal> | ||||||||||||||||||||||||||||
| </View> | ||||||||||||||||||||||||||||
|
Comment on lines
+104
to
+110
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Use i18n strings inside QRScanner QRScanner hardcodes English (“Scan QR Code”, instruction, error, “Close”). Wire the new translation keys via props or context. I can send a small patch to QRScanner.js replacing literals with this.I18n.t('scanQRCodeTitle' | 'pointCameraAtQR' | 'cameraPermissionError') and reuse existing “closeModal” key. Want me to draft it? 🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| const styles = StyleSheet.create({ | ||||||||||||||||||||||||||||
| qrInputContainer: { | ||||||||||||||||||||||||||||
| flexDirection: 'row', | ||||||||||||||||||||||||||||
| alignItems: 'center', | ||||||||||||||||||||||||||||
| borderWidth: 1, | ||||||||||||||||||||||||||||
| borderColor: Colors.InputBorderNormal, | ||||||||||||||||||||||||||||
| borderRadius: 4, | ||||||||||||||||||||||||||||
| paddingHorizontal: 12, | ||||||||||||||||||||||||||||
| paddingVertical: 8, | ||||||||||||||||||||||||||||
| backgroundColor: Colors.GreyContentBackground, | ||||||||||||||||||||||||||||
| flex: 1, | ||||||||||||||||||||||||||||
| minHeight: 44 | ||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||
| qrIcon: { | ||||||||||||||||||||||||||||
| fontSize: 20, | ||||||||||||||||||||||||||||
| marginRight: 8 | ||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||
| qrText: { | ||||||||||||||||||||||||||||
| fontSize: Fonts.Large, | ||||||||||||||||||||||||||||
| flex: 1 | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| export default QRFormElement; | ||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Blocking: react-native-vision-camera@^4.7.1 is incompatible with react-native 0.72.8
VisionCamera 4.3.2+ requires React Native ≥ 0.73 due to React Native framework API changes. This repo is on RN 0.72.8, so 4.7.1 will not build. Options:
Release notes documenting the RN ≥ 0.73 requirement: “react-native-vision-camera 4.3.2 now requires react-native 0.73 or above.” (download.ddeec.com)
Apply one of these diffs:
A) If upgrading RN later, temporarily pin a compatible VC to unblock this PR’s feature work:
B) If you plan to upgrade RN now, leave ^4.7.1 but also raise Android compileSdk to 34 and verify AGP/Kotlin; coordinate that change in a separate PR to keep scope clean.
📝 Committable suggestion
🤖 Prompt for AI Agents