Ver Fonte

Feature: ref prop added for PageContainer component.

lfabl há 1 semana atrás
pai
commit
4fd0e32510

+ 13 - 4
src/components/pageContainer/index.tsx

@@ -1,21 +1,28 @@
 import {
+    forwardRef,
     Fragment,
-    type FC
+    type Ref
 } from "react";
 import {
     ScrollView,
     View
 } from "react-native";
 import type IPageContainerProps from "./type";
+import {
+    type IPageContainerRef
+} from "./type";
 import stylesheet from "./stylesheet";
 import {
     NCoreUIKitTheme
 } from "../../core/hooks";
+import {
+    type RefForwardingComponent
+} from "../../types";
 import {
     SafeAreaView
 } from "react-native-safe-area-context";
 
-const PageContainer: FC<IPageContainerProps> = ({
+const PageContainer: RefForwardingComponent<IPageContainerRef, IPageContainerProps> = ({
     backgroundColor = "default" as keyof NCoreUIKit.ContainerContentColors,
     isWrapSafeareaContext = false,
     isWorkWithHeaderSpace = true,
@@ -30,7 +37,7 @@ const PageContainer: FC<IPageContainerProps> = ({
     children,
     style,
     ...props
-}) => {
+}, ref) => {
     const {
         configs,
         colors,
@@ -48,6 +55,7 @@ const PageContainer: FC<IPageContainerProps> = ({
 
         return <ScrollView
             keyboardShouldPersistTaps="handled"
+            ref={ref as Ref<ScrollView>}
             {...scrollViewProps}
             contentContainerStyle={[
                 stylesheet.contentContainer,
@@ -79,6 +87,7 @@ const PageContainer: FC<IPageContainerProps> = ({
         }
 
         return <View
+            ref={ref as Ref<View>}
             {...props}
             style={[
                 stylesheet.contentContainer,
@@ -125,4 +134,4 @@ const PageContainer: FC<IPageContainerProps> = ({
 
     return renderSafeareaContext();
 };
-export default PageContainer;
+export default forwardRef(PageContainer);

+ 8 - 2
src/components/pageContainer/type.ts

@@ -3,8 +3,10 @@ import {
 } from "react";
 import type {
     ScrollViewProps,
+    ScrollView,
     StyleProp,
-    ViewStyle
+    ViewStyle,
+    View
 } from "react-native";
 
 interface IPageContainerProps {
@@ -27,6 +29,10 @@ interface IPageContainerProps {
     isScrollable?: boolean;
     children?: ReactNode;
 }
+
+type IPageContainerRef = ScrollView | View;
+
 export type {
-    IPageContainerProps as default
+    IPageContainerProps as default,
+    IPageContainerRef
 };