Skip to content
This repository was archived by the owner on Aug 13, 2024. It is now read-only.

Commit 2192ce7

Browse files
committed
chore: update license
1 parent 65b2299 commit 2192ce7

File tree

4 files changed

+69
-22
lines changed

4 files changed

+69
-22
lines changed

LICENSE

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
MIT License
22

3-
Copyright (c) 2023 bang9
3+
Copyright (c) 2023 Sendbird
4+
45
Permission is hereby granted, free of charge, to any person obtaining a copy
56
of this software and associated documentation files (the "Software"), to deal
67
in the Software without restriction, including without limitation the rights

NOTICE

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
react-native-scrollview-enhancer
2+
Copyright 2023 Sendbird.
3+
4+
This project contains subcomponents with separate copyright notices and license terms.
5+
Your use of the source code for these subcomponents is subject to the terms and conditions of the following licenses.
6+
7+
=====
8+
9+
React-Native from https://github.com/facebook/react-native/blob/main/packages/react-native
10+
11+
=====
12+
13+
MIT License
14+
15+
Copyright (c) Meta Platforms, Inc. and affiliates.
16+
17+
Permission is hereby granted, free of charge, to any person obtaining a copy
18+
of this software and associated documentation files (the "Software"), to deal
19+
in the Software without restriction, including without limitation the rights
20+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
21+
copies of the Software, and to permit persons to whom the Software is
22+
furnished to do so, subject to the following conditions:
23+
24+
The above copyright notice and this permission notice shall be included in all
25+
copies or substantial portions of the Software.
26+
27+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
28+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
29+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
30+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
31+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
32+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
33+
SOFTWARE.

android/src/main/java/com/scrollviewenhancer/MaintainVisibleScrollPositionHelper.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,17 @@
1+
/**
2+
* Original Code
3+
* @link https://github.com/facebook/react-native/blob/main/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/scroll/MaintainVisibleScrollPositionHelper.java
4+
*/
5+
16
/*
27
* Copyright (c) Meta Platforms, Inc. and affiliates.
38
*
49
* This source code is licensed under the MIT license found in the
510
* LICENSE file in the root directory of this source tree.
11+
*
12+
* @link
613
*/
14+
715
package com.scrollviewenhancer
816

917
import android.graphics.Rect

src/useBiDirectional.tsx

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
/**
2+
* Original Code
3+
* @link https://github.com/facebook/react-native/blob/main/packages/virtualized-lists/Lists/VirtualizedList.js
4+
*/
5+
16
import type { NativeScrollEvent, NativeSyntheticEvent, VirtualizedListProps } from 'react-native';
27
import type { EnhancedScrollViewProps } from './types';
38
import React, { ComponentType, useRef } from 'react';
@@ -47,19 +52,6 @@ export function useBiDirectional<P extends Partial<VirtualizedListProps<any> & E
4752
const sentEndForContentLength = useRef(0);
4853
const sentStartForContentLength = useRef(0);
4954

50-
function maybeRecallOnEdgeReached(key: 'distanceFromStart' | 'distanceFromEnd', threshold: number) {
51-
const distanceFromEdge = getDistanceFrom(
52-
scrollMetrics.current.offset,
53-
scrollMetrics.current.visibleLength,
54-
scrollMetrics.current.contentLength
55-
)[key];
56-
57-
if (distanceFromEdge <= threshold) {
58-
const lazyOnEdgeReached = key === 'distanceFromStart' ? lazyOnStartReached : lazyOnEndReached;
59-
lazyOnEdgeReached(distanceFromEdge);
60-
}
61-
}
62-
6355
function updateScrollMetrics(metrics: Partial<ScrollMetrics>) {
6456
if (typeof metrics.offset === 'number') {
6557
scrollMetrics.current.offset = metrics.offset;
@@ -105,7 +97,7 @@ export function useBiDirectional<P extends Partial<VirtualizedListProps<any> & E
10597
return p.promise;
10698
}
10799

108-
const maybeCallOnEdgeReached = (offset: number, visibleLength: number, contentLength: number) => {
100+
function maybeCallOnEdgeReached(offset: number, visibleLength: number, contentLength: number) {
109101
if (visibleLength < 0 || contentLength < 0) return;
110102

111103
const { onEndReached, onStartReached } = props;
@@ -154,9 +146,22 @@ export function useBiDirectional<P extends Partial<VirtualizedListProps<any> & E
154146
sentStartForContentLength.current = 0;
155147
}
156148
}
157-
};
149+
}
158150

159-
const onScroll = (e: NativeSyntheticEvent<NativeScrollEvent>) => {
151+
function maybeRecallOnEdgeReached(key: 'distanceFromStart' | 'distanceFromEnd', threshold: number) {
152+
const distanceFromEdge = getDistanceFrom(
153+
scrollMetrics.current.offset,
154+
scrollMetrics.current.visibleLength,
155+
scrollMetrics.current.contentLength
156+
)[key];
157+
158+
if (distanceFromEdge <= threshold) {
159+
const lazyOnEdgeReached = key === 'distanceFromStart' ? lazyOnStartReached : lazyOnEndReached;
160+
lazyOnEdgeReached(distanceFromEdge);
161+
}
162+
}
163+
164+
function onScroll(e: NativeSyntheticEvent<NativeScrollEvent>) {
160165
props.onScroll?.(e);
161166

162167
const { contentOffset, contentSize, layoutMeasurement } = e.nativeEvent;
@@ -167,14 +172,14 @@ export function useBiDirectional<P extends Partial<VirtualizedListProps<any> & E
167172

168173
maybeCallOnEdgeReached(offset, visibleLength, contentLength);
169174
updateScrollMetrics({ offset, visibleLength, contentLength, timestamp: e.timeStamp });
170-
};
175+
}
171176

172-
const onContentSizeChange = (w: number, h: number) => {
177+
function onContentSizeChange(w: number, h: number) {
173178
props.onContentSizeChange?.(w, h);
174179
updateScrollMetrics({ contentLength: isHorizontal ? w : h });
175-
};
180+
}
176181

177-
const renderScrollView = () => {
182+
function renderScrollView() {
178183
return (
179184
<Component
180185
{...props}
@@ -184,7 +189,7 @@ export function useBiDirectional<P extends Partial<VirtualizedListProps<any> & E
184189
onEndReached={null}
185190
/>
186191
);
187-
};
192+
}
188193

189194
return {
190195
renderScrollView,

0 commit comments

Comments
 (0)