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

add RN New Arch Fabric support #9

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 2 additions & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ android {
targetSdkVersion getExtOrIntegerDefault('targetSdkVersion')
buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString()
}

buildTypes {
release {
minifyEnabled false
Expand Down Expand Up @@ -131,7 +132,7 @@ dependencies {
if (isNewArchitectureEnabled()) {
react {
jsRootDir = file("../src/")
libraryName = "FastShadow"
libraryName = "FastShadowView"
codegenJavaPackageName = "com.reactnativefastshadow"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@
import com.facebook.react.views.view.ReactViewManager;

public class FastShadowViewManager extends ReactViewManager {
public static final String REACT_CLASS = "FastShadowView";

public static final String NAME = "FastShadowView";

@Override
@NonNull
public String getName() {
return REACT_CLASS;
return FastShadowViewManager.NAME;
}

@Override
Expand Down
2 changes: 1 addition & 1 deletion example/android/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ reactNativeArchitectures=armeabi-v7a,arm64-v8a,x86,x86_64
# your application. You should enable this flag either if you want
# to write custom TurboModules/Fabric components OR use libraries that
# are providing them.
newArchEnabled=false
newArchEnabled=true

# Use this property to enable or disable the Hermes JS engine.
# If set to false, you will be using JSC instead.
Expand Down
5 changes: 4 additions & 1 deletion example/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useEffect } from 'react';

import { Image, View, ScrollView } from 'react-native';
import { Image, View, ScrollView, Text } from 'react-native';
import { ShadowedView, shadowStyle } from 'react-native-fast-shadow';
import Animated, {
useSharedValue,
Expand Down Expand Up @@ -39,8 +39,11 @@ export default function App() {
height: `${animatedHeight.value}%`,
}));

const uiManager = (global as any)?.nativeFabricUIManager ? 'Fabric' : 'Paper';

return (
<ScrollView style={{ backgroundColor: 'white' }}>
<Text style={{fontSize: 18, fontWeight: 'bold'}}>This View is {uiManager}</Text>
<View style={{ margin: 16 }}>
<View style={{ flexDirection: 'row', marginBottom: 20 }}>
<ShadowedView
Expand Down
7 changes: 5 additions & 2 deletions src/FastShadowView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,8 @@ export type FastShadowViewProps = ViewProps & {
};
};

export const FastShadowView =
requireNativeComponent<FastShadowViewProps>('FastShadowView');
const isFabricEnabled = (global as any).nativeFabricUIManager != null;

export const FastShadowView: React.FC<FastShadowViewProps> = isFabricEnabled
? require('./FastShadowViewNativeComponent').default
: requireNativeComponent('FastShadowView');
18 changes: 18 additions & 0 deletions src/FastShadowViewNativeComponent.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// @flow
import type { ViewProps } from 'react-native/Libraries/Components/View/ViewPropTypes';
import type { HostComponent } from 'react-native';
import codegenNativeComponent from 'react-native/Libraries/Utilities/codegenNativeComponent';

export type FastShadowViewProps = $ReadOnly<{|
...ViewProps,
cornerRadii: $ReadOnly<{|
topLeft: Int32,
topRight: Int32,
bottomLeft: Int32,
bottomRight: Int32,
|}>,
|}>;

export default (codegenNativeComponent<FastShadowViewProps>(
'FastShadowView'
): HostComponent<FastShadowViewProps>);