From 9a6af7fdb60058b24256754f405cff03b2b26307 Mon Sep 17 00:00:00 2001 From: ivliu Date: Tue, 20 Feb 2024 14:37:51 +0800 Subject: [PATCH] feat: rename Offscreen to Activity & support native Activity --- src/Activity.tsx | 23 +++++++++++++++++++++++ src/OffScreen.tsx | 13 ------------- src/index.ts | 6 ++++-- src/type.ts | 4 ++-- test/blah.test.tsx | 4 ++-- 5 files changed, 31 insertions(+), 19 deletions(-) create mode 100644 src/Activity.tsx delete mode 100644 src/OffScreen.tsx diff --git a/src/Activity.tsx b/src/Activity.tsx new file mode 100644 index 0000000..c464a4f --- /dev/null +++ b/src/Activity.tsx @@ -0,0 +1,23 @@ +import React, { Suspense } from 'react'; +import { Repeater } from './Repeater'; +import type { FC, ExoticComponent } from 'react'; +import type { IProps } from './type'; + +// @ts-ignore +const NativeActivity = (React.Activity || React.unstable_Activity) as ExoticComponent | undefined; + +export const Activity: FC = (props) => { + const { mode, children } = props; + + if(NativeActivity) { + return ( + {children} + ) + } + + return ( + + {children} + + ); +}; diff --git a/src/OffScreen.tsx b/src/OffScreen.tsx deleted file mode 100644 index e1752c2..0000000 --- a/src/OffScreen.tsx +++ /dev/null @@ -1,13 +0,0 @@ -import React, { Suspense } from 'react'; -import { Repeater } from './Repeater'; -import type { FC } from 'react'; -import type { IProps } from './type'; - -export const Offscreen: FC = (props) => { - const { mode, children } = props; - return ( - - {children} - - ); -}; diff --git a/src/index.ts b/src/index.ts index a7d11b5..6ac2ce0 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,3 +1,5 @@ -export { Offscreen } from './OffScreen'; +export { Activity } from './Activity'; +export { Activity as Offscreen } from './Activity'; -export type { OffscreenMode } from './type'; \ No newline at end of file +export type { ActivityMode } from './type'; +export type { ActivityMode as OffscreenMode } from './type'; \ No newline at end of file diff --git a/src/type.ts b/src/type.ts index f53ce05..ccac3a4 100644 --- a/src/type.ts +++ b/src/type.ts @@ -1,8 +1,8 @@ import type { ReactNode } from 'react'; -export type OffscreenMode = 'visible' | 'hidden'; +export type ActivityMode = 'visible' | 'hidden'; export interface IProps { - mode: OffscreenMode; + mode: ActivityMode; children: ReactNode; } \ No newline at end of file diff --git a/test/blah.test.tsx b/test/blah.test.tsx index f05ba9b..4fdb79f 100644 --- a/test/blah.test.tsx +++ b/test/blah.test.tsx @@ -1,11 +1,11 @@ import * as React from 'react'; import * as ReactDOM from 'react-dom'; -import { Thing } from '../src'; +import { Activity } from '../src'; describe('it', () => { it('renders without crashing', () => { const div = document.createElement('div'); - ReactDOM.render(, div); + ReactDOM.render(children, div); ReactDOM.unmountComponentAtNode(div); }); });