Skip to content

Commit

Permalink
feat: added keyboard input mode for android
Browse files Browse the repository at this point in the history
  • Loading branch information
gorhom committed Jun 2, 2021
1 parent 8b876cd commit 069c4b6
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/components/bottomSheet/BottomSheet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import {
SHEET_STATE,
SCROLLABLE_STATE,
KEYBOARD_BLUR_BEHAVIOR,
KEYBOARD_INPUT_MODE,
} from '../../constants';
import {
animate,
Expand All @@ -68,6 +69,7 @@ import {
DEFAULT_ENABLE_PAN_DOWN_TO_CLOSE,
INITIAL_CONTAINER_OFFSET,
DEFAULT_ANIMATION_CONFIGS,
DEFAULT_KEYBOARD_INPUT_MODE,
} from './constants';
import { ScrollableRef, BottomSheetMethods, Insets } from '../../types';
import type { BottomSheetProps } from './types';
Expand Down Expand Up @@ -105,6 +107,7 @@ const BottomSheetComponent = forwardRef<BottomSheet, BottomSheetProps>(
// keyboard
keyboardBehavior = DEFAULT_KEYBOARD_BEHAVIOR,
keyboardBlurBehavior = DEFAULT_KEYBOARD_BLUR_BEHAVIOR,
android_keyboardInputMode = DEFAULT_KEYBOARD_INPUT_MODE,

// layout
handleHeight: _providedHandleHeight,
Expand Down Expand Up @@ -253,6 +256,13 @@ const BottomSheetComponent = forwardRef<BottomSheet, BottomSheetProps>(
} = useKeyboard();
const getKeyboardHeightInContainer = useWorkletCallback(() => {
'worklet';
/**
* if android software input mode is not `adjustPan`, than keyboard
* height will be 0 all the time.
*/
if (android_keyboardInputMode === KEYBOARD_INPUT_MODE.adjustResize) {
return 0;
}
return $modal
? keyboardHeight.value -
Math.abs(bottomInset - animatedContainerOffset.value.bottom)
Expand Down
3 changes: 3 additions & 0 deletions src/components/bottomSheet/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import Animated, { Easing } from 'react-native-reanimated';
import {
KEYBOARD_BEHAVIOR,
KEYBOARD_BLUR_BEHAVIOR,
KEYBOARD_INPUT_MODE,
WINDOW_HEIGHT,
} from '../../constants';
import { exp } from '../../utilities/easingExp';
Expand All @@ -28,6 +29,7 @@ const DEFAULT_ENABLE_PAN_DOWN_TO_CLOSE = false;
const DEFAULT_ANIMATE_ON_MOUNT = false;
const DEFAULT_KEYBOARD_BEHAVIOR = KEYBOARD_BEHAVIOR.none;
const DEFAULT_KEYBOARD_BLUR_BEHAVIOR = KEYBOARD_BLUR_BEHAVIOR.none;
const DEFAULT_KEYBOARD_INPUT_MODE = KEYBOARD_INPUT_MODE.adjustPan;

// initial values
const INITIAL_SNAP_POINT = -999;
Expand Down Expand Up @@ -55,6 +57,7 @@ export {
DEFAULT_ANIMATE_ON_MOUNT,
DEFAULT_KEYBOARD_BEHAVIOR,
DEFAULT_KEYBOARD_BLUR_BEHAVIOR,
DEFAULT_KEYBOARD_INPUT_MODE,
// initial
INITIAL_POSITION,
INITIAL_CONTAINER_HEIGHT,
Expand Down
8 changes: 8 additions & 0 deletions src/components/bottomSheet/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import type { BottomSheetBackgroundProps } from '../bottomSheetBackground';
import type {
KEYBOARD_BEHAVIOR,
KEYBOARD_BLUR_BEHAVIOR,
KEYBOARD_INPUT_MODE,
} from '../../constants';

export interface BottomSheetProps
Expand Down Expand Up @@ -139,6 +140,13 @@ export interface BottomSheetProps
* - `restore`: restore sheet position.
*/
keyboardBlurBehavior?: keyof typeof KEYBOARD_BLUR_BEHAVIOR;
/**
* Defines keyboard input mode for Android only.
* @link {https://developer.android.com/guide/topics/manifest/activity-element#wsoft}
* @type `adjustPan` | `adjustResize`
* @default `adjustPan`
*/
android_keyboardInputMode?: keyof typeof KEYBOARD_INPUT_MODE;
//#endregion

/**
Expand Down
6 changes: 6 additions & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ const KEYBOARD_BLUR_BEHAVIOR = {

const KEYBOARD_DISMISS_THRESHOLD = 12.5;

const KEYBOARD_INPUT_MODE = {
adjustPan: 'adjustPan',
adjustResize: 'adjustResize',
};

export {
GESTURE,
SHEET_STATE,
Expand All @@ -79,4 +84,5 @@ export {
KEYBOARD_BEHAVIOR,
KEYBOARD_BLUR_BEHAVIOR,
KEYBOARD_DISMISS_THRESHOLD,
KEYBOARD_INPUT_MODE,
};

0 comments on commit 069c4b6

Please sign in to comment.