Skip to content

Commit

Permalink
Change Legacy basic example into the next basic example
Browse files Browse the repository at this point in the history
  • Loading branch information
Piotr Trocki committed Mar 31, 2024
1 parent 9f0be55 commit 13fa1cb
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 16 deletions.
6 changes: 3 additions & 3 deletions example/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import CoverflowExample from './tabView/CoverflowExample';
import ReanimatedOnPageScrollExample from './ReanimatedOnPageScrollExample';
import { createNativeStackNavigator } from '@react-navigation/native-stack';
import { SafeAreaProvider } from 'react-native-safe-area-context';
import { LegacyBasicPagerViewExample } from './LegacyBasicPagerViewExample';
import { NextBasicPagerViewExample } from './NextBasicPagerViewExample';

const examples = [
{ component: BasicPagerViewExample, name: 'Basic Example' },
Expand Down Expand Up @@ -69,8 +69,8 @@ const examples = [

if (Platform.OS === 'ios') {
examples.unshift({
component: LegacyBasicPagerViewExample,
name: '❌ Legacy Basic Example',
component: NextBasicPagerViewExample,
name: '🔜 Next Basic Example',
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { useNavigationPanel } from './hook/useNavigationPanel';

const AnimatedPagerView = Animated.createAnimatedComponent(PagerView);

export function LegacyBasicPagerViewExample() {
export function NextBasicPagerViewExample() {
const { ref, ...navigationPanel } = useNavigationPanel();

return (
Expand All @@ -29,7 +29,7 @@ export function LegacyBasicPagerViewExample() {
pageMargin={10}
// Lib does not support dynamically orientation change
orientation="horizontal"
useLegacy
useNext={true}
>
{useMemo(
() =>
Expand Down
7 changes: 1 addition & 6 deletions example/src/ScrollViewInsideExample.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,7 @@ export const ScrollViewInsideExample = (): JSX.Element => {
);

return (
<AnimatedPagerView
// todo fix this case
useLegacy
testID="pager-view"
style={styles.flex}
>
<AnimatedPagerView testID="pager-view" style={styles.flex}>
{pages.map((page) => (
<ScrollView key={page.key} style={styles.content}>
{Array(20)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ interface NativeProps extends ViewProps {
onPageScroll?: DirectEventHandler<OnPageScrollEventData>;
onPageSelected?: DirectEventHandler<OnPageSelectedEventData>;
onPageScrollStateChanged?: DirectEventHandler<OnPageScrollStateChangedEventData>;
useLegacy?: WithDefault<boolean, false>;
useLegacy?: WithDefault<boolean, true>;
}

type PagerViewViewType = HostComponent<NativeProps>;
Expand Down
15 changes: 13 additions & 2 deletions src/PagerView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import PagerViewNativeComponent, {
OnPageScrollEventData,
OnPageScrollStateChangedEventData,
OnPageSelectedEventData,
NativeProps as PagerViewProps,
NativeProps,
} from './PagerViewNativeComponent/PagerViewNativeComponent';

import LEGACY_PagerViewNativeComponent, {
Expand Down Expand Up @@ -72,7 +72,8 @@ if (Platform.OS === 'ios') {
* }
* ```
*/
export class PagerView extends React.Component<PagerViewProps> {

class PagerViewInternal extends React.Component<NativeProps> {
private isScrolling = false;
pagerView: React.ElementRef<typeof PagerViewNativeComponent> | null = null;

Expand Down Expand Up @@ -222,3 +223,13 @@ export class PagerView extends React.Component<PagerViewProps> {
);
}
}

// Temporary solution. It should be removed once all things get fixed
type PagerViewProps = Omit<NativeProps, 'useLegacy'> & { useNext: boolean };

export const PagerView = React.forwardRef<PagerViewInternal, PagerViewProps>(
(props, ref) => {
const { useNext, ...rest } = props;
return <PagerViewInternal {...rest} useLegacy={!useNext} ref={ref} />;
}
);
2 changes: 1 addition & 1 deletion src/PagerViewNativeComponent/PagerViewNativeComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export interface NativeProps extends ViewProps {
onPageScroll?: DirectEventHandler<OnPageScrollEventData>;
onPageSelected?: DirectEventHandler<OnPageSelectedEventData>;
onPageScrollStateChanged?: DirectEventHandler<OnPageScrollStateChangedEventData>;
useLegacy?: WithDefault<boolean, false>;
useLegacy?: WithDefault<boolean, true>;
}

type PagerViewViewType = HostComponent<NativeProps>;
Expand Down
1 change: 0 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
"allowUnreachableCode": false,
"allowUnusedLabels": false,
"esModuleInterop": true,
"importsNotUsedAsValues": "error",
"forceConsistentCasingInFileNames": true,
"jsx": "react",
"lib": ["esnext"],
Expand Down

0 comments on commit 13fa1cb

Please sign in to comment.