Skip to content

Commit b010c75

Browse files
committed
feat(scroll-to-hide): add resetPosition function to ScrollToHideProvider
Add resetPosition function to reset scroll position with animation Update documentation to reflect package name changes and new feature Bump rnc-theme version to 0.1.1
1 parent 1b408a4 commit b010c75

File tree

5 files changed

+28
-34
lines changed

5 files changed

+28
-34
lines changed

apps/docs/src/content/docs/hooks/use-scroll-to-hide.mdx

Lines changed: 12 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ The `ScrollToHideProvider` is automatically integrated into the `RNCProvider`. Y
1919

2020
### Basic Usage
2121

22-
<Code code={`import { RNCProvider } from 'your-package';
22+
<Code code={`import { RNCProvider } from 'rnc-theme';
2323
2424
function App() {
2525
return (
@@ -34,26 +34,6 @@ function App() {
3434
);
3535
}`} lang="tsx" title="App.tsx" />
3636

37-
### Standalone Usage (Not Recommended)
38-
39-
If you need to use `ScrollToHideProvider` outside of `RNCProvider`, you can import it directly:
40-
41-
<Code code={`import { ScrollToHideProvider } from 'your-package/contexts/ScrollToHideProvider';
42-
43-
function StandaloneApp() {
44-
return (
45-
<ScrollToHideProvider
46-
headerHeight={100}
47-
tabBarHeight={60}
48-
>
49-
<YourScreenContent />
50-
</ScrollToHideProvider>
51-
);
52-
}`} lang="tsx" title="StandaloneApp.tsx" />
53-
54-
<Aside type="caution" title="Not Recommended">
55-
Using `ScrollToHideProvider` standalone means you'll miss out on theme integration and other RNCProvider features. Always prefer using it through `RNCProvider` with `scrollToHideProps`.
56-
</Aside>
5737

5838
### Props
5939

@@ -123,11 +103,15 @@ The main hook for accessing scroll-to-hide functionality and animated values.
123103
<Card title="onScrollRegular: ScrollHandler" icon="down-caret">
124104
Regular scroll handler for use with standard ScrollView components.
125105
</Card>
106+
107+
<Card title="resetPosition: ResetPosition" icon="seti:crystal">
108+
Reset to the initial scroll position.
109+
</Card>
126110
</CardGrid>
127111

128112
### Usage Example
129113

130-
<Code code={`import { useScrollToHide } from 'your-package';
114+
<Code code={`import { useScrollToHide } from 'rnc-theme';
131115
import Animated from 'react-native-reanimated';
132116
133117
function MyScreen() {
@@ -206,7 +190,7 @@ A lightweight hook that only returns the current scroll values without the full
206190

207191
### Usage Example
208192

209-
<Code code={`import { useScrollValues } from 'your-package';
193+
<Code code={`import { useScrollValues } from 'rnc-theme';
210194
211195
function ScrollIndicator() {
212196
const { scrollValue, clampedValue } = useScrollValues();
@@ -223,7 +207,7 @@ function ScrollIndicator() {
223207

224208
### With Animated.FlatList
225209

226-
<Code code={`import { useScrollToHide } from 'your-package';
210+
<Code code={`import { useScrollToHide } from 'rnc-theme';
227211
import Animated from 'react-native-reanimated';
228212
229213
function AnimatedFlatListExample() {
@@ -259,7 +243,7 @@ function AnimatedFlatListExample() {
259243

260244
### With Regular ScrollView
261245

262-
<Code code={`import { useScrollToHide } from 'your-package';
246+
<Code code={`import { useScrollToHide } from 'rnc-theme';
263247
import { ScrollView } from 'react-native';
264248
265249
function RegularScrollViewExample() {
@@ -288,7 +272,7 @@ function RegularScrollViewExample() {
288272

289273
### Custom Animation Logic
290274

291-
<Code code={`import { useScrollToHide } from 'your-package';
275+
<Code code={`import { useScrollToHide } from 'rnc-theme';
292276
import { interpolate, useDerivedValue } from 'react-native-reanimated';
293277
294278
function CustomAnimationExample() {
@@ -457,8 +441,8 @@ function App() {
457441

458442
The components provide full TypeScript support with proper type definitions:
459443

460-
<Code code={`import { useScrollToHide, ScrollToHideProvider } from 'your-package';
461-
import type { ScrollToHideProviderProps } from 'your-package';
444+
<Code code={`import { useScrollToHide, ScrollToHideProvider } from 'rnc-theme';
445+
import type { ScrollToHideProviderProps } from 'rnc-theme';
462446
463447
// Provider props are fully typed
464448
const providerProps: ScrollToHideProviderProps = {

apps/docs/src/content/docs/hooks/use-theme.mdx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ The `useTheme` hook is the primary interface for accessing and managing theme fu
1616

1717
### Basic Usage
1818

19-
<Code code={`import { useTheme } from 'your-theme-package';
19+
<Code code={`import { useTheme } from 'rnc-theme';
2020
2121
function MyComponent() {
2222
const { theme, isDark, setThemeMode } = useTheme();
@@ -231,8 +231,8 @@ function App() {
231231

232232
The hook is fully typed and provides excellent IntelliSense support:
233233

234-
<Code code={`import { useTheme } from 'your-theme-package';
235-
import type { Theme, ThemeMode } from 'your-theme-package/types';
234+
<Code code={`import { useTheme } from 'rnc-theme';
235+
import type { Theme, ThemeMode } from 'rnc-theme';
236236
237237
function TypedComponent() {
238238
const {

apps/docs/src/content/docs/hooks/use-themed-styles.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ The `useThemedStyles` hook provides a performant way to create theme-aware style
1616

1717
### Basic Usage
1818

19-
<Code code={`import { useThemedStyles } from 'your-theme-package';
19+
<Code code={`import { useThemedStyles } from 'rnc-theme';
2020
2121
function MyComponent() {
2222
const styles = useThemedStyles((theme) => ({

libs/rnc-theme/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "rnc-theme",
3-
"version": "0.1.0",
3+
"version": "0.1.1",
44
"funding": {
55
"type": "github",
66
"url": "https://github.com/masumrpg/react-native-components"

libs/rnc-theme/src/lib/context/ScrollToHideProvider.tsx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
useAnimatedScrollHandler,
1111
useDerivedValue,
1212
useSharedValue,
13+
withTiming,
1314
} from 'react-native-reanimated';
1415

1516
const DEFAULT_HEADER_HEIGHT = 100;
@@ -25,6 +26,7 @@ interface ScrollContextType {
2526
width: number;
2627
onScroll: ReturnType<typeof useAnimatedScrollHandler>;
2728
onScrollRegular: (event: NativeSyntheticEvent<NativeScrollEvent>) => void;
29+
resetPosition: () => void;
2830
}
2931

3032
const ScrollContext = createContext<ScrollContextType | null>(null);
@@ -33,7 +35,7 @@ export type ScrollToHideProviderProps = {
3335
children: React.ReactNode;
3436
headerHeight?: number;
3537
tabBarHeight?: number;
36-
}
38+
};
3739

3840
export const ScrollToHideProvider = ({
3941
children,
@@ -91,6 +93,13 @@ export const ScrollToHideProvider = ({
9193
scrollY.value = event.nativeEvent.contentOffset.y;
9294
};
9395

96+
// Function untuk reset posisi header dan tabbar ke awal
97+
const resetPosition = () => {
98+
scrollY.value = withTiming(0, { duration: 300 });
99+
lastScrollY.value = withTiming(0, { duration: 300 });
100+
clampedOffset.value = withTiming(0, { duration: 300 });
101+
};
102+
94103
const contextValue: ScrollContextType = {
95104
scrollY,
96105
clampedScrollY,
@@ -101,6 +110,7 @@ export const ScrollToHideProvider = ({
101110
width,
102111
onScroll,
103112
onScrollRegular,
113+
resetPosition,
104114
};
105115

106116
return (

0 commit comments

Comments
 (0)