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

feat(iOS): Add a useLegacy flag to switch between the old/new iOS implementation #783

Merged
merged 40 commits into from
Dec 21, 2023
Merged
Show file tree
Hide file tree
Changes from 32 commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
686023c
wip: unsuspicious changes
igorbej Sep 28, 2023
7a2695c
wip: unsuspicious changes v2
igorbej Sep 28, 2023
faed701
FABRIC NEW IMPL -> OLD IMPL
igorbej Oct 5, 2023
b7ac223
wip: bring back useLegacy on the RN side
igorbej Oct 5, 2023
fa06f8b
wip: bring back duplicate types to fix codegen issues
igorbej Oct 10, 2023
8369060
wip: remove #705 related code for now
igorbej Oct 10, 2023
036e286
wip: old/new impl division first draft
igorbej Oct 10, 2023
13b05df
wip: old/new impl division continued
igorbej Oct 10, 2023
1b9dbd0
wip: old/new impl v3
igorbej Oct 11, 2023
4e707ce
wip: add a `LEGACY_` prefix to all legacy implementation-related symbols
igorbej Oct 19, 2023
7586f13
wip: fix styles for new implementation on Fabric
igorbej Oct 19, 2023
5746c99
wip: move old/new impl into separate folders
igorbej Oct 19, 2023
e80ad6c
wip: fix old impl fabric symbol names
igorbej Oct 19, 2023
f293140
wip: xcode changes
igorbej Oct 20, 2023
238afe7
wip: clean up & unify the naming convention
igorbej Oct 20, 2023
5e2af1c
wip: fix linter issues
igorbej Oct 24, 2023
e90d004
wip: fix styles for new implementation on Paper
igorbej Oct 24, 2023
b669e98
wip: make Fabric example run on another port by default to make it po…
igorbej Oct 24, 2023
b56e124
wip: implement an abstraction over native commands invocations to red…
igorbej Oct 24, 2023
f579d11
refactor: remove the unnecessary value for boolean props
igorbej Oct 24, 2023
b73f656
Merge commit '3ea6dae21d3a2f78233720f66343034ccba990f0' into add-useL…
igorbej Oct 24, 2023
67e3ec6
fix: bump react-native-safe-area-context to a Fabric-enabled version
igorbej Oct 26, 2023
a6f6bcf
feat: bring back & adjust the `bootstrap-fabric` script
igorbej Oct 26, 2023
8e676b5
feat: adjust the home screen title depending on the used architecture
igorbej Oct 26, 2023
7aeebcd
chore: update example/Podfile.lock
igorbej Oct 26, 2023
bc51f9b
chore: update an Xcode project file after building
igorbej Oct 26, 2023
6e3507e
ci: make next branch events trigger ios/android build workflows
igorbej Oct 30, 2023
0a3db4f
chore: remove commented-out code related to #705 for now
igorbej Oct 30, 2023
ed08c33
chore: add legacy implementation explanation comment
igorbej Oct 30, 2023
384cde4
wip: Android fixes
igorbej Oct 30, 2023
e2d5ae9
fix: unnecessary comma in MainActivity.java
igorbej Oct 31, 2023
99412a7
feat: readme makeover
igorbej Nov 2, 2023
19785bb
chore: bump react-native-screens & react-native-gesture-handler in ex…
igorbej Nov 20, 2023
6a54d0a
refactor(android): extract module name to shared variable, add commen…
igorbej Nov 29, 2023
2fbccf2
chore: remove unnecessary yarn.lock deps
igorbej Nov 29, 2023
0392c94
chore(ios): bring back removed build flags
igorbej Nov 30, 2023
c7139c1
chore(ios): remove unnecessary concurrentRootEnabled method
igorbej Nov 30, 2023
2a97ac7
fix(android): adjust incorrect param type on Fabric
igorbej Dec 14, 2023
0dd9b2a
chore: remove unnecessary tsconfig.json comment
igorbej Dec 14, 2023
0212f97
chore(ios): bring back (currently unused) code related to #712 and #705
igorbej Dec 14, 2023
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
2 changes: 2 additions & 0 deletions .github/workflows/android.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ on:
pull_request:
branches:
- master
- next
paths:
- '.github/workflows/android.yml'
- 'android/**'
- 'example/android/**'
push:
branches:
- master
- next

concurrency:
group: ${{ github.ref }}-android
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/ios.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ on:
pull_request:
branches:
- master
- next
paths:
- '.github/workflows/ios.yml'
- 'ios/**'
- 'example/ios/**'
push:
branches:
- master
- next

concurrency:
group: ${{ github.ref }}-ios
Expand Down
87 changes: 74 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@
[![iOS Build](https://github.com/callstack/react-native-pager-view/actions/workflows/ios.yml/badge.svg)](https://github.com/callstack/react-native-pager-view/actions/workflows/ios.yml)
[![Android Build](https://github.com/callstack/react-native-pager-view/actions/workflows/android.yml/badge.svg)](https://github.com/callstack/react-native-pager-view/actions/workflows/android.yml)

This component allows the user to swipe left and right through pages of data. Under the hood it is using the native [Android ViewPager](https://developer.android.com/reference/android/support/v4/view/ViewPager) and the [iOS UIPageViewController](https://developer.apple.com/documentation/uikit/uipageviewcontroller) implementations. [See it in action!](https://github.com/callstack/react-native-pager-view#preview)
PagerView allows the user to swipe left and right through pages of data.
It leverages the native [Android ViewPager2](https://developer.android.com/jetpack/androidx/releases/viewpager2)
and [iOS UIScrollView](https://developer.apple.com/documentation/uikit/uiscrollview) under the hood.
[See it in action!](https://github.com/callstack/react-native-pager-view#preview)

<br/>
<p align="center">
Expand All @@ -17,22 +20,80 @@ This component allows the user to swipe left and right through pages of data. Un

<br/>

## Versions
## Getting started

| 4.x | 5.x |
| ---------- | ----------- |
| iOS | iOS support |
| ViewPager1 | ViewPager2 |
Install the library with:

## Migration
```sh
yarn add react-native-pager-view
```

In version **6.x** support for `transitionStyle` property has been dropped. More information [here](https://github.com/callstack/react-native-pager-view/blob/master/MIGRATION.md).
or:

`"@react-native-community/viewpager"` library has been changed to `react-native-pager-view`. Here you can find more information, how to migrate pager view to the latest [version](https://github.com/callstack/react-native-pager-view/blob/master/MIGRATION.md)
```sh
npm install react-native-pager-view
```

## Getting started
## Migration from `@react-native-community/viewpager`

The `@react-native-community/viewpager` library has been moved and now lives here, in the `react-native-pager-view` repo.
[Here](https://github.com/callstack/react-native-pager-view/blob/master/MIGRATION.md) you can find
more information on how to migrate PagerView to the latest version.

## Versions & compatibility

The underlying iOS/Android native implementations of PagerView have changed over the years.
Here's an overview of the implementation details throughout the library's lifespan:

| | `1.x.x` | `2.x.x` | `5.0.8` | `7.x.x` |
| ------- | ----------- | ---------------------- | ---------------------- | -------------- |
| iOS | ❌ | `UIPageViewController` | `UIPageViewController` | `UIScrollView` |
| Android | `ViewPager` | `ViewPager` | `ViewPager2` | `ViewPager2` |

### Legacy iOS implementation support (`UIPageViewController`)
igorbej marked this conversation as resolved.
Show resolved Hide resolved

As per the table above, the iOS implementation of this library has been rewritten to use
[`UIScrollView`](https://developer.apple.com/documentation/uikit/uiscrollview) over
[`UIPageViewController`](https://developer.apple.com/documentation/uikit/uipageviewcontroller).

For backwards-compatibility purposes, the old iOS implementation is still supported, however — simply pass `true` to
the `useLegacy` boolean prop to switch the used implementation back to `UIPageViewController`.

### Other notes

In version **6.x.x** the support for the iOS `transitionStyle` property has been dropped.
More information [here](https://github.com/callstack/react-native-pager-view/blob/master/MIGRATION.md).

## New architecture support (Fabric)

This library supports both architectures — Paper and Fabric!

`yarn add react-native-pager-view`
To properly migrate to the new architecture and enable it in your app consult the newest
[docs](https://reactnative.dev/docs/new-architecture-app-intro).

From the perspective of PagerView, the steps required to make the library work with Fabric are as follows:

### iOS

Install pods the usual way, with the `RCT_NEW_ARCH_ENABLED` flag set, e.g.:

```sh
cd ios && RCT_NEW_ARCH_ENABLED=1 bundle exec pod install
```

### Android

In the `android/gradle.properties` file, set `newArchEnabled` to `true` and build the app, e.g.:

```sh
yarn android
```

If you have issues running the Android build, you can try generating the Codegen files before the build using:

```sh
cd android && ./gradlew generateCodegenArtifactsFromSchema
```

## Linking

Expand Down Expand Up @@ -133,7 +194,7 @@ const styles = StyleSheet.create({

## Advanced usage

For advanced usage please take a look into our [example project](https://github.com/callstack/react-native-pager-view/blob/master/example/src/BasicPagerViewExample.tsx)
For advanced usage please take a look into our [example project](https://github.com/callstack/react-native-pager-view/blob/master/example/src/BasicPagerViewExample.tsx).

## API

Expand Down Expand Up @@ -188,7 +249,7 @@ requestAnimationFrame(() => refPagerView.current?.setPage(index));

## Reanimated onPageScroll handler

An example can be found [here](https://github.com/callstack/react-native-pager-view/blob/master/example/src/ReanimatedOnPageScrollExample.tsx)
An example can be found [here](https://github.com/callstack/react-native-pager-view/blob/master/example/src/ReanimatedOnPageScrollExample.tsx).

#### Instructions

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.reactnativepagerview

import com.facebook.react.uimanager.ViewGroupManager
import android.widget.FrameLayout
import com.facebook.react.module.annotations.ReactModule
import com.facebook.react.uimanager.ThemedReactContext


@ReactModule(name = "LEGACY_RNCViewPager")
krozniata marked this conversation as resolved.
Show resolved Hide resolved
class LEGACY_PagerViewViewManager : ViewGroupManager<FrameLayout>() {
override fun getName() = "LEGACY_RNCViewPager"

override fun createViewInstance(context: ThemedReactContext): FrameLayout {
throw Error("LEGACY_RNCViewPager is an iOS-only feature")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,11 @@ class PagerViewViewManager : ViewGroupManager<NestedScrollableHost>(), RNCViewPa
return
}

@ReactProp(name = "useLegacy")
override fun setUseLegacy(view: NestedScrollableHost?, value: Boolean?) {
igorbej marked this conversation as resolved.
Show resolved Hide resolved
return
}

fun goTo(root: NestedScrollableHost?, selectedPage: Int, scrollWithAnimation: Boolean) {
if (root == null) {
return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ class PagerViewPackage : ReactPackage {
}

override fun createViewManagers(reactContext: ReactApplicationContext): List<ViewManager<*, *>> {
return listOf(PagerViewViewManager())
return listOf(PagerViewViewManager(), LEGACY_PagerViewViewManager())
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.reactnativepagerview

import com.facebook.react.uimanager.ViewGroupManager
import android.widget.FrameLayout
import com.facebook.react.module.annotations.ReactModule
import com.facebook.react.uimanager.ThemedReactContext


@ReactModule(name = "LEGACY_RNCViewPager")
class LEGACY_PagerViewViewManager : ViewGroupManager<FrameLayout>() {
override fun getName() = "LEGACY_RNCViewPager"

override fun createViewInstance(context: ThemedReactContext): FrameLayout {
throw Error("LEGACY_RNCViewPager is an iOS-only feature")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ protected ReactActivityDelegate createReactActivityDelegate() {
this,
getMainComponentName(),
// If you opted-in for the New Architecture, we enable the Fabric Renderer.
DefaultNewArchitectureEntryPoint.getFabricEnabled());
DefaultNewArchitectureEntryPoint.getFabricEnabled() // fabricEnabled
// If you opted-in for the New Architecture, we enable Concurrent React (i.e. React 18).
// DefaultNewArchitectureEntryPoint.getConcurrentReactEnabled() // concurrentRootEnabled // TODO: why has this been deleted?
);
}
}
6 changes: 0 additions & 6 deletions example/ios/PagerViewExample.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -600,10 +600,7 @@
);
OTHER_LDFLAGS = (
"$(inherited)",
"-Wl",
troZee marked this conversation as resolved.
Show resolved Hide resolved
"-ld_classic",
" ",
"-Wl -ld_classic ",
);
REACT_NATIVE_PATH = "${PODS_ROOT}/../../node_modules/react-native";
SDKROOT = iphoneos;
Expand Down Expand Up @@ -676,10 +673,7 @@
);
OTHER_LDFLAGS = (
"$(inherited)",
"-Wl",
"-ld_classic",
" ",
"-Wl -ld_classic ",
);
REACT_NATIVE_PATH = "${PODS_ROOT}/../../node_modules/react-native";
SDKROOT = iphoneos;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
troZee marked this conversation as resolved.
Show resolved Hide resolved
<!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>
10 changes: 10 additions & 0 deletions example/ios/PagerViewExample/AppDelegate.mm
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,14 @@ - (NSURL *)sourceURLForBridge:(RCTBridge *)bridge
#endif
}

/// This method controls whether the `concurrentRoot`feature of React18 is turned on or off.
krozniata marked this conversation as resolved.
Show resolved Hide resolved
///
/// @see: https://reactjs.org/blog/2022/03/29/react-v18.html
/// @note: This requires to be rendering on Fabric (i.e. on the New Architecture).
/// @return: `true` if the `concurrentRoot` feature is enabled. Otherwise, it returns `false`.
- (BOOL)concurrentRootEnabled
{
return true; // TODO: Figure out if we should keep this
troZee marked this conversation as resolved.
Show resolved Hide resolved
}

@end
6 changes: 3 additions & 3 deletions example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ PODS:
- glog
- react-native-pager-view (7.0.0-rc.0):
- React-Core
- react-native-safe-area-context (3.4.1):
- react-native-safe-area-context (4.7.4):
- React-Core
- React-NativeModulesApple (0.72.5):
- hermes-engine
Expand Down Expand Up @@ -751,7 +751,7 @@ SPEC CHECKSUMS:
React-jsinspector: aef73cbd43b70675f572214d10fa438c89bf11ba
React-logger: 2e4aee3e11b3ec4fa6cfd8004610bbb3b8d6cca4
react-native-pager-view: 563a43b511eea680f803ab4fb20bd7525fbde2cc
react-native-safe-area-context: 9e40fb181dac02619414ba1294d6c2a807056ab9
react-native-safe-area-context: 2cd91d532de12acdb0a9cbc8d43ac72a8e4c897c
React-NativeModulesApple: 797bc6078d566eef3fb3f74127e6e1d2e945a15f
React-perflogger: cd8886513f68e1c135a1e79d20575c6489641597
React-RCTActionSheet: 726d2615ca62a77ce3e2c13d87f65379cdc73498
Expand Down Expand Up @@ -780,4 +780,4 @@ SPEC CHECKSUMS:

PODFILE CHECKSUM: 3875acd7cb7e8f7782e244f1db71aa5f14571810

COCOAPODS: 1.13.0
COCOAPODS: 1.12.1
3 changes: 2 additions & 1 deletion example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"react-native-animated-pagination-dots": "^0.1.73",
"react-native-gesture-handler": "^1.9.0",
igorbej marked this conversation as resolved.
Show resolved Hide resolved
"react-native-reanimated": "3.5.4",
"react-native-safe-area-context": "^3.1.9",
"react-native-safe-area-context": "^4.4.1",
"react-native-screens": "~3.20.0",
igorbej marked this conversation as resolved.
Show resolved Hide resolved
"react-native-svg": "12.4.4",
"react-native-tab-view": "^3.1.1"
Expand All @@ -30,6 +30,7 @@
"@babel/core": "^7.20.0",
"@babel/preset-env": "^7.20.0",
"@babel/runtime": "^7.20.0",
"@types/jest": "^29.2.1",
"@react-native/metro-config": "^0.72.11",
"@tsconfig/react-native": "^3.0.0",
"@types/react": "^18.0.24",
Expand Down
12 changes: 12 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 Expand Up @@ -101,6 +110,9 @@ export function Navigation() {
name="PagerView Example"
component={App}
options={{
title: global?.nativeFabricUIManager
? 'PagerView Example (Fabric)'
: 'PagerView Example',
headerRight: () => (
<Button
onPress={() =>
Expand Down
Loading