-
Notifications
You must be signed in to change notification settings - Fork 439
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(🐎): improved Reanimated wrapper (#2379)
- Loading branch information
1 parent
0294341
commit aeb5a85
Showing
13 changed files
with
110 additions
and
151 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// https://github.com/mrousavy/react-native-vision-camera/blob/main/package/src/dependencies/ModuleProxy.ts | ||
type ImportType = ReturnType<typeof require>; | ||
|
||
/** | ||
* Create a lazily-imported module proxy. | ||
* This is useful for lazily requiring optional dependencies. | ||
*/ | ||
export const createModuleProxy = <TModule>( | ||
name: string, | ||
getModule: () => ImportType | ||
): TModule => { | ||
const holder: { module: TModule | undefined } = { module: undefined }; | ||
|
||
const proxy = new Proxy(holder, { | ||
get: (target, property) => { | ||
if (target.module == null) { | ||
try { | ||
target.module = getModule() as TModule; | ||
} catch (e) { | ||
throw new Error(`${name} is not installed!`); | ||
} | ||
} | ||
return target.module[property as keyof typeof holder.module]; | ||
}, | ||
}); | ||
return proxy as unknown as TModule; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import type * as ReanimatedT from "react-native-reanimated"; | ||
|
||
import { createModuleProxy } from "../ModuleProxy"; | ||
type TReanimated = typeof ReanimatedT; | ||
|
||
const Reanimated = createModuleProxy<TReanimated>( | ||
"react-native-reanimated", | ||
() => { | ||
return require("react-native-reanimated"); | ||
} | ||
); | ||
|
||
// eslint-disable-next-line import/no-default-export | ||
export default Reanimated; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.