-
Notifications
You must be signed in to change notification settings - Fork 6
RG-T131 Fixing chat textbox #274
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
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
src/components/ui/keyboard-avoiding-view/__tests__/bottom-anchored.test.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| import { render, screen } from '@testing-library/react-native'; | ||
| import React from 'react'; | ||
| import { Text } from 'react-native'; | ||
|
|
||
| import { BottomAnchoredKeyboardView, keyboardPaddingBottom } from '../bottom-anchored'; | ||
|
|
||
| jest.mock('react-native-keyboard-controller', () => ({ | ||
| useReanimatedKeyboardAnimation: () => ({ height: { value: 0 }, progress: { value: 0 } }), | ||
| })); | ||
|
|
||
| describe('keyboardPaddingBottom', () => { | ||
| it('leaves no gap while the keyboard is closed', () => { | ||
| expect(keyboardPaddingBottom(0, 0)).toBe(0); | ||
| }); | ||
|
|
||
| it('pads by the full keyboard height, which the library reports negative', () => { | ||
| expect(keyboardPaddingBottom(-320, 0)).toBe(320); | ||
| }); | ||
|
|
||
| it('subtracts chrome the keyboard already covers, such as a bottom tab bar', () => { | ||
| expect(keyboardPaddingBottom(-320, 60)).toBe(260); | ||
| }); | ||
|
|
||
| it('never pads when the offset alone exceeds the keyboard', () => { | ||
| expect(keyboardPaddingBottom(-40, 60)).toBe(0); | ||
| }); | ||
|
|
||
| it('clamps at zero so an unexpected positive height cannot pull the content down', () => { | ||
| expect(keyboardPaddingBottom(40, 0)).toBe(0); | ||
| }); | ||
| }); | ||
|
|
||
| describe('BottomAnchoredKeyboardView', () => { | ||
| it('renders its children', () => { | ||
| render( | ||
| <BottomAnchoredKeyboardView> | ||
| <Text>composer</Text> | ||
| </BottomAnchoredKeyboardView> | ||
| ); | ||
|
|
||
| expect(screen.getByText('composer')).toBeTruthy(); | ||
| }); | ||
| }); | ||
60 changes: 60 additions & 0 deletions
60
src/components/ui/keyboard-avoiding-view/bottom-anchored.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| 'use client'; | ||
|
|
||
| import React from 'react'; | ||
| import { StyleSheet, type ViewStyle } from 'react-native'; | ||
| import { useReanimatedKeyboardAnimation } from 'react-native-keyboard-controller'; | ||
| import Reanimated, { useAnimatedStyle } from 'react-native-reanimated'; | ||
|
|
||
| interface BottomAnchoredKeyboardViewProps { | ||
| children: React.ReactNode; | ||
| /** | ||
| * Height in dp of any chrome sitting between this container and the bottom of the | ||
| * display — a bottom tab bar, most often. The keyboard already covers that chrome, so | ||
| * it is space this view must not pad for a second time. | ||
| */ | ||
| offset?: number; | ||
| style?: ViewStyle; | ||
| } | ||
|
|
||
| /** | ||
| * Padding a bottom-anchored container owes the keyboard. | ||
| * | ||
| * `animatedHeight` is the library's keyboard value: 0 when closed, and negative while the | ||
| * keyboard is up, since it is published for `translateY`. Marked as a worklet so the | ||
| * animated style can call it on the UI thread. | ||
| */ | ||
| export const keyboardPaddingBottom = (animatedHeight: number, offset: number): number => { | ||
| 'worklet'; | ||
|
|
||
| return Math.max(-animatedHeight - offset, 0); | ||
| }; | ||
|
|
||
| /** | ||
| * Keyboard avoidance for a container whose bottom edge *is* the bottom of the screen. | ||
| * | ||
| * `KeyboardAvoidingView` derives its padding from where it believes it sits on screen: | ||
| * `frame.y + frame.height` versus `screenHeight - keyboardHeight`. Its `automaticOffset` | ||
| * prop is what makes that frame absolute — it asks the native side for | ||
| * `getLocationOnScreen` once per layout, over a promise. Under a native-stack header on | ||
| * Android that measurement is the entire fix, and when it is stale, rejected, or resolved | ||
| * mid-transition the padding comes up short by the header plus the status bar, which is | ||
| * exactly enough for the keyboard to sit over the composer. | ||
| * | ||
| * This view measures nothing. The container already ends at the bottom of the screen, so | ||
| * the gap it owes is precisely the keyboard height, on both platforms. | ||
| * | ||
| * Only for full-bleed screen content. Anything that does not reach the bottom of the | ||
| * screen (bottom sheets, inset cards) still needs a measuring variant — see | ||
| * `useKeyboardHeight` for the sheet case, which lives in its own native window. | ||
| */ | ||
| export const BottomAnchoredKeyboardView: React.FC<BottomAnchoredKeyboardViewProps> = ({ children, offset = 0, style }) => { | ||
| // Also arms Android's resize mode, the way `KeyboardAvoidingView` did. | ||
| const { height } = useReanimatedKeyboardAnimation(); | ||
| const animatedStyle = useAnimatedStyle(() => ({ paddingBottom: keyboardPaddingBottom(height.value, offset) }), [offset]); | ||
|
|
||
| return <Reanimated.View style={[styles.fill, style, animatedStyle]}>{children}</Reanimated.View>; | ||
| }; | ||
|
|
||
| const styles = StyleSheet.create({ | ||
| fill: { flex: 1 }, | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,5 @@ | ||
| 'use client'; | ||
| export { KeyboardAvoidingView } from 'react-native'; | ||
| // Prefer this on screens that run edge-to-edge to the bottom of the display: it skips | ||
| // the screen-position measurement entirely. See the file for why that matters on Android. | ||
| export { BottomAnchoredKeyboardView } from './bottom-anchored'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| import { getAppTabBarHeight } from '@/lib/app-shell-layout'; | ||
|
|
||
| describe('getAppTabBarHeight', () => { | ||
| it('adds the bottom safe-area inset in portrait', () => { | ||
| expect(getAppTabBarHeight(34, false)).toBe(94); | ||
| }); | ||
|
|
||
| it('uses the fixed landscape height, ignoring the inset', () => { | ||
| expect(getAppTabBarHeight(34, true)).toBe(65); | ||
| }); | ||
|
|
||
| it('treats a negative inset as zero', () => { | ||
| expect(getAppTabBarHeight(-10, false)).toBe(60); | ||
| }); | ||
| }); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
Repository: Resgrid/Unit
Length of output: 2110
🏁 Script executed:
Repository: Resgrid/Unit
Length of output: 50369
🏁 Script executed:
Repository: Resgrid/Unit
Length of output: 30755
🏁 Script executed:
Repository: Resgrid/Unit
Length of output: 3602
🏁 Script executed:
Repository: Resgrid/Unit
Length of output: 848
🏁 Script executed:
Repository: Resgrid/Unit
Length of output: 662
Align the test preamble and cleanup with repository rules.
jest.mock(...)call before all imports.@/components/ui/keyboard-avoiding-view/bottom-anchored.unmountfromrender()and call it after the assertion.🤖 Prompt for AI Agents
Source: Coding guidelines