Skip to content

Commit 1a8fc9f

Browse files
author
Marek Fořt
committed
WIP: FlashList Fabric Android support
1 parent 14b344d commit 1a8fc9f

4 files changed

Lines changed: 65 additions & 21 deletions

File tree

android/build.gradle

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ android {
9191
// only the ones that make the build fail (ideally we should only include librngesturehandler_modules but we
9292
// are only allowed to specify exclude patterns)
9393
exclude "**/libreact_render*.so"
94+
}
9495

9596
lintOptions {
9697
abortOnError false
@@ -112,6 +113,12 @@ dependencies {
112113
androidTestImplementation("androidx.test:rules:${_androidTestRunnerVersion}")
113114
}
114115

115-
react {
116-
jsRootDir = rootProject.file("../src/fabric")
116+
if (isNewArchitectureEnabled()) {
117+
react {
118+
reactRoot = rootProject.file("../node_modules/react-native/")
119+
jsRootDir = file("../src/fabric/")
120+
codegenDir = rootProject.file("../node_modules/react-native-codegen/")
121+
libraryName = "rnflashlist"
122+
codegenJavaPackageName = "com.shopify.reactnative.flash_list"
123+
}
117124
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package com.shopify.reactnative.flash_list.react;
2+
3+
import com.facebook.jni.HybridData;
4+
import com.facebook.proguard.annotations.DoNotStrip;
5+
import com.facebook.react.fabric.ComponentFactory;
6+
import com.facebook.soloader.SoLoader;
7+
8+
@DoNotStrip
9+
public class FlashListComponentsRegistry {
10+
static {
11+
SoLoader.loadLibrary("fabricjni");
12+
SoLoader.loadLibrary("flashlist_modules");
13+
}
14+
15+
@DoNotStrip private final HybridData mHybridData;
16+
17+
@DoNotStrip
18+
private native HybridData initHybrid(ComponentFactory componentFactory);
19+
20+
@DoNotStrip
21+
private FlashListComponentsRegistry(ComponentFactory componentFactory) {
22+
mHybridData = initHybrid(componentFactory);
23+
}
24+
25+
@DoNotStrip
26+
public static FlashListComponentsRegistry register(ComponentFactory componentFactory) {
27+
return new FlashListComponentsRegistry(componentFactory);
28+
}
29+
}

android/src/main/kotlin/com/shopify/reactnative/flash_list/FlashListPackage.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,17 @@ import com.facebook.react.ReactPackage
44
import com.facebook.react.bridge.NativeModule
55
import com.facebook.react.bridge.ReactApplicationContext
66
import com.facebook.react.uimanager.ViewManager
7+
import com.facebook.soloader.SoLoader
78

89
class ReactNativeFlashListPackage : ReactPackage {
910
override fun createNativeModules(reactContext: ReactApplicationContext): List<NativeModule> {
11+
if (BuildConfig.IS_NEW_ARCHITECTURE_ENABLED) {
12+
// For Fabric, we load c++ native library here, this triggers gesture handler's
13+
// Fabric component registration which is necessary in order to avoid asking users
14+
// to manually add init calls in their application code.
15+
// This should no longer be needed if RN's autolink mechanism has Fabric support
16+
SoLoader.loadLibrary("flashlist_modules")
17+
}
1018
return listOf()
1119
}
1220

src/FlashList.tsx

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import {
1919
import StickyContainer, { StickyContainerProps } from "recyclerlistview/sticky";
2020

2121
import { BlankAreaEventHandler } from "./AutoLayoutView";
22-
// import ItemContainer from "./CellContainer";
22+
import ItemContainer from "./CellContainer";
2323
import { PureComponentWrapper } from "./PureComponentWrapper";
2424
import GridLayoutProviderWithProps from "./GridLayoutProviderWithProps";
2525
import CustomError from "./errors/CustomError";
@@ -537,24 +537,24 @@ class FlashList<T> extends React.PureComponent<
537537

538538
private itemContainer = (props: any, parentProps: any) => {
539539
return (
540-
// <ItemContainer
541-
// {...props}
542-
// style={{
543-
// ...props.style,
544-
// flexDirection: this.props.horizontal ? "row" : "column",
545-
// alignItems: "stretch",
546-
// ...this.getTransform(),
547-
// }}
548-
// index={parentProps.index}
549-
// >
550-
<PureComponentWrapper
551-
extendedState={parentProps.extendedState}
552-
internalSnapshot={parentProps.internalSnapshot}
553-
data={parentProps.data}
554-
arg={parentProps.index}
555-
renderer={this.getCellContainerChild}
556-
/>
557-
// </ItemContainer>
540+
<ItemContainer
541+
{...props}
542+
style={{
543+
...props.style,
544+
flexDirection: this.props.horizontal ? "row" : "column",
545+
alignItems: "stretch",
546+
...this.getTransform(),
547+
}}
548+
index={parentProps.index}
549+
>
550+
<PureComponentWrapper
551+
extendedState={parentProps.extendedState}
552+
internalSnapshot={parentProps.internalSnapshot}
553+
data={parentProps.data}
554+
arg={parentProps.index}
555+
renderer={this.getCellContainerChild}
556+
/>
557+
</ItemContainer>
558558
);
559559
};
560560

0 commit comments

Comments
 (0)