Skip to content
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

feat: enabled prop for KeyboardStickyView #717

Merged
merged 5 commits into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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: 5 additions & 1 deletion docs/docs/api/components/keyboard-sticky-view/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,11 @@ const StickyFooter = () => {

## Props

### offset
### `enabled`

A boolean prop indicating whether `KeyboardStickyView` is enabled or disabled. If disabled then view will be moved to its initial position (as keyboard would be closed) and will not react on keyboard movements. Default is `true`.

### `offset`

An object containing next properties:

Expand Down
15 changes: 12 additions & 3 deletions src/components/KeyboardStickyView/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,23 @@ export type KeyboardStickyViewProps = {
*/
opened?: number;
};

/** Controls whether this `KeyboardStickyView` instance should take effect. Default is `true` */
enabled?: boolean;
} & ViewProps;

const KeyboardStickyView = forwardRef<
View,
React.PropsWithChildren<KeyboardStickyViewProps>
>(
(
{ children, offset: { closed = 0, opened = 0 } = {}, style, ...props },
{
children,
offset: { closed = 0, opened = 0 } = {},
style,
enabled = true,
...props
},
ref,
) => {
const { height, progress } = useReanimatedKeyboardAnimation();
Expand All @@ -38,9 +47,9 @@ const KeyboardStickyView = forwardRef<
const offset = interpolate(progress.value, [0, 1], [closed, opened]);

return {
transform: [{ translateY: height.value + offset }],
transform: [{ translateY: enabled ? height.value + offset : closed }],
};
}, [closed, opened]);
}, [closed, opened, enabled]);

const styles = useMemo(
() => [style, stickyViewStyle],
Expand Down
5 changes: 3 additions & 2 deletions src/components/KeyboardToolbar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export type KeyboardToolbarProps = Omit<
* A value for container opacity in hexadecimal format (e.g. `ff`). Default value is `ff`.
*/
opacity?: HEX;
} & Pick<KeyboardStickyViewProps, "offset">;
} & Pick<KeyboardStickyViewProps, "offset" | "enabled">;

const TEST_ID_KEYBOARD_TOOLBAR = "keyboard.toolbar";
const TEST_ID_KEYBOARD_TOOLBAR_PREVIOUS = `${TEST_ID_KEYBOARD_TOOLBAR}.previous`;
Expand Down Expand Up @@ -82,6 +82,7 @@ const KeyboardToolbar: React.FC<KeyboardToolbarProps> = ({
blur = null,
opacity = DEFAULT_OPACITY,
offset: { closed = 0, opened = 0 } = {},
enabled = true,
...rest
}) => {
const colorScheme = useColorScheme();
Expand Down Expand Up @@ -151,7 +152,7 @@ const KeyboardToolbar: React.FC<KeyboardToolbarProps> = ({
);

return (
<KeyboardStickyView offset={offset}>
<KeyboardStickyView enabled={enabled} offset={offset}>
<View {...rest} style={toolbarStyle} testID={TEST_ID_KEYBOARD_TOOLBAR}>
{blur}
{showArrows && (
Expand Down
Loading