Skip to content

Commit 6c702fe

Browse files
author
Marek Fořt
committed
WIP: FlashList Fabric Android support
1 parent 52d8578 commit 6c702fe

4 files changed

Lines changed: 72 additions & 28 deletions

File tree

android/build.gradle

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -85,20 +85,21 @@ android {
8585
}
8686
}
8787

88-
if (isNewArchitectureEnabled()) {
89-
externalNativeBuild {
90-
ndkBuild {
91-
path "src/main/jni/Android.mk"
92-
}
93-
}
94-
}
88+
if (isNewArchitectureEnabled()) {
89+
externalNativeBuild {
90+
ndkBuild {
91+
path "src/main/jni/Android.mk"
92+
}
93+
}
94+
}
9595

9696
packagingOptions {
9797
// For some reason gradle only complains about the duplicated version of libreact_render libraries
9898
// while there are more libraries copied in intermediates folder of the lib build directory, we exclude
9999
// only the ones that make the build fail (ideally we should only include librngesturehandler_modules but we
100100
// are only allowed to specify exclude patterns)
101101
exclude "**/libreact_render*.so"
102+
}
102103

103104
lintOptions {
104105
abortOnError false
@@ -120,6 +121,12 @@ dependencies {
120121
androidTestImplementation("androidx.test:rules:${_androidTestRunnerVersion}")
121122
}
122123

123-
react {
124-
jsRootDir = rootProject.file("../src/fabric")
124+
if (isNewArchitectureEnabled()) {
125+
react {
126+
reactRoot = rootProject.file("../node_modules/react-native/")
127+
jsRootDir = file("../src/fabric/")
128+
codegenDir = rootProject.file("../node_modules/react-native-codegen/")
129+
libraryName = "rnflashlist"
130+
codegenJavaPackageName = "com.shopify.reactnative.flash_list"
131+
}
125132
}
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("rnflashlist_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)