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

Add tap to focus and fix orientation #35014

Merged
merged 2 commits into from
Feb 2, 2024

Conversation

janicduplessis
Copy link
Contributor

@janicduplessis janicduplessis commented Jan 23, 2024

Details

This adds tap to focus on iOS and Android for the scan receipt camera. It also adds a focus indicator to have some feedback of the focus, I made it similar to the IG camera.

Note that this only affects native iOS and Android. As far as I know browser apis have no way to control camera focus.

Fixed Issues

$ #34898
PROPOSAL: N/A

Tests

  • Verify that no errors appear in the JS console

Offline tests

QA Steps

  1. Log in to an account
  2. In the + menu tap Request money
  3. You can now tap on the camera preview to focus different areas

Orientation fix:

  1. on iOS, rotate the phone to landscape
  2. Verify the UI does not rotate
  3. Verify the camera also does not rotate
  4. Take a picture
  5. verify the picture is taken in portrait mode
  • Verify that no errors appear in the JS console

PR Author Checklist

  • I linked the correct issue in the ### Fixed Issues section above
  • I wrote clear testing steps that cover the changes made in this PR
    • I added steps for local testing in the Tests section
    • I added steps for the expected offline behavior in the Offline steps section
    • I added steps for Staging and/or Production testing in the QA steps section
    • I added steps to cover failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
    • I tested this PR with a High Traffic account against the staging or production API to ensure there are no regressions (e.g. long loading states that impact usability).
  • I included screenshots or videos for tests on all platforms
  • I ran the tests on all platforms & verified they passed on:
    • Android: Native
    • Android: mWeb Chrome
    • iOS: Native
    • iOS: mWeb Safari
    • MacOS: Chrome / Safari
    • MacOS: Desktop
  • I verified there are no console errors (if there's a console error not related to the PR, report it or open an issue for it to be fixed)
  • I followed proper code patterns (see Reviewing the code)
    • I verified that any callback methods that were added or modified are named for what the method does and never what callback they handle (i.e. toggleReport and not onIconClick)
    • I verified that the left part of a conditional rendering a React component is a boolean and NOT a string, e.g. myBool && <MyComponent />.
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • I verified any copy / text shown in the product is localized by adding it to src/languages/* files and using the translation method
      • If any non-english text was added/modified, I verified the translation was requested/reviewed in #expensify-open-source and it was approved by an internal Expensify engineer. Link to Slack message:
    • I verified all numbers, amounts, dates and phone numbers shown in the product are using the localization methods
    • I verified any copy / text that was added to the app is grammatically correct in English. It adheres to proper capitalization guidelines (note: only the first word of header/labels should be capitalized), and is approved by marketing by adding the Waiting for Copy label for a copy review on the original GH to get the correct copy.
    • I verified proper file naming conventions were followed for any new files or renamed files. All non-platform specific files are named after what they export and are not named "index.js". All platform-specific files are named for the platform the code supports as outlined in the README.
    • I verified the JSDocs style guidelines (in STYLE.md) were followed
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I followed the guidelines as stated in the Review Guidelines
  • I tested other components that can be impacted by my changes (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar are working as expected)
  • I verified all code is DRY (the PR doesn't include any logic written more than once, with the exception of tests)
  • I verified any variables that can be defined as constants (ie. in CONST.js or at the top of the file that uses the constant) are defined as such
  • I verified that if a function's arguments changed that all usages have also been updated correctly
  • If any new file was added I verified that:
    • The file has a description of what it does and/or why is needed at the top of the file if the code is not self explanatory
  • If a new CSS style is added I verified that:
    • A similar style doesn't already exist
    • The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(theme.componentBG))
  • If the PR modifies code that runs when editing or sending messages, I tested and verified there is no unexpected behavior for all supported markdown - URLs, single line code, code blocks, quotes, headings, bold, strikethrough, and italic.
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • If the PR modifies a component or page that can be accessed by a direct deeplink, I verified that the code functions as expected when the deeplink is used - from a logged in and logged out account.
  • If the PR modifies the form input styles:
    • I verified that all the inputs inside a form are aligned with each other.
    • I added Design label so the design team can review the changes.
  • If a new page is added, I verified it's using the ScrollView component to make it scrollable when more elements are added to the page.
  • If the main branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to the Test steps.

Screenshots/Videos

Android: Native
Screen_Recording_20240127_150658_New.Expensify.Dev.2.mp4
Android: mWeb Chrome

N/A

iOS: Native
RPReplay_Final1706051928.mov
iOS: mWeb Safari

N/A

MacOS: Chrome / Safari

N/A

MacOS: Desktop

N/A

@janicduplessis janicduplessis marked this pull request as ready for review January 27, 2024 20:25
@janicduplessis janicduplessis requested a review from a team as a code owner January 27, 2024 20:25
@melvin-bot melvin-bot bot removed the request for review from a team January 27, 2024 20:25
Copy link

melvin-bot bot commented Jan 27, 2024

@ishpaul777 Please copy/paste the Reviewer Checklist from here into a new comment on this PR and complete it. If you have the K2 extension, you can simply click: [this button]

@melvin-bot melvin-bot bot requested a review from ishpaul777 January 27, 2024 20:26
@ishpaul777
Copy link
Contributor

ishpaul777 commented Jan 27, 2024

@janicduplessis Can you please guide me through the steps to build the ios app of physical device. I couldn't figure it out on my own

@janicduplessis
Copy link
Contributor Author

Hey @ishpaul777! Not sure if there is an easier way, but what I did is use my own developer account to sign the app and run it on device. You can do it with the following changes:

  • Open the app in xcode
  • Go to Signing and Capabilities then in the section called Signing (DebugDevelopment and ReleaseDevelopment)
image
  • Check enable automatically singing
  • Pick your personal team
  • Change the bundle identifier to something unique like com.yourname.expensify.chat.dev
image
  • Go to the NotificationService target and repeat the last 3 steps
image
  • Go back to NewExpensify target and scroll down
  • Remove Associated Domains, Communication Notifications, Push Notifications and Sign In With Apple capabilities

Then it should build, you might need to authorize your dev account on your phone, it should tell you how to when you run the app the first time.

@ishpaul777
Copy link
Contributor

Thanks for detailed steps @janicduplessis, I am able to build the app successfully 🎉

@ishpaul777
Copy link
Contributor

A kind request, Can you please add steps for local and QA testing

@janicduplessis
Copy link
Contributor Author

I added the steps in the PR description, lmk if it is clear.

@mountiny
Copy link
Contributor

@ishpaul777 added test steps for the orientation fix

@ishpaul777
Copy link
Contributor

ishpaul777 commented Jan 29, 2024

Thanks for adding steps @mountiny @janicduplessis!

Focus seems to be working as expected, and App ui does not rotate. But the camera still rotates and picture is not taken in portrait.

  • on iOS, rotate the phone to landscape
  • Verify the UI does not rotate
  • Verify the camera also does not rotate
  • Take a picture
  • verify the picture is taken in portrait mode
RPReplay_Final1706525483.MP4

@mountiny
Copy link
Contributor

@ishpaul777 this is the issue in main currently:

RPReplay_Final1706528549.mp4

The problem seems to be not really a landscape/ portrait but if the phone is laying flat or standing, then the angle changes 🤔

Honestly in your video it seems fine, can you also test laying the phone flat and then straighten it up?

@mountiny
Copy link
Contributor

Even the picture was taken correctly I think

@ishpaul777
Copy link
Contributor

Sorry, maybe i misunderstood the problem, i'll test again 👍

@ishpaul777
Copy link
Contributor

The problem was with auto-rotation turned off in settings, so i never faced the issue on main. Now it seems to work well when auto rotation is on the issue on main Is fixed 🎉

The behaviour in video #35014 (comment) seems correct now i fully understand the issue 👍 Sorry for misunderstanding

@mountiny
Copy link
Contributor

Yeah sorry it's hard to explain so I included the video :D

@mountiny
Copy link
Contributor

Thanks! Sounds like we can do the checklist now, thanks for a quick turn around

@ishpaul777
Copy link
Contributor

ishpaul777 commented Jan 29, 2024

Reviewer Checklist

  • I have verified the author checklist is complete (all boxes are checked off).
  • I verified the correct issue is linked in the ### Fixed Issues section above
  • I verified testing steps are clear and they cover the changes made in this PR
    • I verified the steps for local testing are in the Tests section
    • I verified the steps for Staging and/or Production testing are in the QA steps section
    • I verified the steps cover any possible failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
  • I checked that screenshots or videos are included for tests on all platforms
  • I included screenshots or videos for tests on all platforms
  • I verified tests pass on all platforms & I tested again on:
    • Android: Native
    • Android: mWeb Chrome
    • iOS: Native
    • iOS: mWeb Safari
    • MacOS: Chrome / Safari
    • MacOS: Desktop
  • If there are any errors in the console that are unrelated to this PR, I either fixed them (preferred) or linked to where I reported them in Slack
  • I verified proper code patterns were followed (see Reviewing the code)
    • I verified that any callback methods that were added or modified are named for what the method does and never what callback they handle (i.e. toggleReport and not onIconClick).
    • I verified that the left part of a conditional rendering a React component is a boolean and NOT a string, e.g. myBool && <MyComponent />.
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • I verified any copy / text shown in the product is localized by adding it to src/languages/* files and using the translation method
    • I verified all numbers, amounts, dates and phone numbers shown in the product are using the localization methods
    • I verified any copy / text that was added to the app is grammatically correct in English. It adheres to proper capitalization guidelines (note: only the first word of header/labels should be capitalized), and is approved by marketing by adding the Waiting for Copy label for a copy review on the original GH to get the correct copy.
    • I verified proper file naming conventions were followed for any new files or renamed files. All non-platform specific files are named after what they export and are not named "index.js". All platform-specific files are named for the platform the code supports as outlined in the README.
    • I verified the JSDocs style guidelines (in STYLE.md) were followed
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I verified that this PR follows the guidelines as stated in the Review Guidelines
  • I verified other components that can be impacted by these changes have been tested, and I retested again (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar have been tested & I retested again)
  • I verified all code is DRY (the PR doesn't include any logic written more than once, with the exception of tests)
  • I verified any variables that can be defined as constants (ie. in CONST.js or at the top of the file that uses the constant) are defined as such
  • If a new component is created I verified that:
    • A similar component doesn't exist in the codebase
    • All props are defined accurately and each prop has a /** comment above it */
    • The file is named correctly
    • The component has a clear name that is non-ambiguous and the purpose of the component can be inferred from the name alone
    • The only data being stored in the state is data necessary for rendering and nothing else
    • For Class Components, any internal methods passed to components event handlers are bound to this properly so there are no scoping issues (i.e. for onClick={this.submit} the method this.submit should be bound to this in the constructor)
    • Any internal methods bound to this are necessary to be bound (i.e. avoid this.submit = this.submit.bind(this); if this.submit is never passed to a component event handler like onClick)
    • All JSX used for rendering exists in the render method
    • The component has the minimum amount of code necessary for its purpose, and it is broken down into smaller components in order to separate concerns and functions
  • If any new file was added I verified that:
    • The file has a description of what it does and/or why is needed at the top of the file if the code is not self explanatory
  • If a new CSS style is added I verified that:
    • A similar style doesn't already exist
    • The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(theme.componentBG)
  • If the PR modifies code that runs when editing or sending messages, I tested and verified there is no unexpected behavior for all supported markdown - URLs, single line code, code blocks, quotes, headings, bold, strikethrough, and italic.
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • If the PR modifies a component or page that can be accessed by a direct deeplink, I verified that the code functions as expected when the deeplink is used - from a logged in and logged out account.
  • If the PR modifies the form input styles:
    • I verified that all the inputs inside a form are aligned with each other.
    • I added Design label so the design team can review the changes.
  • If a new page is added, I verified it's using the ScrollView component to make it scrollable when more elements are added to the page.
  • If the main branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to the Test steps.
  • I have checked off every checkbox in the PR reviewer checklist, including those that don't apply to this PR.

Screenshots/Videos

Android: Native
Record_2024-02-01-18-38-03.mp4
iOS: Native
1ca1c6a0-eeb9-47eb-ae01-01db417daadf.mp4

@janicduplessis
Copy link
Contributor Author

@mountiny I completely forgot about the orientation fix, thanks!

@ishpaul777
Copy link
Contributor

ishpaul777 commented Jan 29, 2024

Works well in android 🎉!

Video:

Record_2024-01-29-22-03-23.mp4

However, there was a warning:

Warning

Screenshot_2024-01-29-22-12-46-34_40d2c9e2d8fb5b5aba3904834590021e.jpg

@janicduplessis
Copy link
Contributor Author

I will look into the warning

@mountiny
Copy link
Contributor

Any updates on the warning?

@janicduplessis
Copy link
Contributor Author

I checked with Marc, the author of vision camera and seems to also think the warning is harmless and can just be ignored. I will verify that later today and add code to just ignore it.

@janicduplessis
Copy link
Contributor Author

I added code to ignore the warning, it happens when focusing very quickly and doesn't cause any issues.

@mountiny
Copy link
Contributor

mountiny commented Feb 1, 2024

@ishpaul777 can you please finish the review now? The reassure tests are known, unrelated

@ishpaul777
Copy link
Contributor

On it!

Copy link
Contributor

@ishpaul777 ishpaul777 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good :shipit:

@melvin-bot melvin-bot bot requested a review from mountiny February 1, 2024 13:15
Copy link
Contributor

@mountiny mountiny left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really nice, thank you!!!

@mountiny mountiny merged commit d968010 into Expensify:main Feb 2, 2024
15 of 16 checks passed
@melvin-bot melvin-bot bot added the Emergency label Feb 2, 2024
Copy link

melvin-bot bot commented Feb 2, 2024

@mountiny looks like this was merged without a test passing. Please add a note explaining why this was done and remove the Emergency label if this is not an emergency.

@mountiny mountiny removed the Emergency label Feb 2, 2024
@mountiny
Copy link
Contributor

mountiny commented Feb 2, 2024

Knwown reassure failure that is resolved on main

@OSBotify
Copy link
Contributor

OSBotify commented Feb 2, 2024

✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release.

@janicduplessis janicduplessis deleted the @janic/camera-fixes branch February 2, 2024 01:04
@OSBotify
Copy link
Contributor

OSBotify commented Feb 5, 2024

🚀 Deployed to production by https://github.com/marcaaron in version: 1.4.36-5 🚀

platform result
🤖 android 🤖 success ✅
🖥 desktop 🖥 success ✅
🍎 iOS 🍎 failure ❌
🕸 web 🕸 success ✅

@mountiny
Copy link
Contributor

mountiny commented Feb 6, 2024

@janicduplessis this seems not to be working for me on iOS, should be in prod already, can you test?

RPReplay_Final1707235727.mp4

@janicduplessis
Copy link
Contributor Author

It is kind of hard to test, I think if you angle it with something close and far you should be able to see the focus change. I think the issue you might experience is that we currently only use one camera (I think ultrawide). New iphones usually have one that is better at very close pictures so maybe we could allow it to be used.

@mountiny
Copy link
Contributor

mountiny commented Feb 6, 2024

New iphones usually have one that is better at very close pictures so maybe we could allow it to be used.

Interesting. We need to do something about this for sure as its been couple of people who tried and did not find it working.

How can we achieve it to behave "same" as the built-in camera focus?

@mrousavy
Copy link
Contributor

mrousavy commented Feb 6, 2024

I believe we could use the setPrimaryConstituentDeviceSwitchingBehavior(_:restrictedSwitchingBehaviorConditions:) API from AVFoundation to have it automatically zoom out to the ultra-wide-angle-camera (aka "macro-lens") when something is too close to focus on?

@mrousavy
Copy link
Contributor

mrousavy commented Feb 6, 2024

This is not part of VisionCamera V3 or V2 yet. @janicduplessis wanna just try adding that to the AVCaptureDevice setup code and see if that does anything?

Effectively under the hood this should only switch to the ultra-wide-angle-camera when something is too close to focus on, while still staying at the same zoom factor.

Without this API, we can only zoom out to switch to the ultra-wide, technically not achieving the same behaviour

@mrousavy
Copy link
Contributor

mrousavy commented Feb 6, 2024

I heard about this in this Apple Developer Forums post, and I think the way the iOS stock Camera achieves it is by

  1. zooming "out" to the ultra-wide camera (in VisionCamera terms; zoom={device.minZoom})
  2. locking the device to stay at the ultra-wide camera and prevent it from switching over to the other cameras (setPrimaryConstituentDeviceSwitchingBehavior(.locked, ...))
  3. setting the zoom back to it's value what it was before step 1

I am not sure how that'll work on the implementation though as we need to await until the Camera switches over to the ultra-wide before we lock the switching behaviour.

As an alternative, we can just always use the ultra-wide angle which has a closer minFocusDistance, but that probably looks weird to users, no?

@janicduplessis
Copy link
Contributor Author

My initial thought was to use dual-wide-camera instead of just wide-angle-camera so it can switch automatically between the 2.

@janicduplessis
Copy link
Contributor Author

@mrousavy The api you are suggesting would make it so it only changes to ultra-wide if the thing is too close to focus, instead of switching automatically like when using dual-wide-camera?

@mrousavy
Copy link
Contributor

mrousavy commented Feb 6, 2024

Yea kinda, I think this is how the "Macro Mode" in the stock iOS camera works (the little flower icon at the bottom left if you are close to a subject).

If we use the dual-wide-camera then the user can manually zoom out to achieve the same behaviour. If that's fine, that would take 5 seconds to implement, whereas the other API could take a few hours.

@janicduplessis
Copy link
Contributor Author

When I tested last time using tap to focus or getting really close would cause it to change automatically from what I remember.

@janicduplessis
Copy link
Contributor Author

I think this might be a good solution for now, and we can look at more complex solutions if we still have issues.

@mountiny
Copy link
Contributor

mountiny commented Feb 6, 2024

Interesting, I would say we need to optimize for receipt scanning in this case so that is usually taking picture from close distance so if its hard to make the focus work for all proximities of the object from camera, we should ideally do the macro case first

@janicduplessis
Copy link
Contributor Author

I can try allowing both extra-wide and wide cameras and we can test if that works well. If we are not satisfied we can explore more advanced apis @mrousavy mentionned.

@janicduplessis
Copy link
Contributor Author

I opened a PR with the change to use dual wide camera if you want to try it. #35926

I will test it more in the next few days.

@mrousavy
Copy link
Contributor

mrousavy commented Feb 6, 2024

When I tested last time using tap to focus or getting really close would cause it to change automatically from what I remember.

Oh well then that's even better! AVFoundation positively surprising, as always

@ishpaul777
Copy link
Contributor

hey @mountiny, sorry for delayed response i was afk, i was able to reproduce the issue only when we the camera is closer to the subject but i didn't raised it as it was the same behaviour for the native camera on normal mode so assumed it to be expected. lmk, if i should start testing the other PR

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

Successfully merging this pull request may close these issues.

5 participants