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

Fix iOS React Native implementation #495

Open
wants to merge 36 commits into
base: v3
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
4e159a6
Fix react native bugs
KseniaBuntova Mar 21, 2023
1b3c9e6
fix urls
KseniaBuntova Mar 23, 2023
4fab3b3
fix svgs
KseniaBuntova Mar 23, 2023
a01d6d4
fix comments
KseniaBuntova Mar 23, 2023
b268424
Merge pull request #1 from maxsystems/kbuntova/fix-camera
KseniaBuntova Mar 24, 2023
70f5985
Disable portrait mode for native camera (#2)
KseniaBuntova Mar 28, 2023
06bb15a
[APP-1979] Fix enlarged svgs (#3)
KseniaBuntova Apr 3, 2023
0ec2f6a
[APP-1986] Add onPictureUploaded callback for zoomed damage photos (#4)
KseniaBuntova Apr 6, 2023
2ef5244
[APP-2052] Original of retaken monk picture also uploads to flicker (#5)
KseniaBuntova Apr 17, 2023
6a0fbb1
Merge parent repository (#6)
KseniaBuntova May 23, 2023
87cce1f
Merge branch 'main' of https://github.com/monkvision/monkjs
KseniaBuntova May 23, 2023
237ef11
Fix linter issues
KseniaBuntova Jun 22, 2023
e7a22d3
Merge branch 'main' of https://github.com/monkvision/monkjs
KseniaBuntova Jun 22, 2023
ebf8f23
Fix lint issues and some new native errors
KseniaBuntova Jun 27, 2023
9d2384f
remove console logs
KseniaBuntova Jun 27, 2023
e61f19a
Fix linter issues and native svg implementation (#7)
KseniaBuntova Jul 5, 2023
8f5fd12
fix enlarged overlays
KseniaBuntova Jul 5, 2023
0bb0ce9
Merge branch 'main' of https://github.com/monkvision/monkjs
KseniaBuntova Jul 13, 2023
2421b4d
Fix part selector svgs
KseniaBuntova Jul 24, 2023
9c685fa
Merge branch 'main' of https://github.com/monkvision/monkjs
KseniaBuntova Jul 26, 2023
bdeffa5
[APP-2231] Fix visibility of fullscreen button for mobile (#8)
KseniaBuntova Aug 2, 2023
31be45d
Fix enlarged SVGs and damage part selector (#9)
KseniaBuntova Aug 3, 2023
5b55a41
Merge branch 'main' of https://github.com/monkvision/monkjs
KseniaBuntova Aug 9, 2023
9c630c0
Fix native issues in new functionality (#11)
KseniaBuntova Aug 10, 2023
72ffd18
[APP-2249] scroll for photos doesn't work for some pages in Monk (#12)
KseniaBuntova Aug 17, 2023
5fb8ad7
Fix Damage Manipulator UI (#13)
KseniaBuntova Aug 23, 2023
6722b88
Merge parent main (#14)
KseniaBuntova Sep 6, 2023
d4a697c
Fix Damage Manipulator UI (#15)
KseniaBuntova Sep 21, 2023
bff5bd3
Merge parent (#16)
KseniaBuntova Oct 10, 2023
b042ebe
Merge parent (#17)
KseniaBuntova Oct 13, 2023
868645f
Merge branch 'main' of https://github.com/monkvision/monkjs
KseniaBuntova Nov 7, 2023
755c622
fix merge
KseniaBuntova Nov 7, 2023
c13f99b
Fix infinit PDF loading (#18)
KseniaBuntova Nov 20, 2023
3e13b12
[APP-2343] Fix Gallery (#19)
KseniaBuntova Nov 24, 2023
3136886
Merge branch 'main' of https://github.com/monkvision/monkjs
KseniaBuntova Dec 1, 2023
a5ca027
Merge branch 'main' of https://github.com/monkvision/monkjs
KseniaBuntova Dec 1, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
5 changes: 1 addition & 4 deletions packages/camera/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,8 @@
},
"dependencies": {
"@expo/match-media": "^0.3.0",
"@expo/vector-icons": "^12.0.5",
"@unimodules/core": "^7.1.2",
"@unimodules/react-native-adapter": "^6.3.9",
"axios": "^0.24.0",
"expo-image-manipulator": "^10.2.1",
"expo-image-manipulator": "~11.1.1",
"expo-screen-orientation": "^4.1.1",
"i18next": "^21.8.13",
"image-conversion": "^2.1.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const styles = StyleSheet.create({
padding: 20,
paddingBottom: 5,
maxWidth: 400,
maxHeight: 235
},
header: {
alignSelf: 'stretch',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,12 @@ export default function PartSelector({ orientation, togglePart, isPartSelected,
[height],
);
const svgElement = useMemo(() => {
const svg = doc.children[0];
let svg;
if (Platform.OS === 'web') {
svg = doc.children[0];
} else {
svg = doc.childNodes[1];
}
if (svg.tagName !== 'svg') {
throw new Error('Invalid part selector SVG format: expected <svg> tag as the first children of XML document');
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
/* eslint-disable react/no-array-index-key */
import React, { useMemo } from 'react';
import PropTypes from 'prop-types';

import Svg, { Path, G, } from "react-native-svg";
import CAR_PARTS from './hooks/carParts';

const SELECTED_FILL_COLOR = '#ADE0FFB3';
const UNSELECTED_FILL_COLOR = 'none';

const jsxSpecialAttributes = {
class: 'className',
};

export default function SVGComponentMapper({ element, togglePart, isPartSelected, groupName }) {
function getAttribute(element, name) {
for (let i = 0; i < element.attributes.length; i++) {
if (element.attributes[i].name === name) {
return element.attributes[i].nodeValue;
}
}
return undefined;
}

let names = [];
for (let i = 0; i < element.attributes.length; i++) {
names.push(element.attributes[i].name);
}

const attributes = useMemo(() => names.reduce((prev, attr) => ({
...prev,
[jsxSpecialAttributes[attr] ?? attr]: getAttribute(element, attr),
}), {}), [element]);

const elementClass = getAttribute(element, 'class');
const elementId = getAttribute(element, 'id');

let partKey = null;
if (groupName && CAR_PARTS.includes(groupName)) {
partKey = groupName;
}
if (elementClass && elementClass.includes('selectable') && CAR_PARTS.includes(elementId)) {
partKey = elementId;
}

const color = isPartSelected(partKey) ? SELECTED_FILL_COLOR : UNSELECTED_FILL_COLOR;
const onPress = () => {
togglePart(partKey);
};

let elementChildren;
elementChildren = [];
if (element.childNodes) {
for (let i = 0; i < element.childNodes.length; i++) {
elementChildren.push(element.childNodes[i]);
}
}
const children = useMemo(() => [...elementChildren], [element]);
const passThroughGroupName = useMemo(
() => {
if (element.tagName === 'g') {
return elementId;
} else {
return null;
}
},
[element],
);

if (element.tagName === 'svg') {
return (
<Svg {...attributes}>
{children.map((child, id) => (
<SVGComponentMapper
key={id.toString()}
element={child}
togglePart={togglePart}
isPartSelected={isPartSelected}
groupName={passThroughGroupName}
/>
))}
<Path style={{ fill: '#ffffff' }} />
</Svg>
);
} else if (element.tagName === 'path') {
return (
<Path {...attributes} onPress={partKey ? onPress : null} fill={color}>
{children.map((child, id) => (
<SVGComponentMapper
key={id.toString()}
element={child}
togglePart={togglePart}
isPartSelected={isPartSelected}
groupName={passThroughGroupName}
/>
))}
<Path style={{ fill: '#ffffff' }} />
</Path>
);
} else if (element.tagName === 'g') {
return (
<G {...attributes} onPress={partKey ? onPress : null} fill={color}>
{children.map((child, id) => (
<SVGComponentMapper
key={id.toString()}
element={child}
togglePart={togglePart}
isPartSelected={isPartSelected}
groupName={passThroughGroupName}
/>
))}
<Path style={{ fill: '#ffffff' }} />
</G>
);
} else {
return null;
}
}

SVGComponentMapper.propTypes = {
element: PropTypes.any.isRequired,
groupName: PropTypes.string,
isPartSelected: PropTypes.func.isRequired,
togglePart: PropTypes.func.isRequired,
};

SVGComponentMapper.defaultProps = {
groupName: undefined,
};
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as React from 'react';
import Svg, { Path } from 'react-native-svg';
import PropTypes from 'prop-types';
import {Platform} from 'react-native';

export default function RotateLeft({ width, height }) {
return (
Expand All @@ -11,7 +12,7 @@ export default function RotateLeft({ width, height }) {
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 10 21"
preserveAspectRatio="xMidYMid slice"
pointerEvents="box-none"
pointerEvents= {Platform.OS === 'web' ? 'box-none' : undefined}
>
<Path
d="M3.87 3.87c-1.61 1.85-2.6 4.25-2.6 6.9 0 4.65 3.03 8.58 7.22 9.96l.78-2.36a8.002 8.002 0 0 1-5.5-7.6c0-1.95.72-3.73 1.88-5.12l3.62 3.62v-9h-9l3.6 3.6Z"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as React from 'react';
import Svg, { Path } from 'react-native-svg';
import PropTypes from 'prop-types';
import {Platform} from 'react-native';

export default function RotateRight({ width, height }) {
return (
Expand All @@ -11,7 +12,7 @@ export default function RotateRight({ width, height }) {
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 16 37"
preserveAspectRatio="xMidYMid slice"
pointerEvents="box-none"
pointerEvents= {Platform.OS === 'web' ? 'box-none' : undefined}
>
<Path
d="M9.64 6.117c2.684 3.083 4.334 7.083 4.334 11.5 0 7.75-5.05 14.3-12.034 16.6l-1.3-3.934c5.317-1.75 9.167-6.75 9.167-12.666 0-3.25-1.2-6.217-3.133-8.534L.64 15.117v-15h15l-6 6Z"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { useMemo } from 'react';
const { DOMParser } = require('xmldom')

export default function useXMLParser(xml) {
return useMemo(() => new DOMParser().parseFromString(xml, 'text/xml'), [xml]);
Expand Down
1 change: 1 addition & 0 deletions packages/camera/src/components/AddDamageModal/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const styles = StyleSheet.create({
borderRadius: 10,
padding: CONTAINER_PADDING,
paddingBottom: 5,
maxHeight: 400
},
header: {
alignSelf: 'stretch',
Expand Down
24 changes: 0 additions & 24 deletions packages/camera/src/components/AddDamageOverlay/index.native.js

This file was deleted.

19 changes: 17 additions & 2 deletions packages/camera/src/components/Camera/index.native.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { forwardRef, useCallback } from 'react';
import React, { forwardRef, useCallback, useState, useImperativeHandle } from 'react';
import PropTypes from 'prop-types';
import { I18nextProvider, useTranslation } from 'react-i18next';

Expand All @@ -22,7 +22,20 @@ function Camera({
}, ref) {
const { t } = useTranslation();
const permissions = usePermissions();
const [cameraRef, setCameraRef] = useState(null);

useImperativeHandle(ref, () => ({
async takePictureAsync(options) {
return await cameraRef?.takePictureAsync(options);
},
resumePreview() {
cameraRef?.resumePreview()
},
pausePreview() {
cameraRef?.pausePreview()
}
}));

const { height: windowHeight, width: windowWidth } = useWindowDimensions();
const size = getSize(ratio, { windowHeight, windowWidth });

Expand All @@ -33,7 +46,9 @@ function Camera({
if (permissions.granted && permissions.status === PermissionStatus.GRANTED) {
return (
<ExpoCamera
ref={ref}
ref={ref => {
setCameraRef(ref) ;
}}
ratio={ratio}
onMountError={handleError}
{...passThroughProps}
Expand Down
8 changes: 6 additions & 2 deletions packages/camera/src/components/Camera/styles.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { StyleSheet } from 'react-native';
import { StyleSheet, Platform } from 'react-native';

export default StyleSheet.create({
container: {
Expand All @@ -12,7 +12,11 @@ export default StyleSheet.create({
backgroundColor: 'rgba(0,0,0,0.75)',
borderRadius: 18,
color: 'white',
fontFamily: 'monospace',
...Platform.select({
web: {
fontFamily: 'monospace'
},
}),
fontSize: 14,
lineHeight: 9,
marginTop: 4,
Expand Down
4 changes: 2 additions & 2 deletions packages/camera/src/components/Capture/capture.js
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ const Capture = forwardRef(({
endTour,
};
const startUploadAsync = useStartUploadAsync(startUploadAsyncParams);
const uploadAdditionalDamage = useUploadAdditionalDamage({ inspectionId });
const uploadAdditionalDamage = useUploadAdditionalDamage({inspectionId, onPictureUploaded});

const [goPrevSight, goNextSight] = useNavigationBetweenSights({ sights });

Expand Down Expand Up @@ -359,7 +359,7 @@ const Capture = forwardRef(({
const handlePartSelectorConfirm = useCallback((selectedParts) => {
setAddDamageParts(selectedParts);
setAddDamageStatus(AddDamageStatus.TAKE_PICTURE);
}, [setAddDamageStatus]);
}, [setAddDamageParts, setAddDamageStatus]);

const handleCloseCaptureEarly = useCallback(() => {
if (typeof onCloseEarly === 'function') {
Expand Down
Loading