Skip to content
Closed
Show file tree
Hide file tree
Changes from 105 commits
Commits
Show all changes
137 commits
Select commit Hold shift + click to select a range
1c6d612
WIP iOS
terrysahaidak Mar 16, 2023
4facf63
iOS version kinda works
terrysahaidak Mar 16, 2023
8034696
Clean up stuff
terrysahaidak Mar 16, 2023
8b13bb5
More clean up
terrysahaidak Mar 17, 2023
135f2f9
More clean up
terrysahaidak Mar 18, 2023
59e97e7
Use state machine
terrysahaidak Mar 21, 2023
2c80f08
Fix formatting issues
terrysahaidak Mar 21, 2023
ad9e6f9
use remoteVariable instead of global in worklets
terrysahaidak Mar 21, 2023
7967c29
Fix crash
terrysahaidak Mar 22, 2023
9fae48f
Improve keyboard handling on iOS
terrysahaidak Mar 23, 2023
5e730d5
Do not blur keyboard when opening emoji picker
terrysahaidak Mar 23, 2023
b086a9b
Add safe area, emoji picker after action sheet handling
terrysahaidak Mar 23, 2023
5e849c9
Add mock file for other platforms
terrysahaidak Mar 23, 2023
b48a65e
Fix bottom inset in keyboard avoiding view
terrysahaidak Mar 23, 2023
1fa4d3f
cleanup
terrysahaidak Mar 23, 2023
b3ec31d
More cleanup; fix other platforms
terrysahaidak Mar 23, 2023
5308a6d
Handle attachments and delete modal
terrysahaidak Mar 24, 2023
3ba462e
Handle attachments long press
terrysahaidak Mar 24, 2023
76b0653
Remove handling edit
terrysahaidak Mar 24, 2023
f44bd06
Fix errors on other platforms
terrysahaidak Mar 27, 2023
7680f97
Merge remote-tracking branch 'upstream/main' into fix/10632-when-long…
terrysahaidak Mar 27, 2023
f1f9c63
More cleanup and some comments
terrysahaidak Mar 27, 2023
0797298
Move files into a folder
terrysahaidak Mar 27, 2023
8a417b8
Merge remote-tracking branch 'upstream/main' into fix/10632-when-long…
terrysahaidak Mar 27, 2023
9f5ebfc
Merge remote-tracking branch 'upstream/main' into fix/10632-when-long…
terrysahaidak Mar 27, 2023
d7d0d87
Fix rebase typo
terrysahaidak Mar 28, 2023
e2af955
Add more comments
terrysahaidak Mar 28, 2023
c5cc218
Fix logging state machine actions
terrysahaidak Mar 29, 2023
68bde8f
Merge remote-tracking branch 'upstream/main' into fix/10632-when-long…
terrysahaidak Mar 29, 2023
d9fa70f
format code consistently
terrysahaidak Mar 29, 2023
4e75927
Handle call popover
terrysahaidak Mar 29, 2023
8f88de1
Refactor code
terrysahaidak Mar 30, 2023
e725644
Add missing actions
terrysahaidak Mar 30, 2023
ceb0df8
Fix crash, use safer useState instead of useMemo
terrysahaidak Apr 3, 2023
bbde049
wip attachment modal handling; some review requests
terrysahaidak Apr 3, 2023
8a02c22
Merge remote-tracking branch 'upstream/main' into fix/10632-when-long…
terrysahaidak Apr 3, 2023
4d2c6dc
Fix crash
terrysahaidak Apr 4, 2023
b4a50f1
Merge remote-tracking branch 'upstream/main' into fix/10632-when-long…
terrysahaidak Apr 27, 2023
61b69df
add prettier as in main
May 19, 2023
31dfdf3
Merge branch 'main' into fix/10632-when-long-press-on-message-add-spa…
May 19, 2023
f6d85cd
fix prettier linting
May 19, 2023
5df5bf4
fix: eslint config
May 19, 2023
69b5789
fix: eslint errors
May 19, 2023
ba77c38
replace KeyboardAvoidingView with new one from REA
May 19, 2023
b7c0912
fix: prettier errors
May 19, 2023
3f43547
Merge branch 'main' into fix/10632-when-long-press-on-message-add-spa…
May 22, 2023
754927a
update codegen pod
May 22, 2023
5596c6f
Merge branch 'main' into fix/10632-when-long-press-on-message-add-spa…
May 23, 2023
3e50f59
fix: merge problems
May 23, 2023
cf4abbf
fix: anchorPosition prop wrong
May 23, 2023
3d66d39
move keyboard events to useAnimatedReaction
May 23, 2023
1fa1806
re-structure state machine
May 23, 2023
57d2653
rename states and actions
May 23, 2023
077140d
move KEYBOARD_POPOVER_OPEN state up
May 23, 2023
046d861
Merge branch 'main' into fix/10632-when-long-press-on-message-add-spa…
Aug 30, 2023
c799dc3
Merge branch 'main' into fix/10632-when-long-press-on-message-add-spa…
Aug 30, 2023
2fe7d91
remove contextType from FC
Aug 30, 2023
c0e7438
chore: update react-native-pdf pod
Aug 30, 2023
a73f905
Merge branch 'main' into fix/10632-when-long-press-on-message-add-spa…
chrispader Sep 12, 2023
b4a15a7
fix: wrong import
chrispader Sep 12, 2023
27c4443
Merge branch 'main' into fix/10632-when-long-press-on-message-add-spa…
kirillzyusko Nov 3, 2023
6011c38
fix: compilation issues after a merge
kirillzyusko Nov 3, 2023
0eb20f3
fix: resolve merge conflicts after a merge
kirillzyusko Nov 20, 2023
0a0a8ed
Merge branch 'main' into fix/10632-when-long-press-on-message-add-spa…
kirillzyusko Jan 12, 2024
9e99895
fix: post merge fixes
kirillzyusko Jan 12, 2024
431a800
fix: crash when long press message
kirillzyusko Jan 12, 2024
124511e
fix: smooth emoji picker transition
kirillzyusko Jan 12, 2024
d5f995b
fix: quick emoji selection crash
kirillzyusko Jan 12, 2024
c617120
fix: don't push message to bottom
kirillzyusko Jan 12, 2024
299ea6c
fix: crash on long press document
kirillzyusko Jan 12, 2024
d178057
fix: click on attachment pushing it down
kirillzyusko Jan 15, 2024
5700381
experimental: use RNKC
kirillzyusko Jan 15, 2024
1cc271c
fix: smooth transition when keyboard gets closed (well, almost smooth…
kirillzyusko Jan 16, 2024
b16b0ac
fix: added missing OPEN_EMOJI_PICKER_POPOVER_STANDALONE
kirillzyusko Jan 17, 2024
563053b
chore: keep intermediate changes
kirillzyusko Jan 17, 2024
e8a37c4
fix: crash when delete confirmation is shown
kirillzyusko Jan 17, 2024
2cc0c58
feat: measure composer
kirillzyusko Jan 17, 2024
d5e820c
fix: correct offset when switch from keyboard to emoji picker
kirillzyusko Jan 17, 2024
b4b2138
fix: 10 magic pixels
kirillzyusko Jan 18, 2024
f0ed950
fix: attachment popover (big screen push up)
kirillzyusko Jan 18, 2024
28129a6
fix: smooth attachment picker+keyboard transitions
kirillzyusko Jan 18, 2024
8e6d06c
fix: unnecessary animation on popover hide (when image is not obscure…
kirillzyusko Jan 18, 2024
5979f87
fix: more clickable message types
kirillzyusko Jan 18, 2024
f8d8fd4
Merge branch 'main' into fix/10632-when-long-press-on-message-add-spa…
kirillzyusko Jan 22, 2024
048d6cc
refactor: partial migration to TS
kirillzyusko Jan 22, 2024
52b3396
fix: wrong calculation sometimes
kirillzyusko Jan 22, 2024
5c94c60
chore: update react-native-keyboard-controller
kirillzyusko Jan 23, 2024
e7110c5
long press on message that will be pushed -> close -> long press on m…
kirillzyusko Jan 23, 2024
a220c07
fix: focus on bottom message -> focus on bottom-1 message -> focus on…
kirillzyusko Jan 23, 2024
a003c8f
fix: when message is not overlapped by action sheet keep it in curren…
kirillzyusko Jan 23, 2024
9efcabd
fix: double transitions when multiline text is covered by keyboard in…
kirillzyusko Jan 23, 2024
51295aa
fix: add animated transition when call popup gets shown
kirillzyusko Jan 23, 2024
dfd7f3e
fix: double transitions when call popup appears
kirillzyusko Jan 24, 2024
71d33b8
fix: enable keyboard-controller only on iOS for now
kirillzyusko Jan 24, 2024
4d047a6
fix: smooth call popover back transitions
kirillzyusko Jan 25, 2024
d4de091
chore: better TS support
kirillzyusko Jan 25, 2024
e057c1e
refactor: create reusable function
kirillzyusko Jan 25, 2024
37f1b79
fix: save keyboard height only before dismiss, since condition is in…
kirillzyusko Jan 25, 2024
d7aed3e
Merge branch 'main' into fix/10632-when-long-press-on-message-add-spa…
kirillzyusko Jan 26, 2024
194f82f
Merge branch 'main' into fix/10632-when-long-press-on-message-add-spa…
kirillzyusko Jan 26, 2024
454575d
chore: changes after self review
kirillzyusko Jan 26, 2024
23ad038
Merge branch 'main' into fix/10632-when-long-press-on-message-add-spa…
kirillzyusko Jan 26, 2024
693981b
fix: react on composer height changes when keyboard is opened to cons…
kirillzyusko Jan 26, 2024
84735e4
chore: restore displayName after incorrect conflicts merges
kirillzyusko Jan 29, 2024
1f492da
Merge branch 'main' into fix/10632-when-long-press-on-message-add-spa…
kirillzyusko Jan 29, 2024
110f10e
chore: changes after review
kirillzyusko Jan 30, 2024
d6f005e
Merge branch 'main' into fix/10632-when-long-press-on-message-add-spa…
kirillzyusko Jan 30, 2024
a639731
chore: remove empty line
kirillzyusko Jan 30, 2024
5c2e0cc
chore: re-generate
kirillzyusko Jan 30, 2024
9454c00
fix: double transitions when call popup is shown
kirillzyusko Jan 31, 2024
85e1082
fix: occasional blinks when keyboard open and message is moving
kirillzyusko Jan 31, 2024
fd33fcc
Merge branch 'main' into fix/10632-when-long-press-on-message-add-spa…
kirillzyusko Feb 1, 2024
43a6c9b
fix: occasional blinks when message is not pushed (on long press)
kirillzyusko Feb 1, 2024
2fdd63e
refactor: useState -> useRef
kirillzyusko Feb 2, 2024
2ed311f
fix: removed unreachable code, better (but not ideal) TS support
kirillzyusko Feb 2, 2024
f55bb14
fix: ts error in context
kirillzyusko Feb 2, 2024
e7f0bc4
fix: better TS support (less TS errors, but we still have them)
kirillzyusko Feb 2, 2024
4feb4d1
fix: occasional content movement when keyboard open & you open bottom…
kirillzyusko Feb 2, 2024
c430dce
Merge branch 'main' into fix/10632-when-long-press-on-message-add-spa…
kirillzyusko Feb 5, 2024
cd2a2e0
chore: removed console.log statements
kirillzyusko Feb 6, 2024
e25d764
Merge branch 'main' into fix/10632-when-long-press-on-message-add-spa…
kirillzyusko Feb 7, 2024
619a1c9
chore: update Podfile.lock
kirillzyusko Feb 7, 2024
92f3592
Merge branch 'main' into fix/10632-when-long-press-on-message-add-spa…
kirillzyusko Feb 26, 2024
8d6bc04
Merge branch 'main' into fix/10632-when-long-press-on-message-add-spa…
kirillzyusko Feb 29, 2024
077be6e
Merge branch 'main' into fix/10632-when-long-press-on-message-add-spa…
kirillzyusko Mar 4, 2024
ad42989
fix: prettier
kirillzyusko Mar 4, 2024
7cbabff
fix: mock for unit tests
kirillzyusko Mar 4, 2024
a17688c
fix: partial TS fixes
kirillzyusko Mar 4, 2024
8920741
fix: prettier
kirillzyusko Mar 4, 2024
6ba15fd
fix: further fixes (CI still will fail, but at least we should have o…
kirillzyusko Mar 4, 2024
77eeb68
fix: eslint issues
kirillzyusko Mar 4, 2024
1611eea
fix: TS issues
kirillzyusko Mar 4, 2024
f1fe95f
fix: lint
kirillzyusko Mar 4, 2024
25332a0
Merge branch 'main' into fix/10632-when-long-press-on-message-add-spa…
kirillzyusko Mar 6, 2024
f4660eb
fix: CI
kirillzyusko Mar 6, 2024
1f0260c
Merge branch 'main' into fix/10632-when-long-press-on-message-add-spa…
kirillzyusko Mar 12, 2024
002505f
fix: prettier
kirillzyusko Mar 12, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1176,6 +1176,8 @@ PODS:
- React-Core
- react-native-key-command (1.0.6):
- React-Core
- react-native-keyboard-controller (1.10.3):
- React-Core
- react-native-netinfo (11.2.1):
- React-Core
- react-native-pager-view (6.2.2):
Expand Down Expand Up @@ -1522,6 +1524,7 @@ DEPENDENCIES:
- "react-native-image-manipulator (from `../node_modules/@oguzhnatly/react-native-image-manipulator`)"
- react-native-image-picker (from `../node_modules/react-native-image-picker`)
- react-native-key-command (from `../node_modules/react-native-key-command`)
- react-native-keyboard-controller (from `../node_modules/react-native-keyboard-controller`)
- "react-native-netinfo (from `../node_modules/@react-native-community/netinfo`)"
- react-native-pager-view (from `../node_modules/react-native-pager-view`)
- react-native-pdf (from `../node_modules/react-native-pdf`)
Expand Down Expand Up @@ -1715,6 +1718,8 @@ EXTERNAL SOURCES:
:path: "../node_modules/react-native-image-picker"
react-native-key-command:
:path: "../node_modules/react-native-key-command"
react-native-keyboard-controller:
:path: "../node_modules/react-native-keyboard-controller"
react-native-netinfo:
:path: "../node_modules/@react-native-community/netinfo"
react-native-pager-view:
Expand Down Expand Up @@ -1909,6 +1914,7 @@ SPEC CHECKSUMS:
react-native-image-manipulator: c48f64221cfcd46e9eec53619c4c0374f3328a56
react-native-image-picker: c33d4e79f0a14a2b66e5065e14946ae63749660b
react-native-key-command: 5af6ee30ff4932f78da6a2109017549042932aa5
react-native-keyboard-controller: 7f36466494e6b8d74f1d786bbd7a40a2273fef94
react-native-netinfo: 8a7fd3f7130ef4ad2fb4276d5c9f8d3f28d2df3d
react-native-pager-view: 02a5c4962530f7efc10dd51ee9cdabeff5e6c631
react-native-pdf: b4ca3d37a9a86d9165287741c8b2ef4d8940c00e
Expand Down
16 changes: 16 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@
"react-native-image-picker": "^5.1.0",
"react-native-image-size": "git+https://github.com/Expensify/react-native-image-size#8393b7e58df6ff65fd41f60aee8ece8822c91e2b",
"react-native-key-command": "^1.0.6",
"react-native-keyboard-controller": "^1.10.3",
"react-native-launch-arguments": "^4.0.2",
"react-native-linear-gradient": "^2.8.1",
"react-native-localize": "^2.2.6",
Expand Down
19 changes: 12 additions & 7 deletions src/App.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import {PortalProvider} from '@gorhom/portal';
import React from 'react';
import {LogBox} from 'react-native';
import {LogBox, Platform} from 'react-native';
import {GestureHandlerRootView} from 'react-native-gesture-handler';
import Onyx from 'react-native-onyx';
import {PickerStateProvider} from 'react-native-picker-select';
import {SafeAreaProvider} from 'react-native-safe-area-context';
import {KeyboardProvider} from 'react-native-keyboard-controller';
import '../wdyr';
import ColorSchemeWrapper from './components/ColorSchemeWrapper';
import ComposeProviders from './components/ComposeProviders';
Expand All @@ -26,6 +27,7 @@ import {WindowDimensionsProvider} from './components/withWindowDimensions';
import Expensify from './Expensify';
import useDefaultDragAndDrop from './hooks/useDefaultDragAndDrop';
import OnyxUpdateManager from './libs/actions/OnyxUpdateManager';
import * as ActionSheetAwareScrollView from './components/ActionSheetAwareScrollView';
import * as Session from './libs/actions/Session';
import * as Environment from './libs/Environment/Environment';
import {ReportAttachmentsProvider} from './pages/home/report/ReportAttachmentsContext';
Expand Down Expand Up @@ -69,14 +71,17 @@ function App() {
PickerStateProvider,
EnvironmentProvider,
CustomStatusBarAndBackgroundContextProvider,
ActionSheetAwareScrollView.ActionSheetAwareScrollViewProvider,
]}
>
<CustomStatusBarAndBackground />
<ErrorBoundary errorMessage="NewExpensify crash caught by error boundary">
<ColorSchemeWrapper>
<Expensify />
</ColorSchemeWrapper>
</ErrorBoundary>
<KeyboardProvider enabled={Platform.OS === "ios"}>
Copy link
Contributor

Choose a reason for hiding this comment

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

I notice you're enabling this only on iOS, but this issue occurs the same on Android as it does on iOS. So I think we'd like to see a consistent approach to keyboard avoidance on all platforms.

Currently, I think we use an unintuitive mix of native and JS-layer keyboard avoidance, and it's inconsistent between platforms.

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, should this be inside the error boundary?

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, should this be inside the error boundary?

I added it to the level of all providers - the reason why it's a separate JSX element because I specify props (enabled) and right now ComposeProviders doesn't have an ability to specify additional props. And as I can see all providers are not under ErrorBoundary.

Would you mind to give a brief explanation why do you think it's worth to put this element under ErrorBoundary?

Currently, I think we use an unintuitive mix of native and JS-layer keyboard avoidance, and it's inconsistent between platforms.

Yes, because an initial PR supported only iOS (from PR description: This PR is iOS only for now. Other platforms are not affected. Also, in this explanation, we are talking about iOS only since on Android, iOS web and Android Web keyboard handling works differently.)

But I agree with you that it would be good to have cross-platform code that handles keyboard interactions. And we actually wanted to suggest to do that, but our vision was to merge this PR first (because it's quite old and contains a lot of changes) and then add Android support in next PRs. What do you think about it?

Copy link
Contributor

Choose a reason for hiding this comment

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

@kirillzyusko lets create a new KeyboardHandlerProvider in components, that returns the <KeyboardProvider with the enabled prop set.
Then we can pass it to ComposeProviders so it's in line with all the other providers

<CustomStatusBarAndBackground />
<ErrorBoundary errorMessage="NewExpensify crash caught by error boundary">
<ColorSchemeWrapper>
<Expensify />
</ColorSchemeWrapper>
</ErrorBoundary>
</KeyboardProvider>
</ComposeProviders>
</GestureHandlerRootView>
);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,198 @@
import noop from "lodash/noop"
import type {PropsWithChildren} from 'react';
import React, { createContext, useMemo} from 'react';
import PropTypes from 'prop-types';

import type { ActionWithPayload, State } from '@hooks/useWorkletStateMachine';
import useWorkletStateMachine from '@hooks/useWorkletStateMachine';
import type { SharedValue } from 'react-native-reanimated';

type Context = {
currentActionSheetState: SharedValue<State>,
transitionActionSheetState: (action: ActionWithPayload) => void,
transitionActionSheetStateWorklet: (action: ActionWithPayload) => void;
resetStateMachine: () => void;
};
const defaultValue: Context = {
currentActionSheetState: {
value: {
previous: null,
current: {
state: 'idle',
payload: null,
},
},
addListener: noop,
removeListener: noop,
modify: noop,
},
transitionActionSheetState: noop,
transitionActionSheetStateWorklet: noop,
resetStateMachine: noop,
};

const ActionSheetAwareScrollViewContext = createContext<Context>(defaultValue);

const Actions = {
OPEN_KEYBOARD: 'KEYBOARD_OPEN',
CLOSE_KEYBOARD: 'CLOSE_KEYBOARD',
OPEN_POPOVER: 'OPEN_POPOVER',
CLOSE_POPOVER: 'CLOSE_POPOVER',
MEASURE_POPOVER: 'MEASURE_POPOVER',
MEASURE_COMPOSER: 'MEASURE_COMPOSER',
POPOVER_ANY_ACTION: 'POPOVER_ANY_ACTION',
OPEN_EMOJI_PICKER_POPOVER: 'OPEN_EMOJI_PICKER_POPOVER',
OPEN_EMOJI_PICKER_POPOVER_STANDALONE: 'OPEN_EMOJI_PICKER_POPOVER_STANDALONE',
CLOSE_EMOJI_PICKER_POPOVER: 'CLOSE_EMOJI_PICKER_POPOVER',
MEASURE_EMOJI_PICKER_POPOVER: 'MEASURE_EMOJI_PICKER_POPOVER',
HIDE_WITHOUT_ANIMATION: 'HIDE_WITHOUT_ANIMATION',
EDIT_REPORT: 'EDIT_REPORT',
SHOW_DELETE_CONFIRM_MODAL: 'SHOW_DELETE_CONFIRM_MODAL',
END_TRANSITION: 'END_TRANSITION',
OPEN_CALL_POPOVER: 'OPEN_CALL_POPOVER',
CLOSE_CONFIRM_MODAL: 'CLOSE_CONFIRM_MODAL',
MEASURE_CONFIRM_MODAL: 'MEASURE_CONFIRM_MODAL',
SHOW_ATTACHMENTS_POPOVER: 'SHOW_ATTACHMENTS_POPOVER',
CLOSE_ATTACHMENTS_POPOVER: 'CLOSE_ATTACHMENTS_POPOVER',
SHOW_ATTACHMENTS_PICKER_POPOVER: 'SHOW_ATTACHMENTS_PICKER_POPOVER',
CLOSE_EMOJI_PICKER_POPOVER_STANDALONE: 'CLOSE_EMOJI_PICKER_POPOVER_STANDALONE',
MEASURE_CALL_POPOVER: 'MEASURE_CALL_POPOVER',
CLOSE_CALL_POPOVER: 'CLOSE_CALL_POPOVER'
};

const States = {
IDLE: 'idle',
KEYBOARD_OPEN: 'keyboardOpen',
POPOVER_OPEN: 'popoverOpen',
POPOVER_CLOSED: 'popoverClosed',
KEYBOARD_POPOVER_CLOSED: 'keyboardPopoverClosed',
KEYBOARD_POPOVER_OPEN: 'keyboardPopoverOpen',
KEYBOARD_CLOSED_POPOVER: 'keyboardClosingPopover',
POPOVER_MEASURED: 'popoverMeasured',
EMOJI_PICKER_POPOVER_OPEN: 'emojiPickerPopoverOpen',
DELETE_MODAL_OPEN: 'deleteModalOpen',
DELETE_MODAL_WITH_KEYBOARD_OPEN: 'deleteModalWithKeyboardOpen',
EMOJI_PICKER_POPOVER_WITH_KEYBOARD_OPEN: 'emojiPickerPopoverWithKeyboardOpen',
EMOJI_PICKER_WITH_KEYBOARD_OPEN: 'emojiPickerWithKeyboardOpen',
CALL_POPOVER_WITH_KEYBOARD_OPEN: 'callPopoverWithKeyboardOpen',
CALL_POPOVER_WITH_KEYBOARD_CLOSED: 'callPopoverWithKeyboardClosed',
ATTACHMENTS_POPOVER_WITH_KEYBOARD_OPEN: 'attachmentsPopoverWithKeyboardOpen',
ATTACHMENTS_POPOVER_WITH_KEYBOARD_CLOSED: 'attachmentsPopoverWithKeyboardClosed',
MODAL_DELETED: 'modalDeleted',
MODAL_WITH_KEYBOARD_OPEN_DELETED: 'modalWithKeyboardOpenDeleted'
};

const STATE_MACHINE = {
[States.IDLE]: {
[Actions.OPEN_POPOVER]: States.POPOVER_OPEN,
[Actions.OPEN_KEYBOARD]: States.KEYBOARD_OPEN,
[Actions.MEASURE_POPOVER]: States.IDLE,
[Actions.MEASURE_COMPOSER]: States.IDLE,
[Actions.OPEN_EMOJI_PICKER_POPOVER]: States.EMOJI_PICKER_POPOVER_OPEN,
[Actions.SHOW_ATTACHMENTS_PICKER_POPOVER]: States.ATTACHMENTS_POPOVER_WITH_KEYBOARD_OPEN,
},
[States.POPOVER_OPEN]: {
[Actions.CLOSE_POPOVER]: States.POPOVER_CLOSED,
[Actions.MEASURE_POPOVER]: States.POPOVER_OPEN,
[Actions.MEASURE_COMPOSER]: States.POPOVER_OPEN,
[Actions.OPEN_EMOJI_PICKER_POPOVER]: States.EMOJI_PICKER_POPOVER_OPEN,
[Actions.POPOVER_ANY_ACTION]: States.POPOVER_CLOSED,
[Actions.HIDE_WITHOUT_ANIMATION]: States.IDLE,
[Actions.EDIT_REPORT]: States.IDLE,
[Actions.SHOW_DELETE_CONFIRM_MODAL]: States.MODAL_DELETED,
},
[States.POPOVER_CLOSED]: {
[Actions.END_TRANSITION]: States.IDLE,
},
[States.EMOJI_PICKER_POPOVER_OPEN]: {
[Actions.MEASURE_EMOJI_PICKER_POPOVER]: States.EMOJI_PICKER_POPOVER_OPEN,
[Actions.CLOSE_EMOJI_PICKER_POPOVER]: States.POPOVER_CLOSED,
},
[States.MODAL_DELETED]: {
[Actions.MEASURE_CONFIRM_MODAL]: States.MODAL_DELETED,
[Actions.CLOSE_CONFIRM_MODAL]: States.POPOVER_CLOSED,
},
[States.KEYBOARD_OPEN]: {
[Actions.OPEN_KEYBOARD]: States.KEYBOARD_OPEN,
[Actions.OPEN_POPOVER]: States.KEYBOARD_POPOVER_OPEN,
[Actions.OPEN_EMOJI_PICKER_POPOVER]: States.KEYBOARD_POPOVER_OPEN,
[Actions.OPEN_EMOJI_PICKER_POPOVER_STANDALONE]: States.EMOJI_PICKER_WITH_KEYBOARD_OPEN,
[Actions.CLOSE_KEYBOARD]: States.IDLE,
[Actions.OPEN_CALL_POPOVER]: States.CALL_POPOVER_WITH_KEYBOARD_OPEN,
[Actions.SHOW_ATTACHMENTS_POPOVER]: States.ATTACHMENTS_POPOVER_WITH_KEYBOARD_OPEN,
[Actions.SHOW_ATTACHMENTS_PICKER_POPOVER]: States.ATTACHMENTS_POPOVER_WITH_KEYBOARD_OPEN,
[Actions.MEASURE_COMPOSER]: States.KEYBOARD_OPEN,
},
[States.KEYBOARD_POPOVER_OPEN]: {
[Actions.MEASURE_POPOVER]: States.KEYBOARD_POPOVER_OPEN,
[Actions.MEASURE_COMPOSER]: States.KEYBOARD_POPOVER_OPEN,
[Actions.CLOSE_POPOVER]: States.KEYBOARD_CLOSED_POPOVER,
[Actions.CLOSE_EMOJI_PICKER_POPOVER]: States.KEYBOARD_CLOSED_POPOVER,
[Actions.MEASURE_EMOJI_PICKER_POPOVER]: States.KEYBOARD_POPOVER_OPEN,
[Actions.OPEN_EMOJI_PICKER_POPOVER]: States.EMOJI_PICKER_POPOVER_WITH_KEYBOARD_OPEN,
[Actions.SHOW_DELETE_CONFIRM_MODAL]: States.MODAL_WITH_KEYBOARD_OPEN_DELETED,
},
[States.MODAL_WITH_KEYBOARD_OPEN_DELETED]: {
[Actions.MEASURE_CONFIRM_MODAL]: States.MODAL_WITH_KEYBOARD_OPEN_DELETED,
[Actions.CLOSE_CONFIRM_MODAL]: States.KEYBOARD_CLOSED_POPOVER,
},
[States.EMOJI_PICKER_POPOVER_WITH_KEYBOARD_OPEN]: {
[Actions.MEASURE_EMOJI_PICKER_POPOVER]: States.EMOJI_PICKER_POPOVER_WITH_KEYBOARD_OPEN,
[Actions.CLOSE_EMOJI_PICKER_POPOVER]: States.KEYBOARD_CLOSED_POPOVER,
},
[States.EMOJI_PICKER_WITH_KEYBOARD_OPEN]: {
[Actions.MEASURE_EMOJI_PICKER_POPOVER]: States.EMOJI_PICKER_WITH_KEYBOARD_OPEN,
[Actions.CLOSE_EMOJI_PICKER_POPOVER_STANDALONE]: States.KEYBOARD_POPOVER_CLOSED,
},
[States.CALL_POPOVER_WITH_KEYBOARD_OPEN]: {
[Actions.MEASURE_POPOVER]: States.CALL_POPOVER_WITH_KEYBOARD_OPEN,
[Actions.MEASURE_CALL_POPOVER]: States.CALL_POPOVER_WITH_KEYBOARD_OPEN,
[Actions.CLOSE_CALL_POPOVER]: States.CALL_POPOVER_WITH_KEYBOARD_CLOSED,
},
[States.CALL_POPOVER_WITH_KEYBOARD_CLOSED]: {
[Actions.OPEN_KEYBOARD]: States.KEYBOARD_OPEN,
},
[States.ATTACHMENTS_POPOVER_WITH_KEYBOARD_OPEN]: {
[Actions.MEASURE_POPOVER]: States.ATTACHMENTS_POPOVER_WITH_KEYBOARD_OPEN,
[Actions.MEASURE_COMPOSER]: States.ATTACHMENTS_POPOVER_WITH_KEYBOARD_OPEN,
[Actions.CLOSE_ATTACHMENTS_POPOVER]: States.ATTACHMENTS_POPOVER_WITH_KEYBOARD_CLOSED,
},
[States.ATTACHMENTS_POPOVER_WITH_KEYBOARD_CLOSED]: {
[Actions.OPEN_KEYBOARD]: States.KEYBOARD_OPEN,
},
[States.KEYBOARD_POPOVER_CLOSED]: {
[Actions.OPEN_KEYBOARD]: States.KEYBOARD_OPEN,
},
[States.KEYBOARD_CLOSED_POPOVER]: {
[Actions.OPEN_KEYBOARD]: States.KEYBOARD_OPEN,
[Actions.END_TRANSITION]: States.KEYBOARD_OPEN,
},
};

function ActionSheetAwareScrollViewProvider(props: PropsWithChildren<unknown>) {
const {currentState, transition, transitionWorklet, reset} = useWorkletStateMachine(STATE_MACHINE, {
previous: null,
current: {
state: 'idle',
payload: null,
},
});

const value = useMemo(
() => ({
currentActionSheetState: currentState,
transitionActionSheetState: transition,
transitionActionSheetStateWorklet: transitionWorklet,
resetStateMachine: reset,
}),
[currentState, reset, transition, transitionWorklet],
);

return <ActionSheetAwareScrollViewContext.Provider value={value}>{props.children}</ActionSheetAwareScrollViewContext.Provider>;
}

ActionSheetAwareScrollViewProvider.propTypes = {
children: PropTypes.node.isRequired,
};

export {ActionSheetAwareScrollViewContext, ActionSheetAwareScrollViewProvider, Actions, States};
Loading