Page MenuHomePhabricator

[native] Migrate orientation logic in FullScreenViewModal to functional component
ClosedPublic

Authored by angelika on Feb 6 2025, 5:00 PM.
Tags
None
Referenced Files
F5297586: D14298.id47180.diff
Mon, Apr 7, 9:43 PM
Unknown Object (File)
Fri, Mar 14, 7:59 AM
Unknown Object (File)
Fri, Mar 14, 7:59 AM
Unknown Object (File)
Fri, Mar 14, 7:59 AM
Unknown Object (File)
Tue, Mar 11, 4:14 PM
Unknown Object (File)
Tue, Mar 11, 4:13 PM
Unknown Object (File)
Tue, Mar 11, 3:50 PM
Unknown Object (File)
Tue, Mar 11, 3:40 PM
Subscribers

Diff Detail

Repository
rCOMM Comm
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

angelika held this revision as a draft.
tomek added inline comments.
native/components/full-screen-view-modal.react.js
1242 ↗(On Diff #47076)

We're replacing an invariant with an if condition. Is it intentional?

1254 ↗(On Diff #47076)

I'm not sure if it matters, but in the original code this was conditional.

This revision is now accepted and ready to land.Feb 13 2025, 10:24 AM
native/components/full-screen-view-modal.react.js
1244–1256 ↗(On Diff #47076)

I wonder if a single effect would be cleaner:

React.useEffect(() => {
  if (isActive) {
    Orientation.unlockAllOrientations();
  } else {
    Orientation.lockToPortrait();
  }
  return () => {
    if (isActive) {
      Orientation.lockToPortrait();
    };
  };
}, [isActive]);
native/components/full-screen-view-modal.react.js
1244–1256 ↗(On Diff #47076)

Arguably it could be even more simple:

React.useEffect(() => {
  if (!isActive) {
    return undefined;
  }
  Orientation.unlockAllOrientations();
  return () => {
    Orientation.lockToPortrait();
  };
}, [isActive]);
angelika added inline comments.
native/components/full-screen-view-modal.react.js
1242 ↗(On Diff #47076)

replaced with an invariant

1244–1256 ↗(On Diff #47076)

We had similar discussions here and a couple of versions: https://phab.comm.dev/D14221 and we finally ended up with this version. In your version if isActive changes, the cleanup is run first then the effect and it's messy. In the version in the diff it's really clear:

  • if modal is active then unlock orientation
  • if modal is not active then lock orientation
  • on onmount just lock orientation no matter what (in the original code there is an if but we can omit it as I explained in comment above)
1254 ↗(On Diff #47076)

It doesn't really matter, if isActive is false, then we had called lockToPortrait before and here we call it again. I don't see anything wrong with calling it twice in a row.

native/components/full-screen-view-modal.react.js
1244–1256 ↗(On Diff #47076)

In your version if isActive changes, the cleanup is run first then the effect and it's messy.

Not sure I agree that it's messy, but I don't feel strongly

angelika marked an inline comment as done.

Rebase