diff --git a/packages/react-native-reanimated/android/src/main/java/com/swmansion/reanimated/ReanimatedPackage.java b/packages/react-native-reanimated/android/src/main/java/com/swmansion/reanimated/ReanimatedPackage.java index eee7e930f859..5b706bf10e04 100644 --- a/packages/react-native-reanimated/android/src/main/java/com/swmansion/reanimated/ReanimatedPackage.java +++ b/packages/react-native-reanimated/android/src/main/java/com/swmansion/reanimated/ReanimatedPackage.java @@ -11,7 +11,10 @@ import com.facebook.react.module.annotations.ReactModuleList; import com.facebook.react.module.model.ReactModuleInfo; import com.facebook.react.module.model.ReactModuleInfoProvider; +import com.facebook.react.uimanager.ViewManager; +import com.swmansion.reanimated.view.ReanimatedViewManager; import java.util.HashMap; +import java.util.List; import java.util.Map; import java.util.Objects; @@ -29,6 +32,11 @@ public NativeModule getModule( }; } + @Override + public List createViewManagers(ReactApplicationContext reactContext) { + return List.of(new ReanimatedViewManager()); + } + @Override public ReactModuleInfoProvider getReactModuleInfoProvider() { Class[] moduleList = diff --git a/packages/react-native-reanimated/android/src/main/java/com/swmansion/reanimated/view/ReanimatedView.java b/packages/react-native-reanimated/android/src/main/java/com/swmansion/reanimated/view/ReanimatedView.java new file mode 100644 index 000000000000..4643dc0d2ba2 --- /dev/null +++ b/packages/react-native-reanimated/android/src/main/java/com/swmansion/reanimated/view/ReanimatedView.java @@ -0,0 +1,13 @@ +package com.swmansion.reanimated.view; + +import android.content.Context; +import android.view.ViewGroup; + +public class ReanimatedView extends ViewGroup { + public ReanimatedView(Context context) { + super(context); + } + + @Override + protected void onLayout(boolean changed, int l, int t, int r, int b) {} +} diff --git a/packages/react-native-reanimated/android/src/main/java/com/swmansion/reanimated/view/ReanimatedViewManager.java b/packages/react-native-reanimated/android/src/main/java/com/swmansion/reanimated/view/ReanimatedViewManager.java new file mode 100644 index 000000000000..f2d4579bff48 --- /dev/null +++ b/packages/react-native-reanimated/android/src/main/java/com/swmansion/reanimated/view/ReanimatedViewManager.java @@ -0,0 +1,19 @@ +package com.swmansion.reanimated.view; + +import androidx.annotation.NonNull; +import com.facebook.react.uimanager.ThemedReactContext; +import com.facebook.react.uimanager.ViewGroupManager; + +public class ReanimatedViewManager extends ViewGroupManager { + @NonNull + @Override + public String getName() { + return "ReanimatedView"; + } + + @NonNull + @Override + protected ReanimatedView createViewInstance(@NonNull ThemedReactContext themedReactContext) { + return new ReanimatedView(themedReactContext); + } +} diff --git a/packages/react-native-reanimated/apple/reanimated/apple/view/ReanimatedView.h b/packages/react-native-reanimated/apple/reanimated/apple/view/ReanimatedView.h new file mode 100644 index 000000000000..fc5875afc81c --- /dev/null +++ b/packages/react-native-reanimated/apple/reanimated/apple/view/ReanimatedView.h @@ -0,0 +1,11 @@ +#pragma once + +#import +#import + +NS_ASSUME_NONNULL_BEGIN + +@interface ReanimatedView : RCTViewComponentView +@end + +NS_ASSUME_NONNULL_END diff --git a/packages/react-native-reanimated/apple/reanimated/apple/view/ReanimatedView.mm b/packages/react-native-reanimated/apple/reanimated/apple/view/ReanimatedView.mm new file mode 100644 index 000000000000..1cd2e06c7865 --- /dev/null +++ b/packages/react-native-reanimated/apple/reanimated/apple/view/ReanimatedView.mm @@ -0,0 +1,25 @@ +#import + +#import +#import +#import +#import + +using namespace facebook::react; + +@implementation ReanimatedView + ++ (ComponentDescriptorProvider)componentDescriptorProvider +{ + return concreteComponentDescriptorProvider(); +} + +- (void)updateProps:(Props::Shared const &)props oldProps:(Props::Shared const &)oldProps +{ + // const auto &oldViewProps = *std::static_pointer_cast(_props); + // const auto &newViewProps = *std::static_pointer_cast(props); + + [super updateProps:props oldProps:oldProps]; +} + +@end diff --git a/packages/react-native-reanimated/package.json b/packages/react-native-reanimated/package.json index e5b96dff9712..41c30c1be454 100644 --- a/packages/react-native-reanimated/package.json +++ b/packages/react-native-reanimated/package.json @@ -173,10 +173,15 @@ }, "codegenConfig": { "name": "rnreanimated", - "type": "modules", + "type": "all", "jsSrcsDir": "./src/specs", "android": { "javaPackageName": "com.swmansion.reanimated" + }, + "ios": { + "componentProvider": { + "ReanimatedView": "ReanimatedView" + } } }, "sideEffects": [ diff --git a/packages/react-native-reanimated/src/index.ts b/packages/react-native-reanimated/src/index.ts index 62aa46f81226..cd25492de3e2 100644 --- a/packages/react-native-reanimated/src/index.ts +++ b/packages/react-native-reanimated/src/index.ts @@ -287,6 +287,7 @@ export { ScreenTransition, startScreenTransition, } from './screenTransition'; +export { ReanimatedView } from './specs'; export type { WorkletRuntime } from 'react-native-worklets'; export { isWorkletFunction, diff --git a/packages/react-native-reanimated/src/jestUtils.ts b/packages/react-native-reanimated/src/jestUtils.ts index 0d567377d295..9b90afe132ef 100644 --- a/packages/react-native-reanimated/src/jestUtils.ts +++ b/packages/react-native-reanimated/src/jestUtils.ts @@ -13,6 +13,16 @@ import { ReanimatedError } from './errors'; import type { DefaultStyle } from './hook/commonTypes'; import { isJest } from './PlatformChecker'; +// Mock ReanimatedView +jest.mock( + 'react-native-reanimated/lib/module/specs/ReanimatedNativeComponent', + () => ({}) +); +jest.mock( + 'react-native-reanimated/src/specs/ReanimatedNativeComponent', + () => ({}) +); + declare global { namespace jest { interface Matchers { diff --git a/packages/react-native-reanimated/src/specs/ReanimatedNativeComponent.ts b/packages/react-native-reanimated/src/specs/ReanimatedNativeComponent.ts new file mode 100644 index 000000000000..2b1d07b5a7b8 --- /dev/null +++ b/packages/react-native-reanimated/src/specs/ReanimatedNativeComponent.ts @@ -0,0 +1,7 @@ +'use strict'; +import type { ViewProps } from 'react-native'; +import codegenNativeComponent from 'react-native/Libraries/Utilities/codegenNativeComponent'; + +interface NativeProps extends ViewProps {} + +export default codegenNativeComponent('ReanimatedView'); diff --git a/packages/react-native-reanimated/src/specs/ReanimatedViewProvider.native.ts b/packages/react-native-reanimated/src/specs/ReanimatedViewProvider.native.ts new file mode 100644 index 000000000000..78c5ea28023f --- /dev/null +++ b/packages/react-native-reanimated/src/specs/ReanimatedViewProvider.native.ts @@ -0,0 +1,5 @@ +'use strict'; +import ReanimatedView from './ReanimatedNativeComponent'; + +// ts-prune-ignore-next-line +export default ReanimatedView; diff --git a/packages/react-native-reanimated/src/specs/ReanimatedViewProvider.ts b/packages/react-native-reanimated/src/specs/ReanimatedViewProvider.ts new file mode 100644 index 000000000000..94155447c4ca --- /dev/null +++ b/packages/react-native-reanimated/src/specs/ReanimatedViewProvider.ts @@ -0,0 +1,6 @@ +'use strict'; + +import type { HostComponent } from 'react-native'; + +// This is workaround for next.js +export default {} as HostComponent; diff --git a/packages/react-native-reanimated/src/specs/index.ts b/packages/react-native-reanimated/src/specs/index.ts index 588f045e8b25..c5e89182002e 100644 --- a/packages/react-native-reanimated/src/specs/index.ts +++ b/packages/react-native-reanimated/src/specs/index.ts @@ -2,5 +2,6 @@ import ReanimatedTurboModule from './NativeReanimatedModule'; import WorkletsTurboModule from './NativeReaWorkletsModule'; +import ReanimatedView from './ReanimatedViewProvider'; -export { ReanimatedTurboModule, WorkletsTurboModule }; +export { ReanimatedTurboModule, ReanimatedView, WorkletsTurboModule };