-
-
Notifications
You must be signed in to change notification settings - Fork 192
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
feat: planter selfie rotation #142
Conversation
45e431e
to
a636045
Compare
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.
It's a good start, but a few things don't quite work as they should.
We also need to apply the rotation on Planter cards and in the Planter Detail dialog.
src/components/ImageScroller.js
Outdated
onSelectChange('imageRotation', 0); | ||
} else { | ||
setRotation(rotation + 90); | ||
onSelectChange('imageRotation', rotation + 90); |
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.
You could reduce duplication here by using a temporary variable:
let newRotation = rotation + 90;
if (newRotation === 360) {
newRotation = 0;
}
setRotation(newRotation);
onSelectChange('imageRotation, newRotation);
src/components/ImageScroller.js
Outdated
@@ -129,7 +165,15 @@ export default function ImageScroller(props) { | |||
height={192} | |||
className={classes.image} | |||
fixed | |||
style={{ transform: `rotate(${rotation}deg)` }} |
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.
Applying the style
attribute here overrides the value inside the OptimizedImage
component, causing the image to become squashed.
Instead, you could add a rotation
or transform
prop to OptimizedImage
and add the transform to the style
within that component.
src/components/ImageScroller.js
Outdated
position: 'absolute', | ||
bottom: 0, | ||
right: 0, | ||
width: 25, |
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.
I think the button needs to be larger (try 32px).
src/components/ImageScroller.js
Outdated
/> | ||
<IconButton |
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.
A Fab
is more appropriate here, and the default styling is better than an IconButton
.
src/components/ImageScroller.js
Outdated
@@ -118,7 +154,7 @@ export default function ImageScroller(props) { | |||
images.slice(0, maxImages).map((img, idx) => ( | |||
<Card | |||
key={`${idx}_${img}`} | |||
onClick={() => onSelectImage(img)} | |||
onClick={() => handleDataChange(img)} |
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.
Clicking the image shouldn't trigger rotation, just select the image.
Only clicking the rotate button should trigger rotation.
src/components/ImageScroller.js
Outdated
/> | ||
<IconButton |
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.
We should only show the rotation button on (and apply to the rotation to) the selected image.
Otherwise it looks a bit messy with multiple images:
Screen.Recording.2021-08-08.at.12.03.36.mov
src/components/ImageScroller.js
Outdated
@@ -103,6 +126,19 @@ export default function ImageScroller(props) { | |||
}); | |||
} | |||
|
|||
function handleDataChange(img) { | |||
if (img) { |
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.
Doing the selection and rotation at the same time doesn't work. Only the rotation is applied.
Selection and rotation should be two separate actions.
src/components/EditPlanter.js
Outdated
@@ -90,17 +90,13 @@ const EditPlanter = (props) => { | |||
return newPlanter[key] !== planter[key]; | |||
}); | |||
|
|||
if (changed) { | |||
if (key === 'imageRotation' || changed) { |
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.
This causes the Save button to be enabled if there is a non-zero rotation, even if nothing has changed.
src/components/ImageScroller.js
Outdated
width: 25, | ||
height: 25, | ||
color: 'white', | ||
backgroundColor: 'black', |
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.
If you use a Fab
component, there's no need to override the default colors.
src/components/ImageScroller.js
Outdated
<IconButton | ||
className={classes.clickRotate} | ||
onClick={() => handleDataChange(null)} | ||
style={{ transform: `rotateY(180deg)` }} |
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.
It's just the icon we want to rotate, not the button.
@tranquanghuy0801 For info, while having a look at the latest updates I noticed a bug in the api (fixed in Greenstand/treetracker-admin-api#587) whereby The fix has now been deployed to dev and test. |
@nmcharlton Yeah thanks for fixing that issue. I will check my code again later today. |
This will make the "Save" button become inactive even you click rotate icon. Hope this make sense. Do you have any thought on this case? |
@nmcharlton that's alright. I knew how to fix that. Check my latest commits. |
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.
Thanks @tranquanghuy0801. This looks a lot better, but I still see a couple of issues:
- The rotation should only be applied to the selected image in the Edit Planter dialog, but is applied to all of them. Search planter ID 323 in the Planters tool for an example.
- Rotated images have gaps at the top and bottom in the Edit Planter dialog, and overlap text in the Planter Detail drawer (see video below). The image should fill but not overflow the container.
- If you edit the planter from the Verify tool, the Planter Detail does not get updated straight away. This is a more general problem, and not specific to image rotation, so could be handled under a separate PR if you don't want to fix it here.
Screen.Recording.2021-08-14.at.14.02.18.mov
@nmcharlton |
8548b61
to
d2de60e
Compare
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.
Sorry to keep asking for changes – this is a more complex problem than I'd realised!
src/components/ImageScroller.js
Outdated
@@ -30,7 +30,7 @@ const useStyle = makeStyles((theme) => ({ | |||
textAlign: 'center', | |||
}, | |||
imageCard: { | |||
height: '100%', | |||
height: '84%', |
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.
Let's keep it simple and make these images square.
src/components/ImageScroller.js
Outdated
objRotation[selectedIndex] = imageRotation; | ||
} else { | ||
images.map((_, idx) => { | ||
objRotation[idx] = imageRotation; |
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.
It doesn't really make sense to apply image rotation to all images if none is selected.
Just leave all other images unrotated and apply the rotation to the selected image only.
src/components/ImageScroller.js
Outdated
objRotation[idx] = imageRotation; | ||
}); | ||
} | ||
let [rotations, setRotations] = useState(objRotation); |
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.
I think this is introducing unnecessary complexity.
There's no point in persisting the image rotation for other images in the frontend like this; only one value gets stored for each planter so all other rotations will be lost when they refresh (which is annoying for a user).
src/components/ImageScroller.js
Outdated
@@ -147,14 +157,14 @@ export default function ImageScroller(props) { | |||
height={192} | |||
className={classes.image} | |||
fixed | |||
rotation={rotation} | |||
rotation={rotations[idx] ? rotations[idx] : imageRotation} |
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.
I'd suggest reverting back to the single value, but only applying it if this is the selected image.
When the user selects a new image, just reset the rotation to zero.
@@ -108,7 +105,14 @@ const PlanterDetail = (props) => { | |||
return ( | |||
<React.Fragment> | |||
<Drawer anchor="right" open={props.open} onClose={props.onClose}> | |||
<Grid className={classes.root}> | |||
<Grid |
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.
Let's make the container and image square to avoid this awkwardness and inconsistency between rotated and unrotated images.
The planter card can also be updated to use a square image.
I am a bit struggling to remove the white gaps when setting the rotation of image = 90 or 270 deg if I set the images square as you said in Edit Planter dialog. Do you have any suggestions at this? |
@tranquanghuy0801 It seems to be a quirk of the way rotated elements are rendered, presumably due to some rounding in the transform calculation.
|
Resolves #137