-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ensure global objects initialization for web (#3418)
The PR with tree shaking moved global objects initialization for web to another file and then imported it into the `index` file (`import './reanimated2/js-reanimated/global';`). However, the Webpack can lazy import modules, but we don't have any call to this module, so global objects were never initialized. Fixes #3355
- Loading branch information
Showing
2 changed files
with
50 additions
and
30 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,45 @@ | ||
// In order to keep bundle size down, we treat this file as a polyfill for Web. | ||
|
||
import { shouldBeUseWeb } from '../PlatformChecker'; | ||
|
||
if (shouldBeUseWeb()) { | ||
global._frameTimestamp = null; | ||
global._setGlobalConsole = (_val) => { | ||
// noop | ||
}; | ||
global._measure = () => { | ||
console.warn( | ||
"[Reanimated] You can't use `measure` with Chrome Debugger or with web version" | ||
); | ||
return { | ||
x: 0, | ||
y: 0, | ||
width: 0, | ||
height: 0, | ||
pageX: 0, | ||
pageY: 0, | ||
const initializeGlobalsForWeb = () => { | ||
if (shouldBeUseWeb()) { | ||
global._frameTimestamp = null; | ||
global._setGlobalConsole = (_val) => { | ||
// noop | ||
}; | ||
global._measure = () => { | ||
console.warn( | ||
"[Reanimated] You can't use `measure` with Chrome Debugger or with web version" | ||
); | ||
return { | ||
x: 0, | ||
y: 0, | ||
width: 0, | ||
height: 0, | ||
pageX: 0, | ||
pageY: 0, | ||
}; | ||
}; | ||
global._scrollTo = () => { | ||
console.warn( | ||
"[Reanimated] You can't use `scrollTo` with Chrome Debugger or with web version" | ||
); | ||
}; | ||
}; | ||
global._scrollTo = () => { | ||
console.warn( | ||
"[Reanimated] You can't use `scrollTo` with Chrome Debugger or with web version" | ||
); | ||
}; | ||
global._setGestureState = () => { | ||
console.warn( | ||
"[Reanimated] You can't use `setGestureState` with Chrome Debugger or with web version" | ||
); | ||
}; | ||
} | ||
global._setGestureState = () => { | ||
console.warn( | ||
"[Reanimated] You can't use `setGestureState` with Chrome Debugger or with web version" | ||
); | ||
}; | ||
} | ||
return true; | ||
}; | ||
|
||
/* | ||
If a file doesn't export anything, tree shaking doesn't pack | ||
it into the JS bundle. In effect, the code inside of this file | ||
will never execute. That is why we wrapped initialization code | ||
into a function, and we call this one during creating | ||
the module export object. | ||
*/ | ||
|
||
export default initializeGlobalsForWeb(); |