-
-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: android build fail with rnx kit & treeShaking enabled (#380)
## 📜 Description Fixed build issues when using `@rnx-kit`. ## 💡 Motivation and Context When using tools like @rnx-kit from microsoft, which uses esbuild to handle bundling and also enables treeShaking, the build fails ## 📢 Changelog - instead of direct export of type Ex: export { KeyboardToolbarProps } we export using "type": export { type KeyboardToolbarProps } ## 📸 Screenshots (if appropriate): <img width="1249" alt="Screenshot 2024-03-07 at 23 01 07" src="https://github.com/kirillzyusko/react-native-keyboard-controller/assets/10183866/6d2b5476-aadd-4736-98d2-22e5b53d68f3"> <img width="870" alt="Screenshot 2024-03-07 at 23 00 53" src="https://github.com/kirillzyusko/react-native-keyboard-controller/assets/10183866/3c252693-a220-4ebb-bd77-e606b0139756">
- Loading branch information
1 parent
ae5d4f0
commit 5a516aa
Showing
4 changed files
with
37 additions
and
29 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -64,4 +64,7 @@ lib/ | |
.metro-health-check* | ||
|
||
# testing | ||
/coverage | ||
/coverage | ||
|
||
# yarn cache folder (v2+) | ||
.yarn |
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 |
---|---|---|
@@ -1,39 +1,44 @@ | ||
// @ts-expect-error because there is no corresponding type definition | ||
import * as NativeAndroidManager from "react-native/Libraries/Components/StatusBar/NativeStatusBarManagerAndroid"; | ||
|
||
const DefaultNativeAndroidManager = NativeAndroidManager.default; | ||
const getConstants = NativeAndroidManager.default.getConstants; | ||
const RCTStatusBarManagerCompat = | ||
// eslint-disable-next-line @typescript-eslint/no-var-requires | ||
require("./specs/NativeStatusBarManagerCompat").default; | ||
|
||
// Copy original default manager to keep its original state and methods | ||
const OriginalNativeAndroidManager = { ...NativeAndroidManager.default }; | ||
|
||
// Create a new object that modifies the necessary methods | ||
// On Android < 11 RN uses legacy API which breaks EdgeToEdge mode in RN, so | ||
// in order to use library on all available platforms we have to monkey patch | ||
// default RN implementation and use modern `WindowInsetsControllerCompat`. | ||
export const applyMonkeyPatch = () => { | ||
NativeAndroidManager.default = { | ||
getConstants, | ||
setColor(color: number, animated: boolean): void { | ||
RCTStatusBarManagerCompat.setColor(color, animated); | ||
}, | ||
|
||
setTranslucent(translucent: boolean): void { | ||
RCTStatusBarManagerCompat.setTranslucent(translucent); | ||
}, | ||
|
||
/** | ||
* - statusBarStyles can be: | ||
* - 'default' | ||
* - 'dark-content' | ||
*/ | ||
setStyle(statusBarStyle?: string): void { | ||
RCTStatusBarManagerCompat.setStyle(statusBarStyle); | ||
}, | ||
const ModifiedNativeAndroidManager = { | ||
...NativeAndroidManager.default, // Spread original properties to keep existing functionality | ||
setColor: (color: number, animated: boolean): void => { | ||
RCTStatusBarManagerCompat.setColor(color, animated); | ||
}, | ||
setTranslucent: (translucent: boolean): void => { | ||
RCTStatusBarManagerCompat.setTranslucent(translucent); | ||
}, | ||
/** | ||
* - statusBarStyles can be: | ||
* - 'default' | ||
* - 'dark-content' | ||
*/ | ||
setStyle: (statusBarStyle?: string): void => { | ||
RCTStatusBarManagerCompat.setStyle(statusBarStyle); | ||
}, | ||
setHidden: (hidden: boolean): void => { | ||
RCTStatusBarManagerCompat.setHidden(hidden); | ||
}, | ||
}; | ||
|
||
setHidden(hidden: boolean): void { | ||
RCTStatusBarManagerCompat.setHidden(hidden); | ||
}, | ||
}; | ||
// Define a function to apply the monkey patch | ||
export const applyMonkeyPatch = () => { | ||
Object.assign(NativeAndroidManager.default, ModifiedNativeAndroidManager); | ||
}; | ||
|
||
// Define a function to revert changes back to the original state | ||
export const revertMonkeyPatch = () => { | ||
NativeAndroidManager.default = DefaultNativeAndroidManager; | ||
Object.assign(NativeAndroidManager.default, OriginalNativeAndroidManager); | ||
}; |