From fa788ae7c5b983bbcf97211c257ba17d3fc73ce7 Mon Sep 17 00:00:00 2001 From: Jung-gun Lim Date: Tue, 16 Feb 2016 16:20:38 +0900 Subject: [PATCH 1/3] Update definition for react-native : AppState --- react-native/react-native-tests.tsx | 19 +++++++++++++++++-- react-native/react-native.d.ts | 11 +++++++---- 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/react-native/react-native-tests.tsx b/react-native/react-native-tests.tsx index d4b89ab34..51e01ae77 100644 --- a/react-native/react-native-tests.tsx +++ b/react-native/react-native-tests.tsx @@ -21,7 +21,7 @@ For a list of complete Typescript examples: check https://github.com/bgrieder/RN import * as React from 'react-native' -const { StyleSheet, Text, View } = React +const { StyleSheet, Text, View, AppState, AppStateIOS } = React var styles = StyleSheet.create( { @@ -67,5 +67,20 @@ class Welcome extends React.Component { } } -export default Welcome +export default Welcome; +// App State + +function appStateListener(state : string) { + console.log('New state: ' + state); +} + +function appStateTest() { + console.log('Current state: ' + AppState.currentState); + AppState.addEventListener('change', appStateListener); +} + +function appStateIOSTest() { + console.log('Current state: ' + AppStateIOS.currentState); + AppStateIOS.addEventListener('change', appStateListener); +} diff --git a/react-native/react-native.d.ts b/react-native/react-native.d.ts index b3fa3e3cc..03b3e28c7 100644 --- a/react-native/react-native.d.ts +++ b/react-native/react-native.d.ts @@ -1,4 +1,4 @@ -// Type definitions for react-native 0.14 +// Type definitions for react-native 0.19 // Project: https://github.com/facebook/react-native // Definitions by: Bruno Grieder // Definitions: https://github.com/borisyankov/DefinitelyTyped @@ -2853,7 +2853,7 @@ declare namespace __React { * * @see https://facebook.github.io/react-native/docs/appstateios.html#content */ - export interface AppStateIOSStatic { + export interface AppStateStatic { currentState: string addEventListener( type: string, listener: ( state: string ) => void ): void removeEventListener( type: string, listener: ( state: string ) => void ): void @@ -3378,8 +3378,11 @@ declare namespace __React { export var AlertIOS: AlertIOSStatic export type AlertIOS = AlertIOSStatic - export var AppStateIOS: AppStateIOSStatic - export type AppStateIOS = AppStateIOSStatic + export var AppState : AppStateStatic; + export type AppState = AppStateStatic; + + export var AppStateIOS: AppStateStatic + export type AppStateIOS = AppStateStatic export var AsyncStorage: AsyncStorageStatic export type AsyncStorage = AsyncStorageStatic From 52270b07349ce82b720c9e79a0dfb992dc89c1d8 Mon Sep 17 00:00:00 2001 From: Jung-gun Lim Date: Tue, 16 Feb 2016 17:37:38 +0900 Subject: [PATCH 2/3] Update definition for react-native: ViewPagerAndroid --- react-native/react-native-tests.tsx | 29 ++++++++++++++++++++++++++++- react-native/react-native.d.ts | 28 ++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+), 1 deletion(-) diff --git a/react-native/react-native-tests.tsx b/react-native/react-native-tests.tsx index 51e01ae77..bb76ab8b1 100644 --- a/react-native/react-native-tests.tsx +++ b/react-native/react-native-tests.tsx @@ -21,7 +21,14 @@ For a list of complete Typescript examples: check https://github.com/bgrieder/RN import * as React from 'react-native' -const { StyleSheet, Text, View, AppState, AppStateIOS } = React +const { + StyleSheet, + Text, + View, + AppState, + AppStateIOS, + ViewPagerAndroid +} = React var styles = StyleSheet.create( { @@ -84,3 +91,23 @@ function appStateIOSTest() { console.log('Current state: ' + AppStateIOS.currentState); AppStateIOS.addEventListener('change', appStateListener); } + +// ViewPagerAndroid + +export class ViewPagerAndroidTest { + render() { + return ( + { + console.log(`position: ${e.nativeEvent.position}`); + console.log(`offset: ${e.nativeEvent.offset}`); + }} + onPageSelected={(e) => { + console.log(`position: ${e.nativeEvent.position}`) + }} + /> + ); + } +} diff --git a/react-native/react-native.d.ts b/react-native/react-native.d.ts index 03b3e28c7..0bdae5196 100644 --- a/react-native/react-native.d.ts +++ b/react-native/react-native.d.ts @@ -979,6 +979,31 @@ declare namespace __React { } + /** + * @see https://facebook.github.io/react-native/docs/viewpagerandroid.html#props + */ + + + export interface ViewPagerAndroidOnPageScrollEventData { + position: number; + offset: number; + } + + export interface ViewPagerAndroidOnPageSelectedEventData { + position: number; + } + + export interface ViewPagerAndroidProperties extends ViewProperties { + initialPage?: number; + onPageScroll?: ( event: NativeSyntheticEvent ) => void; + onPageSelected?: ( event: NativeSyntheticEvent ) => void; + keyboardDismissMode?: string; /* enum('none', 'on-drag') */ + } + + export interface ViewPagerAndroidStatic extends NativeComponent, React.ComponentClass { + + } + /** * //FIXME: No documentation extracted from code comment on WebView.ios.js */ @@ -3364,6 +3389,9 @@ declare namespace __React { export var View: ViewStatic export type View = ViewStatic + export var ViewPagerAndroid: ViewPagerAndroidStatic + export type ViewPagerAndroid = ViewPagerAndroidStatic + export var WebView: WebViewStatic export type WebView = WebViewStatic From adb2d9174d90dc49c0c830a2a9d56987d29e2313 Mon Sep 17 00:00:00 2001 From: Jung-gun Lim Date: Wed, 17 Feb 2016 10:20:53 +0900 Subject: [PATCH 3/3] Update definition for react-native: Changed import syntax --- react-native/react-native-tests.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/react-native/react-native-tests.tsx b/react-native/react-native-tests.tsx index bb76ab8b1..ffb127b6c 100644 --- a/react-native/react-native-tests.tsx +++ b/react-native/react-native-tests.tsx @@ -21,14 +21,14 @@ For a list of complete Typescript examples: check https://github.com/bgrieder/RN import * as React from 'react-native' -const { +import { StyleSheet, Text, View, AppState, AppStateIOS, ViewPagerAndroid -} = React +} from 'react-native'; var styles = StyleSheet.create( {