Skip to content

feat: allow js and reanimated scroll handlers for KeyboardAwareScrollView #500

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
merged 2 commits into from
Jul 10, 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
12 changes: 11 additions & 1 deletion docs/docs/guides/compatibility.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ If you found an incompatibility or conflict with other open source libraries - d

:::

## React Native
## `react-native`

Below you can find an information about compatibility with `react-native` package per different architectures.

Expand All @@ -25,6 +25,10 @@ Below you can find a table with supported versions:

| library version | react-native version |
| --------------- | -------------------- |
| 1.12.0+ | 0.74.0+ |
| 1.10.0+ | 0.73.0+ |
| 1.6.0+ | 0.72.0+ |
| 1.5.0+ | 0.71.0+ |
| 1.3.0+ | 0.70.0+ |
| 1.2.0+ | 0.69.0+ |

Expand All @@ -37,6 +41,12 @@ This library supports as minimal `react-native` version as possible. However it
| 1.7.0+ | 0.65.0+ |
| 1.0.0+ | 0.62.0+ |

## `react-native-reanimated`

This library is heavily relies on `react-native-reanimated` primitives to bring advanced concepts for keyboard handling.

The minimal supported version of `react-native-reanimated` is `2.11.0`.

## Third-party libraries compatibility

Since this library uses `WindowInsetsCompat` API on Android it may conflict with other libraries if they are using deprecated API (if they are changing `window` flags directly).
Expand Down
8 changes: 7 additions & 1 deletion docs/versioned_docs/version-1.0.0/guides/compatibility.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ sidebar_position: 3

# Compatibility

## React Native
## `react-native`

Starting from `1.2.0` this library adds support for a new architecture called `Fabric`. Since a new architecture is still in adoption stage and it changes some APIs over time - it's highly recommended to use versions which are compatible and were intensively tested against specific `react-native` versions.

Expand All @@ -21,6 +21,12 @@ For `Paper` (old) architecture there is no any restrictions. If you found an inc

:::

## `react-native-reanimated`

This library is heavily relies on `react-native-reanimated` primitives to bring advanced concepts for keyboard handling.

The minimal supported version of `react-native-reanimated` is `2.3.0`.

## Third-party libraries compatibility

Since this library uses `WindowInsetsCompat` API on Android it may conflict with other libraries if they are using deprecated API (if they are changing `window` flags directly).
Expand Down
8 changes: 7 additions & 1 deletion docs/versioned_docs/version-1.10.0/guides/compatibility.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ If you found an incompatibility or conflict with other open source libraries - d

:::

## React Native
## `react-native`

Below you can find an information about compatibility with `react-native` package per different architectures.

Expand All @@ -40,6 +40,12 @@ This library supports as minimal `react-native` version as possible. However it
| 1.7.0+ | 0.65.0+ |
| 1.0.0+ | 0.62.0+ |

## `react-native-reanimated`

This library is heavily relies on `react-native-reanimated` primitives to bring advanced concepts for keyboard handling.

The minimal supported version of `react-native-reanimated` is `2.3.0`.

## Third-party libraries compatibility

Since this library uses `WindowInsetsCompat` API on Android it may conflict with other libraries if they are using deprecated API (if they are changing `window` flags directly).
Expand Down
8 changes: 7 additions & 1 deletion docs/versioned_docs/version-1.11.0/guides/compatibility.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ If you found an incompatibility or conflict with other open source libraries - d

:::

## React Native
## `react-native`

Below you can find an information about compatibility with `react-native` package per different architectures.

Expand All @@ -40,6 +40,12 @@ This library supports as minimal `react-native` version as possible. However it
| 1.7.0+ | 0.65.0+ |
| 1.0.0+ | 0.62.0+ |

## `react-native-reanimated`

This library is heavily relies on `react-native-reanimated` primitives to bring advanced concepts for keyboard handling.

The minimal supported version of `react-native-reanimated` is `2.3.0`.

## Third-party libraries compatibility

Since this library uses `WindowInsetsCompat` API on Android it may conflict with other libraries if they are using deprecated API (if they are changing `window` flags directly).
Expand Down
8 changes: 7 additions & 1 deletion docs/versioned_docs/version-1.12.0/guides/compatibility.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ If you found an incompatibility or conflict with other open source libraries - d

:::

## React Native
## `react-native`

Below you can find an information about compatibility with `react-native` package per different architectures.

Expand Down Expand Up @@ -41,6 +41,12 @@ This library supports as minimal `react-native` version as possible. However it
| 1.7.0+ | 0.65.0+ |
| 1.0.0+ | 0.62.0+ |

## `react-native-reanimated`

This library is heavily relies on `react-native-reanimated` primitives to bring advanced concepts for keyboard handling.

The minimal supported version of `react-native-reanimated` is `2.11.0`.

## Third-party libraries compatibility

Since this library uses `WindowInsetsCompat` API on Android it may conflict with other libraries if they are using deprecated API (if they are changing `window` flags directly).
Expand Down
8 changes: 7 additions & 1 deletion docs/versioned_docs/version-1.4.0/guides/compatibility.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ sidebar_position: 3

# Compatibility

## React Native
## `react-native`

Starting from `1.2.0` this library adds support for a new architecture called `Fabric`. Since a new architecture is still in adoption stage and it changes some APIs over time - it's highly recommended to use versions which are compatible and were intensively tested against specific `react-native` versions.

Expand All @@ -21,6 +21,12 @@ For `Paper` (old) architecture there is no any restrictions. If you found an inc

:::

## `react-native-reanimated`

This library is heavily relies on `react-native-reanimated` primitives to bring advanced concepts for keyboard handling.

The minimal supported version of `react-native-reanimated` is `2.3.0`.

## Third-party libraries compatibility

Since this library uses `WindowInsetsCompat` API on Android it may conflict with other libraries if they are using deprecated API (if they are changing `window` flags directly).
Expand Down
8 changes: 7 additions & 1 deletion docs/versioned_docs/version-1.5.0/guides/compatibility.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ keywords:

# Compatibility

## React Native
## `react-native`

Starting from `1.2.0` this library adds support for a new architecture called `Fabric`. Since a new architecture is still in adoption stage and it changes some APIs over time - it's highly recommended to use versions which are compatible and were intensively tested against specific `react-native` versions.

Expand All @@ -25,6 +25,12 @@ For `Paper` (old) architecture there is no any restrictions. If you found an inc

:::

## `react-native-reanimated`

This library is heavily relies on `react-native-reanimated` primitives to bring advanced concepts for keyboard handling.

The minimal supported version of `react-native-reanimated` is `2.3.0`.

## Third-party libraries compatibility

Since this library uses `WindowInsetsCompat` API on Android it may conflict with other libraries if they are using deprecated API (if they are changing `window` flags directly).
Expand Down
8 changes: 7 additions & 1 deletion docs/versioned_docs/version-1.6.0/guides/compatibility.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ keywords:

# Compatibility

## React Native
## `react-native`

Starting from `1.2.0` this library adds support for a new architecture called `Fabric`. Since a new architecture is still in adoption stage and it changes some APIs over time - it's highly recommended to use versions which are compatible and were intensively tested against specific `react-native` versions.

Expand All @@ -26,6 +26,12 @@ For `Paper` (old) architecture there is no any restrictions. If you found an inc

:::

## `react-native-reanimated`

This library is heavily relies on `react-native-reanimated` primitives to bring advanced concepts for keyboard handling.

The minimal supported version of `react-native-reanimated` is `2.3.0`.

## Third-party libraries compatibility

Since this library uses `WindowInsetsCompat` API on Android it may conflict with other libraries if they are using deprecated API (if they are changing `window` flags directly).
Expand Down
8 changes: 7 additions & 1 deletion docs/versioned_docs/version-1.7.0/guides/compatibility.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ If you found an incompatibility or conflict with other open source libraries - d

:::

## React Native
## `react-native`

Below you can find an information about compatibility with `react-native` package per different architectures.

Expand All @@ -39,6 +39,12 @@ This library supports as minimal `react-native` version as possible. However it
| 1.7.0+ | 0.65.0+ |
| 1.0.0+ | 0.62.0+ |

## `react-native-reanimated`

This library is heavily relies on `react-native-reanimated` primitives to bring advanced concepts for keyboard handling.

The minimal supported version of `react-native-reanimated` is `2.3.0`.

## Third-party libraries compatibility

Since this library uses `WindowInsetsCompat` API on Android it may conflict with other libraries if they are using deprecated API (if they are changing `window` flags directly).
Expand Down
8 changes: 7 additions & 1 deletion docs/versioned_docs/version-1.8.0/guides/compatibility.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ If you found an incompatibility or conflict with other open source libraries - d

:::

## React Native
## `react-native`

Below you can find an information about compatibility with `react-native` package per different architectures.

Expand All @@ -39,6 +39,12 @@ This library supports as minimal `react-native` version as possible. However it
| 1.7.0+ | 0.65.0+ |
| 1.0.0+ | 0.62.0+ |

## `react-native-reanimated`

This library is heavily relies on `react-native-reanimated` primitives to bring advanced concepts for keyboard handling.

The minimal supported version of `react-native-reanimated` is `2.3.0`.

## Third-party libraries compatibility

Since this library uses `WindowInsetsCompat` API on Android it may conflict with other libraries if they are using deprecated API (if they are changing `window` flags directly).
Expand Down
8 changes: 7 additions & 1 deletion docs/versioned_docs/version-1.9.0/guides/compatibility.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ If you found an incompatibility or conflict with other open source libraries - d

:::

## React Native
## `react-native`

Below you can find an information about compatibility with `react-native` package per different architectures.

Expand All @@ -39,6 +39,12 @@ This library supports as minimal `react-native` version as possible. However it
| 1.7.0+ | 0.65.0+ |
| 1.0.0+ | 0.62.0+ |

## `react-native-reanimated`

This library is heavily relies on `react-native-reanimated` primitives to bring advanced concepts for keyboard handling.

The minimal supported version of `react-native-reanimated` is `2.3.0`.

## Third-party libraries compatibility

Since this library uses `WindowInsetsCompat` API on Android it may conflict with other libraries if they are using deprecated API (if they are changing `window` flags directly).
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@
"peerDependencies": {
"react": "*",
"react-native": "*",
"react-native-reanimated": ">=2.3.0"
"react-native-reanimated": ">=2.11.0"
},
"jest": {
"preset": "react-native",
Expand Down
21 changes: 2 additions & 19 deletions src/components/KeyboardAwareScrollView/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@ import React, { forwardRef, useCallback, useMemo } from "react";
import { findNodeHandle } from "react-native";
import Reanimated, {
interpolate,
runOnJS,
scrollTo,
useAnimatedReaction,
useAnimatedRef,
useAnimatedScrollHandler,
useAnimatedStyle,
useScrollViewOffset,
useSharedValue,
} from "react-native-reanimated";

Expand Down Expand Up @@ -87,7 +86,6 @@ const KeyboardAwareScrollView = forwardRef<
bottomOffset = 0,
disableScrollOnKeyboardHide = false,
enabled = true,
onScroll: onScrollProps,
extraKeyboardSpace = 0,
...rest
},
Expand All @@ -96,7 +94,7 @@ const KeyboardAwareScrollView = forwardRef<
const scrollViewAnimatedRef = useAnimatedRef<Reanimated.ScrollView>();
const scrollViewTarget = useSharedValue<number | null>(null);
const scrollPosition = useSharedValue(0);
const position = useSharedValue(0);
const position = useScrollViewOffset(scrollViewAnimatedRef);
const currentKeyboardFrameHeight = useSharedValue(0);
const keyboardHeight = useSharedValue(0);
const keyboardWillAppear = useSharedValue(false);
Expand All @@ -108,20 +106,6 @@ const KeyboardAwareScrollView = forwardRef<

const { height } = useWindowDimensions();

const onScroll = useAnimatedScrollHandler(
{
onScroll: (event) => {
position.value = event.contentOffset.y;

if (onScrollProps) {
// @ts-expect-error https://github.com/software-mansion/react-native-reanimated/issues/6204
runOnJS(onScrollProps)({ nativeEvent: event });
}
},
},
[onScrollProps],
);

const onRef = useCallback((assignedRef: Reanimated.ScrollView) => {
if (typeof ref === "function") {
ref(assignedRef);
Expand Down Expand Up @@ -344,7 +328,6 @@ const KeyboardAwareScrollView = forwardRef<
ref={onRef}
{...rest}
onLayout={onScrollViewLayout}
onScroll={onScroll}
scrollEventThrottle={16}
>
{children}
Expand Down
Loading