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

WIP feat(ios): add useLegacy flag #763

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be removed

<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>
9 changes: 9 additions & 0 deletions example/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
Alert,
I18nManager,
DevSettings,
Platform,
} from 'react-native';
import { NavigationContainer, useNavigation } from '@react-navigation/native';
import { createStackNavigator } from '@react-navigation/stack';
Expand All @@ -33,6 +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';

const examples = [
{ component: BasicPagerViewExample, name: 'Basic Example' },
Expand Down Expand Up @@ -65,6 +67,13 @@ const examples = [
{ component: CoverflowExample, name: 'CoverflowExample' },
];

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

function App() {
const navigation = useNavigation();
return (
Expand Down
70 changes: 70 additions & 0 deletions example/src/LegacyBasicPagerViewExample.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import React, { useMemo } from 'react';
import { StyleSheet, View, SafeAreaView, Animated, Text } from 'react-native';

import PagerView from 'react-native-pager-view';

import { LikeCount } from './component/LikeCount';
import { NavigationPanel } from './component/NavigationPanel';
import { useNavigationPanel } from './hook/useNavigationPanel';

const AnimatedPagerView = Animated.createAnimatedComponent(PagerView);

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

return (
<SafeAreaView style={styles.container}>
<AnimatedPagerView
// @ts-ignore
testID="pager-view"
ref={ref}
style={styles.PagerView}
initialPage={0}
layoutDirection="ltr"
overdrag={navigationPanel.overdragEnabled}
scrollEnabled={navigationPanel.scrollEnabled}
onPageScroll={navigationPanel.onPageScroll}
onPageSelected={navigationPanel.onPageSelected}
onPageScrollStateChanged={navigationPanel.onPageScrollStateChanged}
pageMargin={10}
// Lib does not support dynamically orientation change
orientation="horizontal"
useLegacy={true}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can specify just useLegacy without passing true

>
{useMemo(
() =>
navigationPanel.pages.map((page, index) => (
<View
testID="pager-view-content"
key={page.key}
style={page.style}
collapsable={false}
>
<LikeCount />
<Text
testID={`pageNumber${index}`}
>{`page number ${index}`}</Text>
</View>
)),
[navigationPanel.pages]
)}
</AnimatedPagerView>
<NavigationPanel {...navigationPanel} />
</SafeAreaView>
);
}

const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: 'white',
},
image: {
width: 300,
height: 200,
padding: 20,
},
PagerView: {
flex: 1,
},
});
2 changes: 1 addition & 1 deletion ios/RNCPagerViewManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ @implementation RNCPagerViewManager

#pragma mark - RTC

RCT_EXPORT_MODULE(RNCViewPager)
RCT_EXPORT_MODULE(RNCScrollViewPager)

RCT_EXPORT_VIEW_PROPERTY(initialPage, NSInteger)
RCT_EXPORT_VIEW_PROPERTY(orientation, NSString)
Expand Down
27 changes: 27 additions & 0 deletions ios/legacy/Fabric/LegacyRNCPagerViewComponentView.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#ifdef RCT_NEW_ARCH_ENABLED

#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#import <React/RCTViewComponentView.h>
#import "UIViewController+CreateExtension.h"

NS_ASSUME_NONNULL_BEGIN

@interface RNCPagerViewComponentView : RCTViewComponentView <UIPageViewControllerDataSource, UIPageViewControllerDelegate, UIScrollViewDelegate>

@property(strong, nonatomic, readonly) UIPageViewController *nativePageViewController;
@property(nonatomic, strong) NSMutableArray<UIViewController *> *nativeChildrenViewControllers;
@property(nonatomic) NSInteger initialPage;
@property(nonatomic) NSInteger currentIndex;
@property(nonatomic) NSInteger destinationIndex;
@property(nonatomic) NSString* layoutDirection;
@property(nonatomic) BOOL overdrag;

- (void)setPage:(NSInteger)number;
- (void)setPageWithoutAnimation:(NSInteger)number;

@end

NS_ASSUME_NONNULL_END

#endif
Loading