mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-04-23 04:49:15 +08:00
react-native: fix Dimensions event handler type
This commit is contained in:
4
types/react-native/index.d.ts
vendored
4
types/react-native/index.d.ts
vendored
@@ -5250,7 +5250,7 @@ export interface Dimensions {
|
||||
* @param type the type of event to listen to
|
||||
* @param handler the event handler
|
||||
*/
|
||||
addEventListener(type: "change", handler: () => void): void;
|
||||
addEventListener(type: "change", handler: ({ window, screen }: { window: ScaledSize, screen: ScaledSize }) => void): void;
|
||||
|
||||
/**
|
||||
* Remove an event listener
|
||||
@@ -5258,7 +5258,7 @@ export interface Dimensions {
|
||||
* @param type the type of event
|
||||
* @param handler the event handler
|
||||
*/
|
||||
removeEventListener(type: "change", handler: () => void): void;
|
||||
removeEventListener(type: "change", handler: ({ window, screen }: { window: ScaledSize, screen: ScaledSize }) => void): void;
|
||||
}
|
||||
|
||||
export type SimpleTask = {
|
||||
|
||||
@@ -34,6 +34,7 @@ import {
|
||||
ViewPagerAndroid,
|
||||
FlatList,
|
||||
FlatListProperties,
|
||||
ScaledSize,
|
||||
SectionList,
|
||||
SectionListProperties,
|
||||
findNodeHandle,
|
||||
@@ -60,8 +61,16 @@ NativeModules.NativeUntypedModule;
|
||||
NativeModules.NativeTypedModule.someFunction();
|
||||
NativeModules.NativeTypedModule.someProperty = "";
|
||||
|
||||
function dimensionsListener(dimensions: { window: ScaledSize, screen: ScaledSize }) {
|
||||
console.log("window dimensions: ", dimensions.window);
|
||||
console.log("screen dimensions: ", dimensions.screen);
|
||||
}
|
||||
|
||||
function testDimensions() {
|
||||
const { width, height, scale, fontScale } = Dimensions.get(1 === 1 ? "window" : "screen");
|
||||
|
||||
Dimensions.addEventListener('change', dimensionsListener);
|
||||
Dimensions.removeEventListener('change', dimensionsListener);
|
||||
}
|
||||
|
||||
BackAndroid.addEventListener("hardwareBackPress", () => {});
|
||||
|
||||
Reference in New Issue
Block a user