-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
When you long-press on a message in iOS mobile, the message moves out of the screen frame and is hidden (iOS only) #16356
Conversation
CLA Assistant Lite bot All contributors have signed the CLA ✍️ ✅ |
I have read the CLA Document and I hereby sign the CLA |
recheck |
…-press-on-message-add-space-for-image
…-press-on-message-add-space-for-image
…-press-on-message-add-space-for-image
Assigning a C+ here as well |
@shubham1206agra I think before you dive in here, we should wait for consensus on #35270 |
…nly TS errors (14))
|
popoverHeight?: number; | ||
height?: number; | ||
composerHeight?: number; | ||
}; |
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.
Nit: Add a blank line? Here and other similar places. I think we do that in general.
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.
In this file and other files
|
||
const invertedKeyboardHeight = keyboard.state.value === KeyboardState.CLOSED ? lastKeyboardHeight : 0; | ||
|
||
let elementOffset = 0; |
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.
const
+ ternary?- ...or a local function?
// when the sate is not idle we know for sure we have previous state | ||
const previousPayload = previous.payload ?? {}; | ||
|
||
let previousElementOffset = 0; |
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.
const
+ ternary?- ...or a local function?
I understand that this is conflict-prone. So I guess we'll need to parallelize review and testing with conflict resolution. @kirillzyusko Would you handle minor comments I left and ensure to keep all commits signed? We'll need at least one force-push to fix the commit signing thing. |
@cubuspl42 @roryabraham I couldn't sign unsigned commits 😔 All ways come to rebase - and it's close to unreal to rebase 137 commits over 50000 other commits (we literally have incompatible changes even in first commit, because from 5 modified files 4 were removed (migrated to TS I guess) - so it's unbelievably difficult to rebase these changes to latest branch. I suggest to keep this PR in the current shape and move all work in a new PR with squashed commit - #38232 Such approach has several benefits:
Let me know what do you think 😊 |
@cubuspl42 yeah, sure, let's come to conclusion what should we od with unsigned commits and then I'll address your comments 👍 |
Expensify has a policy of accepting only signed commits to the From my perspective, squashing is fine. |
Yeah, I know - and I agree that it's not exceptional situation, that's why I proposed squashing and new PR (to keep history of changes) 😅 Waiting for @roryabraham feedback 👀 |
closing this in favor of #38232 |
Details
Important notice
Important
This PR relies on
react-native-keyboard-controller
(useKeyboardHandler
) hook andKeyboardAvoidingView
component).How it works 🤔
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.
Note
We're talking about default platform behavior. If we start to use
react-native-keyboard-controller
on Android - it'll disable all default keyboard handling by OS and will delegate the keyboard handling to us - so we will have identical behavior across both iOS/Android platforms.But it may introduce additional issues (because we need to enter edge-to-edge mode - that would be good to do on entire app level, but it may bring some issues with
StatusBar
paddings, so everything has to be verified very carefully). That's why I think it would be better to handle in separate PR.When we long press on a message, we want to be able to see it. It's easy when we have the keyboard closed. But gets tricky when the keyboard is open.
But first of all let's focus on the case when the keyboard is closed. User long press on the message, we render the bottom sheet (action sheet) with some options. If the message is higher than the height of bottom sheet - the message is visible. When the message is the last one (first from the bottom), it can be fully or partially covered by the bottom sheet.
Press to see videos
Simulator.Screen.Recording.-.iPhone.15.Pro.-.2024-01-29.at.14.41.55.mp4
Simulator.Screen.Recording.-.iPhone.15.Pro.-.2024-01-29.at.14.42.56.mp4
Also everything is tricky when we have keyboard open 😓
Press to see videos with keyboard
Simulator.Screen.Recording.-.iPhone.15.Pro.-.2024-01-29.at.14.47.17.mp4
Simulator.Screen.Recording.-.iPhone.15.Pro.-.2024-01-29.at.14.49.27.mp4
To achieve this goal we had to:
FlatList
ofReportListView
(it usesreanimated
to move the view by the offset)KeyboardAvoiding
so we're in sync with keyboard-avoiding style updatesActionSheetAwareScrollViewContext
to pass the transition function, so we can transition from one state to another by action triggered from different parts of the applicationBelow you can find more use cases that involves keyboard and other UI elements interactions:
Interactions with other UI elements
Simulator.Screen.Recording.-.iPhone.15.Pro.-.2024-01-29.at.14.51.22.mp4
Simulator.Screen.Recording.-.iPhone.15.Pro.-.2024-01-29.at.14.52.04.mp4
Note
Call popover, bottom sheet and emoji picker are implemented as Modal windows and on iOS keyboard instantly gets hidden when modal window is shown. But "Attachment" popup is implemented not as modal, so for this type of transition we are using
progress
-based animations. When we press on plus -> popup is already shown under keyboard and we dismiss the keyboard. Overall the mechanism is similar to what we've used in the past, except the moment where we substitutetranslationY
value - in case when keyboard disappear/appears we interpolate it byprogress
variable to achieve smooth transitions.Technical details ⚒️
So in order to calculate the offset for the message, we:
ref.current.measureInWindow
, so we can haveheight
andy
coordinate of the imageonLayout
callbackDimensions
safeArea.top
sincey
coordinate doesn't get into account safe areaelementOffset = (y + safeArea.top + itemHeight) - (windowHeight - popoverHeight)
In order to animate item when they keyboard was open, we need to also know its height which is provided by useAnimatedKeyboard hook from react-native-reanimated, but we should always subtract safeArea.bottom from it since it's not part of the calculation for the offset, but only keyboardHeight.
Overall, the keyboard is the tricky part. On iOS, the keyboard doesn't resize the viewport. So for the content to not be covered by the keyboard,
KeyboardAvoidingView
is used. In React Native,KeyboardAvoidingView
is implemented as a view that changes its height or resizes the children's view by the keyboard height. It's done using RN's Layout Animations. This results in the animation for the keyboard being applied using the native event emitter callback which uses the bridge. So open/close events of the keyboard will always be delayed that resulting in the delayed keyboard avoiding animation and, which is more important, scheduling layout animations.In order to be consistent 100% of the time with animation and timings, we had to:
KeyboardAvoidingView
fromreact-native-keyboard-controller
for iOS. It reacts on keyboard height/state change on UI thread in the same frame, so we can schedule an update for styles in the next frameuseDerivedValue
for all the logic, since introducinguseAnimatedReaction
or having multiple shared values will delay updates for 1 frame, but we want to be 100% in sync with keyboard updatespaddingTop: translateY
(becauseScrollView
is inverted).Another important aspect of the implementation is the usage of the state machine for the animation. State machine allows us to specify the chain of events and how to handle them, and more importantly what actions to ignore, for example:
KEYBOARD_OPEN
actionEMOJI_PICKER_OPEN
actionEMOJI_PICKER_CLOSE
action which again does nothingKEYBOARD_OPEN
action. idle can react to this action by transitioning into keyboardOpen stateKEYBOARD_CLOSE
,EMOJI_PICKER_OPEN
actionsEMOJI_PICKER_OPEN
action which transitions our state into emojiPickerOpen state. now we react only toEMOJI_PICKER_CLOSE
actionKEYBOARD_CLOSE
action. but we ignore it since ouremojiPickerOpen
state can only handleEMOJI_PICKER_CLOSE
action. so we write the logic for handling hiding the keyboard but maintaining the offset based on the keyboard state shared valueEMOJI_PICKER_CLOSE
action which transitions us back intokeyboardOpen
state.Fixed Issues
$ #10632
PROPOSAL: GH_LINK_ISSUE(COMMENT)
Tests
These steps were performed on all the platforms. The new behavior is iOS only for now.
Before each next we make sure the keyboard is open:
Offline tests
Should not affect the offline state.
QA Steps
Same as Tests
PR Author Checklist
### Fixed Issues
section aboveTests
sectionOffline steps
sectionQA steps
sectiontoggleReport
and notonIconClick
)src/languages/*
files and using the translation methodWaiting for Copy
label for a copy review on the original GH to get the correct copy.STYLE.md
) were followedAvatar
, I verified the components usingAvatar
are working as expected)/** comment above it */
this
are necessary to be bound (i.e. avoidthis.submit = this.submit.bind(this);
ifthis.submit
is never passed to a component event handler likeonClick
)StyleUtils.getBackgroundAndBorderStyle(themeColors.componentBG
)Avatar
is modified, I verified thatAvatar
is working as expected in all cases)ScrollView
component to make it scrollable when more elements are added to the page.main
branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to theTest
steps.Screenshots/Videos
Web
Mobile Web - Chrome
Mobile Web - Safari
Desktop
iOS
Android