From efce0c25ec532a4651859f10eda49e97a5716a42 Mon Sep 17 00:00:00 2001 From: bgrieder Date: Fri, 6 Nov 2015 22:01:15 +0100 Subject: [PATCH 01/15] Initial definitions for react-native 0.14 --- react-native/react-native-tests.tsx | 68 + react-native/react-native-tests.tsx.tscparams | 1 + react-native/react-native.d.ts | 1260 +++++++++++++++++ 3 files changed, 1329 insertions(+) create mode 100644 react-native/react-native-tests.tsx create mode 100644 react-native/react-native-tests.tsx.tscparams create mode 100644 react-native/react-native.d.ts diff --git a/react-native/react-native-tests.tsx b/react-native/react-native-tests.tsx new file mode 100644 index 000000000..4f2ef64d6 --- /dev/null +++ b/react-native/react-native-tests.tsx @@ -0,0 +1,68 @@ + +/* + +The content of index.io.js could be something like + + +'use strict'; + +import { AppRegistry } from 'react-native' +import Welcome from './gen/Welcome' + +AppRegistry.registerComponent('MopNative', () => Welcome); + + +*/ + +/// + + +import React from 'react-native' +const { StyleSheet, Text, View } = React + +var styles = StyleSheet.create( + { + container: { + flex: 1, + justifyContent: 'center', + alignItems: 'center', + backgroundColor: '#F5FCFF', + }, + welcome: { + fontSize: 20, + textAlign: 'center', + margin: 10, + }, + instructions: { + textAlign: 'center', + color: '#333333', + marginBottom: 5, + }, + } +) + + +class Welcome extends React.Component { + + + render() { + + return ( + + + Welcome to React Native + + + To get started, edit index.ios.js + + + Press Cmd+R to reload,{'\n'} + Cmd+D or shake for dev menu + + + ) + } +} + +export default Welcome + diff --git a/react-native/react-native-tests.tsx.tscparams b/react-native/react-native-tests.tsx.tscparams new file mode 100644 index 000000000..bc8c2d622 --- /dev/null +++ b/react-native/react-native-tests.tsx.tscparams @@ -0,0 +1 @@ +--target es6 --noImplicitAny --jsx react diff --git a/react-native/react-native.d.ts b/react-native/react-native.d.ts new file mode 100644 index 000000000..fe18baa09 --- /dev/null +++ b/react-native/react-native.d.ts @@ -0,0 +1,1260 @@ +// Type definitions for react-native 0.14 +// Project: https://github.com/facebook/react-native +// Definitions by: Bruno Grieder +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// +// This work is mostly based on the work made by Bernd Paradies: https://github.com/bparadie +// +// +// WARNING: this work is very much beta: +// -it may be missing react-native definitions +// -it re-exports the whole of react 0.14 which may not be what react-native actually does +// +/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +/// + +import React = __React; + +declare namespace ReactNative { + + + /** + * Represents the completion of an asynchronous operation + * @see lib.es6.d.ts + */ + export interface Promise { + /** + * Attaches callbacks for the resolution and/or rejection of the Promise. + * @param onfulfilled The callback to execute when the Promise is resolved. + * @param onrejected The callback to execute when the Promise is rejected. + * @returns A Promise for the completion of which ever callback is executed. + */ + then(onfulfilled?: (value: T) => TResult | Promise, onrejected?: (reason: any) => TResult | Promise): Promise; + + /** + * Attaches a callback for only the rejection of the Promise. + * @param onrejected The callback to execute when the Promise is rejected. + * @returns A Promise for the completion of the callback. + */ + catch(onrejected?: (reason: any) => T | Promise): Promise; + + + // not in lib.es6.d.ts but called by react-native + done(): void; + } + + export interface PromiseConstructor { + /** + * A reference to the prototype. + */ + prototype: Promise; + + /** + * Creates a new Promise. + * @param init A callback used to initialize the promise. This callback is passed two arguments: + * a resolve callback used resolve the promise with a value or the result of another promise, + * and a reject callback used to reject the promise with a provided reason or error. + */ + new (init: (resolve: (value?: T | Promise) => void, reject: (reason?: any) => void) => void): Promise; + + (init: (resolve: (value?: T | Promise) => void, reject: (reason?: any) => void) => void): Promise; + + /** + * Creates a Promise that is resolved with an array of results when all of the provided Promises + * resolve, or rejected when any Promise is rejected. + * @param values An array of Promises. + * @returns A new Promise. + */ + all(values: (T | Promise)[]): Promise; + + /** + * Creates a Promise that is resolved with an array of results when all of the provided Promises + * resolve, or rejected when any Promise is rejected. + * @param values An array of values. + * @returns A new Promise. + */ + all(values: Promise[]): Promise; + + /** + * Creates a Promise that is resolved or rejected when any of the provided Promises are resolved + * or rejected. + * @param values An array of Promises. + * @returns A new Promise. + */ + race(values: (T | Promise)[]): Promise; + + /** + * Creates a new rejected promise for the provided reason. + * @param reason The reason the promise was rejected. + * @returns A new rejected Promise. + */ + reject(reason: any): Promise; + + /** + * Creates a new rejected promise for the provided reason. + * @param reason The reason the promise was rejected. + * @returns A new rejected Promise. + */ + reject(reason: any): Promise; + + /** + * Creates a new resolved promise for the provided value. + * @param value A promise. + * @returns A promise whose internal state matches the provided promise. + */ + resolve(value: T | Promise): Promise; + + /** + * Creates a new resolved promise . + * @returns A resolved promise. + */ + resolve(): Promise; + } + + // @see lib.es6.d.ts + export var Promise: PromiseConstructor; + + // node_modules/react-tools/src/classic/class/ReactClass.js + export interface ReactClass + { + // TODO: + } + + // see react-jsx.d.ts + export function createElement

( + type: React.ReactType, + props?: P, + ...children: React.ReactNode[]): React.ReactElement

; + + + export type Runnable = (appParameters:any) => void; + + export type AppConfig = { + appKey: string; + component: ReactClass; + run?: Runnable; + } + + // https://github.com/facebook/react-native/blob/master/Libraries/AppRegistry/AppRegistry.js + export class AppRegistry + { + static registerConfig(config: AppConfig[]): void; + static registerComponent(appKey: string, getComponentFunc: () => React.ComponentClass): string; + static registerRunnable(appKey: string, func: Runnable): string; + static runApplication(appKey: string, appParameters: any): void; + } + + /* + export interface ReactPropTypes extends React.ReactPropTypes + { + + } + + export interface PropTypes + { + [key:string]: React.Requireable; + } + */ + + + export interface StyleSheetProperties + { + // TODO: + } + + export interface LayoutRectangle + { + x: number; + y: number; + width: number; + height: number; + } + + // @see TextProperties.onLayout + export interface LayoutChangeEvent + { + nativeEvent: { + layout: LayoutRectangle + } + } + + // @see https://facebook.github.io/react-native/docs/text.html#style + export interface TextStyle + { + color?: string; + containerBackgroundColor?: string; + fontFamily?: string; + fontSize?: number; + fontStyle?: string; // 'normal' | 'italic'; + fontWeight?: string; // enum("normal", 'bold', '100', '200', '300', '400', '500', '600', '700', '800', '900') + letterSpacing?: number; + lineHeight?: number; + textAlign?: string; // enum("auto", 'left', 'right', 'center') + writingDirection?: string; //enum("auto", 'ltr', 'rtl') + } + + // https://facebook.github.io/react-native/docs/text.html#props + export interface TextProperties + { + /** + * numberOfLines number + * + * Used to truncate the text with an elipsis after computing the text layout, including line wrapping, such that the total number of lines does not exceed this number. + */ + numberOfLines?: number; + + /** + * onLayout function + * + * Invoked on mount and layout changes with + * + * {nativeEvent: { layout: {x, y, width, height}}}. + */ + onLayout?: (event: LayoutChangeEvent) => void; + + /** + * onPress function + * + * This function is called on press. Text intrinsically supports press handling with a default highlight state (which can be disabled with suppressHighlighting). + */ + onPress?: () => void; + + /** + * @see https://facebook.github.io/react-native/docs/text.html#style + */ + style?: TextStyle; + } + + export interface AccessibilityTraits + { + // TODO + } + + // @see https://facebook.github.io/react-native/docs/view.html#style + export interface ViewStyle + { + backgroundColor?: string; + borderBottomColor?: string; + borderBottomLeftRadius?: number; + borderBottomRightRadius?: number; + borderColor?: string; + borderLeftColor?: string; + borderRadius?: number; + borderRightColor?: string; + borderTopColor?: string; + borderTopLeftRadius?: number; + borderTopRightRadius?: number; + opacity?: number; + overflow?: string; // enum('visible', 'hidden') + shadowColor?: string; + shadowOffset?: {width: number, height: number}; + shadowOpacity?: number; + shadowRadius?: number; + } + + /** + * @see https://facebook.github.io/react-native/docs/view.html#props + */ + export interface ViewProperties + { + /** + * accessibilityLabel string + * + * Overrides the text that's read by the screen reader when the user interacts with the element. By default, the label is constructed by traversing all the children and accumulating all the Text nodes separated by space. + * + */ + + accessibilityLabel?: string; + + + /** + * accessibilityTraits AccessibilityTraits, [AccessibilityTraits] + * Provides additional traits to screen reader. By default no traits are provided unless specified otherwise in element + */ + + accessibilityTraits?: AccessibilityTraits; + + /** + * accessible bool + * + * When true, indicates that the view is an accessibility element. By default, all the touchable elements are accessible. + */ + + accessible?: boolean; + + /** + * onAcccessibilityTap function + * When accessible is true, the system will try to invoke this function when the user performs accessibility tap gesture. + * + */ + + onAcccessibilityTap?: () => void; + + /** + * onLayout function + * + * Invoked on mount and layout changes with + * + * {nativeEvent: { layout: {x, y, width, height}}}. + */ + onLayout?: (event: LayoutChangeEvent) => void; + + /** + * onMagicTap function + * + * When accessible is true, the system will invoke this function when the user performs the magic tap gesture. + */ + + onMagicTap?: () => void; + + /** + * onMoveShouldSetResponder function + * + * For most touch interactions, you'll simply want to wrap your component in TouchableHighlight or TouchableOpacity. Check out Touchable.js, ScrollResponder.js and ResponderEventPlugin.js for more discussion. + */ + onMoveShouldSetResponder?: () => void; + + onResponderGrant?: () => void; + + onResponderMove?: () => void; + + onResponderReject?: () => void; + + onResponderRelease?: () => void; + + onResponderTerminate?: () => void; + + onResponderTerminationRequest?: () => void; + + onStartShouldSetResponder?: () => void; + + onStartShouldSetResponderCapture?: () => void; + + /** + * pointerEvents enum('box-none', 'none', 'box-only', 'auto') + * + * In the absence of auto property, none is much like CSS's none value. box-none is as if you had applied the CSS class: + * + * .box-none { + * pointer-events: none; + * } + * .box-none * { + * pointer-events: all; + * } + * + * box-only is the equivalent of + * + * .box-only { + * pointer-events: all; + * } + * .box-only * { + * pointer-events: none; + * } + * + * But since pointerEvents does not affect layout/appearance, and we are already deviating from the spec by adding additional modes, + * we opt to not include pointerEvents on style. On some platforms, we would need to implement it as a className anyways. Using style or not is an implementation detail of the platform. + */ + + pointerEvents?: string; + + /** + * removeClippedSubviews bool + * + * This is a special performance property exposed by RCTView and is useful for scrolling content when there are many subviews, + * most of which are offscreen. For this property to be effective, it must be applied to a view that contains many subviews that extend outside its bound. + * The subviews must also have overflow: hidden, as should the containing view (or one of its superviews). + */ + + removeClippedSubviews?: boolean + + /** + * renderToHardwareTextureAndroid bool + * + * Whether this view should render itself (and all of its children) into a single hardware texture on the GPU. + * + * On Android, this is useful for animations and interactions that only modify opacity, rotation, translation, and/or scale: + * in those cases, the view doesn't have to be redrawn and display lists don't need to be re-executed. The texture can just be + * re-used and re-composited with different parameters. The downside is that this can use up limited video memory, so this prop should be set back to false at the end of the interaction/animation. + */ + + renderToHardwareTextureAndroid?: boolean; + + style?: ViewStyle; + + /** + * testID string + * + * Used to locate this view in end-to-end tests. + */ + + testID?: string; + } + + /** + * @see https://facebook.github.io/react-native/docs/activityindicatorios.html#props + */ + export interface AlertIOSProperties + { + /** + * animating bool + * + * Whether to show the indicator (true, the default) or hide it (false). + */ + animating?: boolean; + + /** + * color string + * + * The foreground color of the spinner (default is gray). + */ + + color?: string; + + /** + * hidesWhenStopped bool + * + * Whether the indicator should hide when not animating (true by default). + */ + + hidesWhenStopped?: boolean; + + /** + * onLayout function + * + * Invoked on mount and layout changes with + * + * {nativeEvent: { layout: {x, y, width, height}}}. + */ + onLayout?: (event: LayoutChangeEvent) => void; + + /** + * size enum('small', 'large') + * + * Size of the indicator. Small has a height of 20, large has a height of 36. + */ + size: string; // enum('small', 'large') + } + + /** + * @see + */ + export interface SegmentedControlIOSProperties + { + /// TODO + } + + /** + * @see + */ + export interface SwitchIOSProperties + { + /// TODO + } + + /** + * @see + */ + export interface NavigatorProperties + { + /// TODO + } + + /** + * @see + */ + export interface ActivityIndicatorIOSProperties + { + /// TODO + } + + /** + * @see https://facebook.github.io/react-native/docs/sliderios.html + */ + export interface SliderIOSProperties + { + /** + maximumTrackTintColor string + The color used for the track to the right of the button. Overrides the default blue gradient image. + */ + maximumTrackTintColor?: string; + + /** + maximumValue number + + Initial maximum value of the slider. Default value is 1. + */ + maximumValue?: number; + + /** + minimumTrackTintColor string + The color used for the track to the left of the button. Overrides the default blue gradient image. + */ + minimumTrackTintColor?: string; + + /** + minimumValue number + Initial minimum value of the slider. Default value is 0. + */ + minimumValue?: number; + + /** + onSlidingComplete function + Callback called when the user finishes changing the value (e.g. when the slider is released). + */ + onSlidingComplete?: () => void; + + /** + onValueChange function + Callback continuously called while the user is dragging the slider. + */ + onValueChange?: (value: number) => void; + + /** + value number + Initial value of the slider. The value should be between minimumValue and maximumValue, which default to 0 and 1 respectively. Default value is 0. + + This is not a controlled component, e.g. if you don't update the value, the component won't be reset to its inital value. + */ + value?: number; + } + + /** + * @see + */ + export interface CameraRollProperties + { + /// TODO + } + + /** + * @see + */ + export interface ImageProperties + { + /// TODO + } + + /** + * @see + */ + export interface ListViewProperties + { + /// TODO + } + + /** + * @see https://facebook.github.io/react-native/docs/touchablehighlight.html#props + */ + export interface TouchableHighlightProperties + { + /** + * activeOpacity number + * + * Determines what the opacity of the wrapped view should be when touch is active. + */ + activeOpacity?: number; + + /** + * onHideUnderlay function + * + * Called immediately after the underlay is hidden + */ + + onHideUnderlay?: () => void; + + + /** + * onShowUnderlay function + * + * Called immediately after the underlay is shown + */ + + /** + * @see https://facebook.github.io/react-native/docs/view.html#style + */ + style?: ViewStyle; + + + /** + * underlayColor string + * + * The color of the underlay that will show through when the touch is active. + */ + underlayColor?: string; + + } + + /** + * @see https://facebook.github.io/react-native/docs/touchablewithoutfeedback.html + */ + export interface TouchableWithoutFeedbackProperties + { + /* + accessible bool + + Called when the touch is released, but not if cancelled (e.g. by a scroll that steals the responder lock). + */ + accessible?: boolean; + /* + delayLongPress number + + Delay in ms, from onPressIn, before onLongPress is called. + */ + delayLongPress?: number; + + /* + delayPressIn number + + Delay in ms, from the start of the touch, before onPressIn is called. + */ + delayPressIn?: number; + + /* + delayPressOut number + + Delay in ms, from the release of the touch, before onPressOut is called. + */ + delayPressOut?: number; + + /* + onLongPress function + */ + onLongPress?: () => void; + + /* + onPress function + */ + onPress?: () => void; + + /* + onPressIn function + */ + onPressIn?: () => void; + + /* + onPressOut function + */ + onPressOut?: () => void; + } + + + /** + * @see https://facebook.github.io/react-native/docs/touchableopacity.html#props + */ + export interface TouchableOpacityProperties + { + /** + * activeOpacity number + * + * Determines what the opacity of the wrapped view should be when touch is active. + */ + activeOpacity?: number; + } + + + export interface LeftToRightGesture + { + + } + + export interface AnimationInterpolator + { + + } + + // see /NavigatorSceneConfigs.js + export interface SceneConfig + { + // A list of all gestures that are enabled on this scene + gestures: { + pop: LeftToRightGesture, + }, + + // Rebound spring parameters when transitioning FROM this scene + springFriction: number; + springTension: number; + + // Velocity to start at when transitioning without gesture + defaultTransitionVelocity: number; + + // Animation interpolators for horizontal transitioning: + animationInterpolators: { + into: AnimationInterpolator, + out: AnimationInterpolator + }; + + } + + // see /NavigatorSceneConfigs.js + export interface SceneConfigs + { + FloatFromBottom: SceneConfig; + FloatFromRight: SceneConfig; + PushFromRight: SceneConfig; + FloatFromLeft: SceneConfig; + HorizontalSwipeJump: SceneConfig; + } + + export interface Route { + id: string; + title?: string; + } + + /** + * @see + */ + export interface NavigatorBarProperties + { + + } + + export interface NavigationBar extends React.ComponentClass + { + + } + + export interface NavigatorStatic extends React.ComponentClass + { + SceneConfigs: SceneConfigs; + getContext(self:any): NavigatorStatic; + + push(route: Route): void; + pop(): void; + popToTop(): void; + popToRoute( route: Route ): void; + immediatelyResetRouteStack( routes: Route[] ): void; + getCurrentRoutes(): Route[]; + + NavigationBar: NavigationBar; + } + + export interface StyleSheetStatic extends React.ComponentClass + { + create(styles:T): T; + } + + export interface DataSourceAssetCallback + { + rowHasChanged: (r1: any[], r2: any[]) => boolean; + } + + export interface ListViewDataSource + { + new(onAsset: DataSourceAssetCallback): ListViewDataSource; + cloneWithRows(rowList:T[][]): void; + } + + export interface ListViewStatic extends React.ComponentClass + { + DataSource: ListViewDataSource; + } + + export interface ImageStatic extends React.ComponentClass + { + uri: string; + } + + /** + * @see + */ + export interface TabBarItemProperties + { + + } + + export interface TabBarItem extends React.ComponentClass + { + } + + /** + * @see + */ + export interface TabBarIOSProperties + { + } + + export interface TabBarIOSStatic extends React.ComponentClass + { + Item: TabBarItem; + } + + export interface CameraRollFetchParams + { + first: number; + groupTypes: string; + after?: string; + } + + export interface CameraRollNodeInfo + { + image: Image; + group_name: string; + timestamp: number; + location: any; + } + + export interface CameraRollEdgeInfo + { + node: CameraRollNodeInfo; + } + + export interface CameraRollAssetInfo + { + edges: CameraRollEdgeInfo[]; + page_info: { + has_next_page: boolean; + end_cursor: string; + }; + } + + export interface CameraRollStatic extends React.ComponentClass + { + getPhotos(fetch: CameraRollFetchParams, + onAsset: (assetInfo: CameraRollAssetInfo) => void, + logError: ()=> void): void; + } + + export interface PanHandlers + { + + } + + export interface PanResponderEvent + { + + } + + export interface PanResponderGestureState + { + stateID: number; + moveX: number; + moveY: number; + x0: number; + y0: number; + dx: number; + dy: number; + vx: number; + vy: number; + numberActiveTouches: number; + // All `gestureState` accounts for timeStamps up until: + _accountsForMovesUpTo: number; + } + + /** + * @param {object} config Enhanced versions of all of the responder callbacks + * that provide not only the typical `ResponderSyntheticEvent`, but also the + * `PanResponder` gesture state. Simply replace the word `Responder` with + * `PanResponder` in each of the typical `onResponder*` callbacks. For + * example, the `config` object would look like: + * + * - `onMoveShouldSetPanResponder: (e, gestureState) => {...}` + * - `onMoveShouldSetPanResponderCapture: (e, gestureState) => {...}` + * - `onStartShouldSetPanResponder: (e, gestureState) => {...}` + * - `onStartShouldSetPanResponderCapture: (e, gestureState) => {...}` + * - `onPanResponderReject: (e, gestureState) => {...}` + * - `onPanResponderGrant: (e, gestureState) => {...}` + * - `onPanResponderStart: (e, gestureState) => {...}` + * - `onPanResponderEnd: (e, gestureState) => {...}` + * - `onPanResponderRelease: (e, gestureState) => {...}` + * - `onPanResponderMove: (e, gestureState) => {...}` + * - `onPanResponderTerminate: (e, gestureState) => {...}` + * - `onPanResponderTerminationRequest: (e, gestureState) => {...}` + * + * In general, for events that have capture equivalents, we update the + * gestureState once in the capture phase and can use it in the bubble phase + * as well. + * + * Be careful with onStartShould* callbacks. They only reflect updated + * `gestureState` for start/end events that bubble/capture to the Node. + * Once the node is the responder, you can rely on every start/end event + * being processed by the gesture and `gestureState` being updated + * accordingly. (numberActiveTouches) may not be totally accurate unless you + * are the responder. + */ + export interface PanResponderCallbacks + { + onMoveShouldSetPanResponder?: (e: PanResponderEvent, gestureState: PanResponderGestureState) => boolean; + onStartShouldSetPanResponder?: (e: PanResponderEvent, gestureState: PanResponderGestureState) => void; + onPanResponderGrant?: (e: PanResponderEvent, gestureState: PanResponderGestureState) => void; + onPanResponderMove?: (e: PanResponderEvent, gestureState: PanResponderGestureState) => void; + onPanResponderRelease?: (e: PanResponderEvent, gestureState: PanResponderGestureState) => void; + onPanResponderTerminate?: (e: PanResponderEvent, gestureState: PanResponderGestureState) => void; + + onMoveShouldSetPanResponderCapture?: (e: PanResponderEvent, gestureState: PanResponderGestureState) => boolean; + onStartShouldSetPanResponderCapture?: (e: PanResponderEvent, gestureState: PanResponderGestureState) => boolean; + onPanResponderReject?: (e: PanResponderEvent, gestureState: PanResponderGestureState) => void; + onPanResponderStart?: (e: PanResponderEvent, gestureState: PanResponderGestureState) => void; + onPanResponderEnd?: (e: PanResponderEvent, gestureState: PanResponderGestureState) => void; + onPanResponderTerminationRequest?: (e: PanResponderEvent, gestureState: PanResponderGestureState) => void; + } + + export interface PanResponderInstance + { + panHandlers: PanHandlers; + } + + export interface PanResponderStatic + { + create(callbacks: PanResponderCallbacks): PanResponderInstance; + } + + export interface PixelRatioStatic + { + get(): number; + } + + export interface DeviceEventSubscriptionStatic + { + remove(): void; + } + + export interface DeviceEventEmitterStatic + { + addListener(type:string, onReceived: (data:T) => void): DeviceEventSubscription; + } + + // Used by Dimensions below + export interface ScaledSize + { + width: number; + height: number; + scale: number; + } + + // @see https://facebook.github.io/react-native/docs/asyncstorage.html#content + export interface AsyncStorageStatic + { + getItem(key: string, callback?: (error?: Error, result?: string) => void): Promise; + setItem(key: string, value: string, callback?: (error?: Error) => void): Promise; + removeItem(key: string, callback?: (error?: Error) => void): Promise; + mergeItem(key: string, value: string, callback?: (error?: Error) => void): Promise; + clear(callback?: (error?: Error) => void): Promise; + getAllKeys(callback?: (error?: Error, keys?: string[]) => void): Promise; + multiGet(keys: string[], callback?: (errors?: Error[], result?: string[][]) => void): Promise; + multiSet(keyValuePairs: string[][], callback?: (errors?: Error[]) => void): Promise; + multiRemove(keys: string[], callback?: (errors?: Error[]) => void): Promise; + multiMerge(keyValuePairs: string[][], callback?: (errors?: Error[]) => void): Promise; + } + + export interface InteractionManagerStatic + { + runAfterInteractions( fn: () => void ): void; + } + + export interface ScrollViewProperties + { + + } + + + export interface NativeScrollRectangle + { + left: number; + top: number; + bottom: number; + right: number; + } + + export interface NativeScrollPoint + { + x: number; + y: number; + } + + export interface NativeScrollSize + { + height: number; + width: number; + } + + export interface NativeScrollEvent + { + contentInset: NativeScrollRectangle; + contentOffset: NativeScrollPoint; + contentSize: NativeScrollSize; + layoutMeasurement: NativeScrollSize; + zoomScale: number; + } + + export interface AppStateIOSStatic + { + currentState: string; + addEventListener( type: string, listener: (state: string) => void ): void; + removeEventListener( type: string, listener: (state: string) => void ): void; + } + + // exported singletons: + // export var AppRegistry: AppRegistryStatic; + export var StyleSheet: StyleSheetStatic; + export var Navigator: NavigatorStatic; + export type Navigator = NavigatorStatic; + export var ListView: ListViewStatic; + export var CameraRoll: CameraRollStatic; + export var Image: ImageStatic; + export type Image = ImageStatic; + export var TabBarIOS: TabBarIOSStatic; + export type TabBarIOS = TabBarIOSStatic; + export var AsyncStorage: AsyncStorageStatic; + + export var Text: React.ComponentClass; + export var View: React.ComponentClass; + export var AlertIOS: React.ComponentClass; + export var SegmentedControlIOS: React.ComponentClass; + export var SwitchIOS: React.ComponentClass; + export var TouchableHighlight: React.ComponentClass; + export var TouchableOpacity: React.ComponentClass; + export var TouchableWithoutFeedback: React.ComponentClass; + + + export var ActivityIndicatorIOS: React.ComponentClass; + export var PixelRatio: PixelRatioStatic; + export var DeviceEventEmitter: DeviceEventEmitterStatic; + export var DeviceEventSubscription: DeviceEventSubscriptionStatic; + export type DeviceEventSubscription = DeviceEventSubscriptionStatic; + export var InteractionManager: InteractionManagerStatic; + export var ScrollView: React.ComponentClass; + export var PanResponder: PanResponderStatic; + export var SliderIOS: React.ComponentClass; + export var AppStateIOS: AppStateIOSStatic; + + + //react re-exported + export type ReactType = React.ReactType; + + export interface ReactElement

extends React.ReactElement

{} + + export interface ClassicElement

extends React.ClassicElement

{} + + export interface DOMElement

extends React.DOMElement

{} + + export type HTMLElement =React.HTMLElement; + export type SVGElement = React.SVGElement; + + // + // Factories + // ---------------------------------------------------------------------- + + export interface Factory

extends React.Factory

{} + + export interface ClassicFactory

extends React.ClassicFactory

{} + + export interface DOMFactory

extends React.DOMFactory

{} + + export type HTMLFactory = React.HTMLFactory; + export type SVGFactory = React.SVGFactory; + export type SVGElementFactory = React.SVGElementFactory; + + // + // React Nodes + // http://facebook.github.io/react/docs/glossary.html + // ---------------------------------------------------------------------- + + export type ReactText = React.ReactText; + export type ReactChild = React.ReactChild; + + // Should be Array but type aliases cannot be recursive + export type ReactFragment = React.ReactFragment; + export type ReactNode = React.ReactNode; + + // + // Top Level API + // ---------------------------------------------------------------------- + + export function createClass(spec: React.ComponentSpec): React.ClassicComponentClass

; + + export function createFactory

(type: string): React.DOMFactory

; + export function createFactory

(type: React.ClassicComponentClass

| string): React.ClassicFactory

; + export function createFactory

(type: React.ComponentClass

): React.Factory

; + + export function createElement

( + type: string, + props?: P, + ...children: React.ReactNode[]): React.DOMElement

; + export function createElement

( + type: React.ClassicComponentClass

| string, + props?: P, + ...children: React.ReactNode[]): React.ClassicElement

; + export function createElement

( + type: React.ComponentClass

, + props?: P, + ...children: React.ReactNode[]): React.ReactElement

; + + export function cloneElement

( + element: React.DOMElement

, + props?: P, + ...children: React.ReactNode[]): React.DOMElement

; + export function cloneElement

( + element: React.ClassicElement

, + props?: P, + ...children: React.ReactNode[]): React.ClassicElement

; + export function cloneElement

( + element: React.ReactElement

, + props?: P, + ...children: React.ReactNode[]): React.ReactElement

; + + export function isValidElement(object: {}): boolean; + + export var DOM: React.ReactDOM; + export var PropTypes: React.ReactPropTypes; + export var Children: React.ReactChildren; + + // + // Component API + // ---------------------------------------------------------------------- + + // Base component for plain JS classes + export class Component extends React.Component{} + + export interface ClassicComponent extends React.ClassicComponent {} + + export interface DOMComponent

extends ClassicComponent { + tagName: string; + } + + export type HTMLComponent = React.HTMLComponent; + export type SVGComponent = React.SVGComponent + + export interface ChildContextProvider extends React.ChildContextProvider{} + + // + // Class Interfaces + // ---------------------------------------------------------------------- + + export interface ComponentClass

extends React.ComponentClass

{} + + export interface ClassicComponentClass

extends React.ClassicComponentClass

{} + + // + // Component Specs and Lifecycle + // ---------------------------------------------------------------------- + + export interface ComponentLifecycle extends React.ComponentLifecycle{} + + export interface Mixin extends React.Mixin{} + + export interface ComponentSpec extends React.ComponentSpec{} + + // + // Event System + // ---------------------------------------------------------------------- + + interface SyntheticEvent extends React.SyntheticEvent{} + + interface DragEvent extends React.DragEvent{} + + interface ClipboardEvent extends React.ClipboardEvent{} + + interface KeyboardEvent extends React.KeyboardEvent{} + + + interface FocusEvent extends React.FocusEvent{} + + interface FormEvent extends React.FormEvent {} + + interface MouseEvent extends React.MouseEvent {} + + interface TouchEvent extends React.TouchEvent {} + + interface UIEvent extends React.UIEvent {} + + interface WheelEvent extends React.WheelEvent {} + + // + // Event Handler Types + // ---------------------------------------------------------------------- + + interface EventHandler extends React.EventHandler{} + + interface DragEventHandler extends React.DragEventHandler {} + interface ClipboardEventHandler extends React.ClipboardEventHandler {} + interface KeyboardEventHandler extends React.KeyboardEventHandler {} + interface FocusEventHandler extends React.FocusEventHandler {} + interface FormEventHandler extends React.FormEventHandler {} + interface MouseEventHandler extends React.MouseEventHandler {} + interface TouchEventHandler extends React.TouchEventHandler {} + interface UIEventHandler extends React.UIEventHandler {} + interface WheelEventHandler extends React.WheelEventHandler{} + + // + // Props / DOM Attributes + // ---------------------------------------------------------------------- + + interface Props extends React.Props{} + + interface DOMAttributesBase extends React.DOMAttributesBase{} + + interface DOMAttributes extends React.DOMAttributes{} + + // This interface is not complete. Only properties accepting + // unitless numbers are listed here (see CSSProperty.js in React) + interface CSSProperties extends React.CSSProperties{} + + interface HTMLAttributesBase extends React.HTMLAttributesBase{} + + interface HTMLAttributes extends React.HTMLAttributes{} + + interface SVGElementAttributes extends React.SVGElementAttributes{} + + interface SVGAttributes extends React.SVGAttributes{} + + // + // React.DOM + // ---------------------------------------------------------------------- + + interface ReactDOM extends React.ReactDOM{} + + // + // React.PropTypes + // ---------------------------------------------------------------------- + + interface Validator extends React.Validator{} + + interface Requireable extends React.Requireable {} + + interface ValidationMap extends React.ValidationMap{} + + interface ReactPropTypes extends React.ReactPropTypes{} + + // + // React.Children + // ---------------------------------------------------------------------- + + interface ReactChildren extends React.ReactChildren{} + + // + // Browser Interfaces + // https://github.com/nikeee/2048-typescript/blob/master/2048/js/touch.d.ts + // ---------------------------------------------------------------------- + + interface AbstractView extends React.AbstractView{} + + interface Touch extends React.Touch{} + + interface TouchList extends React.TouchList{} + + + export function __spread(target:any, ...sources:any[]): any; +} + +declare module "react-native" { + + export default ReactNative +} + + + +declare module "Dimensions" +{ + import React from 'react-native'; + + interface Dimensions + { + get(what:string): React.ScaledSize; + } + + var ExportDimensions: Dimensions; + export = ExportDimensions; +} From c4d24f7f7e98fdfa69a0c8a44351375c9f0ab44b Mon Sep 17 00:00:00 2001 From: bgrieder Date: Fri, 6 Nov 2015 22:20:52 +0100 Subject: [PATCH 02/15] Note on using ES6 as the target --- react-native/react-native-tests.tsx | 3 +++ react-native/react-native-tests.tsx.tscparams | 2 +- react-native/react-native.d.ts | 1 + 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/react-native/react-native-tests.tsx b/react-native/react-native-tests.tsx index 4f2ef64d6..7c02ce9ca 100644 --- a/react-native/react-native-tests.tsx +++ b/react-native/react-native-tests.tsx @@ -1,6 +1,9 @@ /* +Note: This must be compiled with the target set to ES6 + + The content of index.io.js could be something like diff --git a/react-native/react-native-tests.tsx.tscparams b/react-native/react-native-tests.tsx.tscparams index bc8c2d622..b928cbf7c 100644 --- a/react-native/react-native-tests.tsx.tscparams +++ b/react-native/react-native-tests.tsx.tscparams @@ -1 +1 @@ ---target es6 --noImplicitAny --jsx react +--target ES6 --noImplicitAny --experimentalDecorators --jsx react diff --git a/react-native/react-native.d.ts b/react-native/react-native.d.ts index fe18baa09..bc1926a30 100644 --- a/react-native/react-native.d.ts +++ b/react-native/react-native.d.ts @@ -7,6 +7,7 @@ // // This work is mostly based on the work made by Bernd Paradies: https://github.com/bparadie // +// These definitions are meant to be used with the compiler target set to ES6 // // WARNING: this work is very much beta: // -it may be missing react-native definitions From 281006bf74486985e994ddb0e53f7d0b9edb1b03 Mon Sep 17 00:00:00 2001 From: bgrieder Date: Fri, 6 Nov 2015 22:40:15 +0100 Subject: [PATCH 03/15] Test building using es5/commonjs --- react-native/react-native-tests.tsx.tscparams | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/react-native/react-native-tests.tsx.tscparams b/react-native/react-native-tests.tsx.tscparams index b928cbf7c..7cf88bb1b 100644 --- a/react-native/react-native-tests.tsx.tscparams +++ b/react-native/react-native-tests.tsx.tscparams @@ -1 +1 @@ ---target ES6 --noImplicitAny --experimentalDecorators --jsx react +--target es5 --noImplicitAny --experimentalDecorators --jsx react --module commonjs From b2ce26a078c850923a3aa81b7112bfdf7a98af62 Mon Sep 17 00:00:00 2001 From: bgrieder Date: Sat, 7 Nov 2015 07:03:49 +0100 Subject: [PATCH 04/15] Fixed missing exports --- react-native/react-native.d.ts | 74 +++++++++++++++++----------------- 1 file changed, 37 insertions(+), 37 deletions(-) diff --git a/react-native/react-native.d.ts b/react-native/react-native.d.ts index bc1926a30..ad6b132ea 100644 --- a/react-native/react-native.d.ts +++ b/react-native/react-native.d.ts @@ -1142,99 +1142,99 @@ declare namespace ReactNative { // Event System // ---------------------------------------------------------------------- - interface SyntheticEvent extends React.SyntheticEvent{} + export interface SyntheticEvent extends React.SyntheticEvent{} - interface DragEvent extends React.DragEvent{} + export interface DragEvent extends React.DragEvent{} - interface ClipboardEvent extends React.ClipboardEvent{} + export interface ClipboardEvent extends React.ClipboardEvent{} - interface KeyboardEvent extends React.KeyboardEvent{} + export interface KeyboardEvent extends React.KeyboardEvent{} - interface FocusEvent extends React.FocusEvent{} + export interface FocusEvent extends React.FocusEvent{} - interface FormEvent extends React.FormEvent {} + export interface FormEvent extends React.FormEvent {} - interface MouseEvent extends React.MouseEvent {} + export interface MouseEvent extends React.MouseEvent {} - interface TouchEvent extends React.TouchEvent {} + export interface TouchEvent extends React.TouchEvent {} - interface UIEvent extends React.UIEvent {} + export interface UIEvent extends React.UIEvent {} - interface WheelEvent extends React.WheelEvent {} + export interface WheelEvent extends React.WheelEvent {} // // Event Handler Types // ---------------------------------------------------------------------- - interface EventHandler extends React.EventHandler{} + export interface EventHandler extends React.EventHandler{} - interface DragEventHandler extends React.DragEventHandler {} - interface ClipboardEventHandler extends React.ClipboardEventHandler {} - interface KeyboardEventHandler extends React.KeyboardEventHandler {} - interface FocusEventHandler extends React.FocusEventHandler {} - interface FormEventHandler extends React.FormEventHandler {} - interface MouseEventHandler extends React.MouseEventHandler {} - interface TouchEventHandler extends React.TouchEventHandler {} - interface UIEventHandler extends React.UIEventHandler {} - interface WheelEventHandler extends React.WheelEventHandler{} + export interface DragEventHandler extends React.DragEventHandler {} + export interface ClipboardEventHandler extends React.ClipboardEventHandler {} + export interface KeyboardEventHandler extends React.KeyboardEventHandler {} + export interface FocusEventHandler extends React.FocusEventHandler {} + export interface FormEventHandler extends React.FormEventHandler {} + export interface MouseEventHandler extends React.MouseEventHandler {} + export interface TouchEventHandler extends React.TouchEventHandler {} + export interface UIEventHandler extends React.UIEventHandler {} + export interface WheelEventHandler extends React.WheelEventHandler{} // // Props / DOM Attributes // ---------------------------------------------------------------------- - interface Props extends React.Props{} + export interface Props extends React.Props{} - interface DOMAttributesBase extends React.DOMAttributesBase{} + export interface DOMAttributesBase extends React.DOMAttributesBase{} - interface DOMAttributes extends React.DOMAttributes{} + export interface DOMAttributes extends React.DOMAttributes{} // This interface is not complete. Only properties accepting // unitless numbers are listed here (see CSSProperty.js in React) - interface CSSProperties extends React.CSSProperties{} + export interface CSSProperties extends React.CSSProperties{} - interface HTMLAttributesBase extends React.HTMLAttributesBase{} + export interface HTMLAttributesBase extends React.HTMLAttributesBase{} - interface HTMLAttributes extends React.HTMLAttributes{} + export interface HTMLAttributes extends React.HTMLAttributes{} - interface SVGElementAttributes extends React.SVGElementAttributes{} + export interface SVGElementAttributes extends React.SVGElementAttributes{} - interface SVGAttributes extends React.SVGAttributes{} + export interface SVGAttributes extends React.SVGAttributes{} // // React.DOM // ---------------------------------------------------------------------- - interface ReactDOM extends React.ReactDOM{} + export interface ReactDOM extends React.ReactDOM{} // // React.PropTypes // ---------------------------------------------------------------------- - interface Validator extends React.Validator{} + export interface Validator extends React.Validator{} - interface Requireable extends React.Requireable {} + export interface Requireable extends React.Requireable {} - interface ValidationMap extends React.ValidationMap{} + export interface ValidationMap extends React.ValidationMap{} - interface ReactPropTypes extends React.ReactPropTypes{} + export interface ReactPropTypes extends React.ReactPropTypes{} // // React.Children // ---------------------------------------------------------------------- - interface ReactChildren extends React.ReactChildren{} + export interface ReactChildren extends React.ReactChildren{} // // Browser Interfaces // https://github.com/nikeee/2048-typescript/blob/master/2048/js/touch.d.ts // ---------------------------------------------------------------------- - interface AbstractView extends React.AbstractView{} + export interface AbstractView extends React.AbstractView{} - interface Touch extends React.Touch{} + export interface Touch extends React.Touch{} - interface TouchList extends React.TouchList{} + export interface TouchList extends React.TouchList{} export function __spread(target:any, ...sources:any[]): any; From 00d496b4c45cc4050ebc0943729b5ce03951fd4e Mon Sep 17 00:00:00 2001 From: bgrieder Date: Sat, 7 Nov 2015 08:27:42 +0100 Subject: [PATCH 05/15] added FlexStyle and ImageProperties --- react-native/react-native.d.ts | 584 ++++++++++++++++++--------------- 1 file changed, 326 insertions(+), 258 deletions(-) diff --git a/react-native/react-native.d.ts b/react-native/react-native.d.ts index ad6b132ea..592cecdaf 100644 --- a/react-native/react-native.d.ts +++ b/react-native/react-native.d.ts @@ -33,14 +33,14 @@ declare namespace ReactNative { * @param onrejected The callback to execute when the Promise is rejected. * @returns A Promise for the completion of which ever callback is executed. */ - then(onfulfilled?: (value: T) => TResult | Promise, onrejected?: (reason: any) => TResult | Promise): Promise; + then( onfulfilled?: ( value: T ) => TResult | Promise, onrejected?: ( reason: any ) => TResult | Promise ): Promise; /** * Attaches a callback for only the rejection of the Promise. * @param onrejected The callback to execute when the Promise is rejected. * @returns A Promise for the completion of the callback. */ - catch(onrejected?: (reason: any) => T | Promise): Promise; + catch( onrejected?: ( reason: any ) => T | Promise ): Promise; // not in lib.es6.d.ts but called by react-native @@ -59,9 +59,9 @@ declare namespace ReactNative { * a resolve callback used resolve the promise with a value or the result of another promise, * and a reject callback used to reject the promise with a provided reason or error. */ - new (init: (resolve: (value?: T | Promise) => void, reject: (reason?: any) => void) => void): Promise; + new ( init: ( resolve: ( value?: T | Promise ) => void, reject: ( reason?: any ) => void ) => void ): Promise; - (init: (resolve: (value?: T | Promise) => void, reject: (reason?: any) => void) => void): Promise; + ( init: ( resolve: ( value?: T | Promise ) => void, reject: ( reason?: any ) => void ) => void ): Promise; /** * Creates a Promise that is resolved with an array of results when all of the provided Promises @@ -69,7 +69,7 @@ declare namespace ReactNative { * @param values An array of Promises. * @returns A new Promise. */ - all(values: (T | Promise)[]): Promise; + all( values: (T | Promise)[] ): Promise; /** * Creates a Promise that is resolved with an array of results when all of the provided Promises @@ -77,7 +77,7 @@ declare namespace ReactNative { * @param values An array of values. * @returns A new Promise. */ - all(values: Promise[]): Promise; + all( values: Promise[] ): Promise; /** * Creates a Promise that is resolved or rejected when any of the provided Promises are resolved @@ -85,28 +85,28 @@ declare namespace ReactNative { * @param values An array of Promises. * @returns A new Promise. */ - race(values: (T | Promise)[]): Promise; + race( values: (T | Promise)[] ): Promise; /** * Creates a new rejected promise for the provided reason. * @param reason The reason the promise was rejected. * @returns A new rejected Promise. */ - reject(reason: any): Promise; + reject( reason: any ): Promise; /** * Creates a new rejected promise for the provided reason. * @param reason The reason the promise was rejected. * @returns A new rejected Promise. */ - reject(reason: any): Promise; + reject( reason: any ): Promise; /** * Creates a new resolved promise for the provided value. * @param value A promise. * @returns A promise whose internal state matches the provided promise. */ - resolve(value: T | Promise): Promise; + resolve( value: T | Promise ): Promise; /** * Creates a new resolved promise . @@ -119,19 +119,17 @@ declare namespace ReactNative { export var Promise: PromiseConstructor; // node_modules/react-tools/src/classic/class/ReactClass.js - export interface ReactClass - { + export interface ReactClass { // TODO: } // see react-jsx.d.ts - export function createElement

( - type: React.ReactType, - props?: P, - ...children: React.ReactNode[]): React.ReactElement

; + export function createElement

( type: React.ReactType, + props?: P, + ...children: React.ReactNode[] ): React.ReactElement

; - export type Runnable = (appParameters:any) => void; + export type Runnable = ( appParameters: any ) => void; export type AppConfig = { appKey: string; @@ -140,12 +138,14 @@ declare namespace ReactNative { } // https://github.com/facebook/react-native/blob/master/Libraries/AppRegistry/AppRegistry.js - export class AppRegistry - { - static registerConfig(config: AppConfig[]): void; - static registerComponent(appKey: string, getComponentFunc: () => React.ComponentClass): string; - static registerRunnable(appKey: string, func: Runnable): string; - static runApplication(appKey: string, appParameters: any): void; + export class AppRegistry { + static registerConfig( config: AppConfig[] ): void; + + static registerComponent( appKey: string, getComponentFunc: () => React.ComponentClass ): string; + + static registerRunnable( appKey: string, func: Runnable ): string; + + static runApplication( appKey: string, appParameters: any ): void; } /* @@ -160,14 +160,52 @@ declare namespace ReactNative { } */ + /** + * Flex Prop Types + * @see https://facebook.github.io/react-native/docs/flexbox.html#proptypes + */ + export interface FlexStyle { - export interface StyleSheetProperties - { + alignItems?: string; //enum('flex-start', 'flex-end', 'center', 'stretch') + alignSelf?: string// enum('auto', 'flex-start', 'flex-end', 'center', 'stretch') + borderBottomWidth?: number + borderLeftWidth?: number + borderRightWidth?: number + borderTopWidth?: number + borderWidth?: number + bottom?: number + flex?: number + flexDirection?: string // enum('row', 'column') + flexWrap?: string // enum('wrap', 'nowrap') + height?: number + justifyContent?: string // enum('flex-start', 'flex-end', 'center', 'space-between', 'space-around') + left?: number + margin?: number + marginBottom?: number + marginHorizontal?: number + marginLeft?: number + marginRight?: number + marginTop?: number + marginVertical?: number + padding?: number + paddingBottom?: number + paddingHorizontal?: number + paddingLeft?: number + paddingRight?: number + paddingTop?: number + paddingVertical?: number + position?: string // enum('absolute', 'relative') + right?: number + top?: number + width?: number + } + + + export interface StyleSheetProperties { // TODO: } - export interface LayoutRectangle - { + export interface LayoutRectangle { x: number; y: number; width: number; @@ -175,16 +213,14 @@ declare namespace ReactNative { } // @see TextProperties.onLayout - export interface LayoutChangeEvent - { + export interface LayoutChangeEvent { nativeEvent: { layout: LayoutRectangle } } // @see https://facebook.github.io/react-native/docs/text.html#style - export interface TextStyle - { + export interface TextStyle extends FlexStyle{ color?: string; containerBackgroundColor?: string; fontFamily?: string; @@ -198,8 +234,7 @@ declare namespace ReactNative { } // https://facebook.github.io/react-native/docs/text.html#props - export interface TextProperties - { + export interface TextProperties { /** * numberOfLines number * @@ -214,7 +249,7 @@ declare namespace ReactNative { * * {nativeEvent: { layout: {x, y, width, height}}}. */ - onLayout?: (event: LayoutChangeEvent) => void; + onLayout?: ( event: LayoutChangeEvent ) => void; /** * onPress function @@ -229,14 +264,12 @@ declare namespace ReactNative { style?: TextStyle; } - export interface AccessibilityTraits - { + export interface AccessibilityTraits { // TODO } // @see https://facebook.github.io/react-native/docs/view.html#style - export interface ViewStyle - { + export interface ViewStyle extends FlexStyle { backgroundColor?: string; borderBottomColor?: string; borderBottomLeftRadius?: number; @@ -259,8 +292,7 @@ declare namespace ReactNative { /** * @see https://facebook.github.io/react-native/docs/view.html#props */ - export interface ViewProperties - { + export interface ViewProperties { /** * accessibilityLabel string * @@ -301,7 +333,7 @@ declare namespace ReactNative { * * {nativeEvent: { layout: {x, y, width, height}}}. */ - onLayout?: (event: LayoutChangeEvent) => void; + onLayout?: ( event: LayoutChangeEvent ) => void; /** * onMagicTap function @@ -397,8 +429,7 @@ declare namespace ReactNative { /** * @see https://facebook.github.io/react-native/docs/activityindicatorios.html#props */ - export interface AlertIOSProperties - { + export interface AlertIOSProperties { /** * animating bool * @@ -429,7 +460,7 @@ declare namespace ReactNative { * * {nativeEvent: { layout: {x, y, width, height}}}. */ - onLayout?: (event: LayoutChangeEvent) => void; + onLayout?: ( event: LayoutChangeEvent ) => void; /** * size enum('small', 'large') @@ -442,40 +473,35 @@ declare namespace ReactNative { /** * @see */ - export interface SegmentedControlIOSProperties - { + export interface SegmentedControlIOSProperties { /// TODO } /** * @see */ - export interface SwitchIOSProperties - { + export interface SwitchIOSProperties { /// TODO } /** * @see */ - export interface NavigatorProperties - { + export interface NavigatorProperties { /// TODO } /** * @see */ - export interface ActivityIndicatorIOSProperties - { + export interface ActivityIndicatorIOSProperties { /// TODO } /** * @see https://facebook.github.io/react-native/docs/sliderios.html */ - export interface SliderIOSProperties - { + export interface SliderIOSProperties { /** maximumTrackTintColor string The color used for the track to the right of the button. Overrides the default blue gradient image. @@ -511,7 +537,7 @@ declare namespace ReactNative { onValueChange function Callback continuously called while the user is dragging the slider. */ - onValueChange?: (value: number) => void; + onValueChange?: ( value: number ) => void; /** value number @@ -525,32 +551,124 @@ declare namespace ReactNative { /** * @see */ - export interface CameraRollProperties - { + export interface CameraRollProperties { /// TODO } + /** + * Image style + * @see https://facebook.github.io/react-native/docs/image.html#style + */ + export interface ImageStyle extends FlexStyle{ + color?: string; + containerBackgroundColor?: string; + fontFamily?: string; + fontSize?: number; + fontStyle?: string; // 'normal' | 'italic'; + fontWeight?: string; // enum("normal", 'bold', '100', '200', '300', '400', '500', '600', '700', '800', '900') + letterSpacing?: number; + lineHeight?: number; + textAlign?: string; // enum("auto", 'left', 'right', 'center') + writingDirection?: string; //enum("auto", 'ltr', 'rtl') + } + + /** + * @see https://facebook.github.io/react-native/docs/image.html + */ + export interface ImageProperties { + /** + * onLayout function + * + * Invoked on mount and layout changes with + * + * {nativeEvent: { layout: {x, y, width, height}}}. + */ + onLayout?: ( event: LayoutChangeEvent ) => void; + + + /** + * Determines how to resize the image when the frame doesn't match the raw image dimensions. + */ + resizeMode?: string; // enum('cover', 'contain', 'stretch') + + /** + * uri is a string representing the resource identifier for the image, + * which could be an http address, a local file path, + * or the name of a static image resource (which should be wrapped in the require('image!name') function). + */ + source: {uri: string} | string; + + /** + * + * Style + */ + style?: ImageStyle; + + /** + * A unique identifier for this element to be used in UI Automation testing scripts. + */ + testID?: string; + + /** + * The text that's read by the screen reader when the user interacts with the image. + */ + iosaccessibilityLabel?: string; + + /** + * When true, indicates the image is an accessibility element. + */ + iosaccessible?: boolean; + + /** + * When the image is resized, the corners of the size specified by capInsets will stay a fixed size, + * but the center content and borders of the image will be stretched. + * This is useful for creating resizable rounded buttons, shadows, and other resizable assets. + * More info on Apple documentation + */ + ioscapInsets?: {top: number, left: number, bottom: number, right: number} + + /** + * A static image to display while downloading the final image off the network. + */ + iosdefaultSource?: {uri: string} + + /** + * Invoked on load error with {nativeEvent: {error}} + */ + iosonError?: ( error: {nativeEvent: any} ) => void + + /** + * Invoked when load completes successfully + */ + iosonLoad?: () => void + + /** + * Invoked when load either succeeds or fails + */ + iosonLoadEnd?: () => void + + /** + * Invoked on load start + */ + iosonLoadStart?: () => void + + /** + * Invoked on download progress with {nativeEvent: {loaded, total}} + */ + iosonProgress?: ()=> void + } + /** * @see */ - export interface ImageProperties - { - /// TODO - } - - /** - * @see - */ - export interface ListViewProperties - { + export interface ListViewProperties { /// TODO } /** * @see https://facebook.github.io/react-native/docs/touchablehighlight.html#props */ - export interface TouchableHighlightProperties - { + export interface TouchableHighlightProperties { /** * activeOpacity number * @@ -591,8 +709,7 @@ declare namespace ReactNative { /** * @see https://facebook.github.io/react-native/docs/touchablewithoutfeedback.html */ - export interface TouchableWithoutFeedbackProperties - { + export interface TouchableWithoutFeedbackProperties { /* accessible bool @@ -645,8 +762,7 @@ declare namespace ReactNative { /** * @see https://facebook.github.io/react-native/docs/touchableopacity.html#props */ - export interface TouchableOpacityProperties - { + export interface TouchableOpacityProperties { /** * activeOpacity number * @@ -656,19 +772,16 @@ declare namespace ReactNative { } - export interface LeftToRightGesture - { + export interface LeftToRightGesture { } - export interface AnimationInterpolator - { + export interface AnimationInterpolator { } // see /NavigatorSceneConfigs.js - export interface SceneConfig - { + export interface SceneConfig { // A list of all gestures that are enabled on this scene gestures: { pop: LeftToRightGesture, @@ -690,8 +803,7 @@ declare namespace ReactNative { } // see /NavigatorSceneConfigs.js - export interface SceneConfigs - { + export interface SceneConfigs { FloatFromBottom: SceneConfig; FloatFromRight: SceneConfig; PushFromRight: SceneConfig; @@ -707,22 +819,19 @@ declare namespace ReactNative { /** * @see */ - export interface NavigatorBarProperties - { + export interface NavigatorBarProperties { } - export interface NavigationBar extends React.ComponentClass - { + export interface NavigationBar extends React.ComponentClass { } - export interface NavigatorStatic extends React.ComponentClass - { + export interface NavigatorStatic extends React.ComponentClass { SceneConfigs: SceneConfigs; - getContext(self:any): NavigatorStatic; + getContext( self: any ): NavigatorStatic; - push(route: Route): void; + push( route: Route ): void; pop(): void; popToTop(): void; popToRoute( route: Route ): void; @@ -732,78 +841,65 @@ declare namespace ReactNative { NavigationBar: NavigationBar; } - export interface StyleSheetStatic extends React.ComponentClass - { - create(styles:T): T; + export interface StyleSheetStatic extends React.ComponentClass { + create( styles: T ): T; } - export interface DataSourceAssetCallback - { - rowHasChanged: (r1: any[], r2: any[]) => boolean; + export interface DataSourceAssetCallback { + rowHasChanged: ( r1: any[], r2: any[] ) => boolean; } - export interface ListViewDataSource - { - new(onAsset: DataSourceAssetCallback): ListViewDataSource; - cloneWithRows(rowList:T[][]): void; + export interface ListViewDataSource { + new( onAsset: DataSourceAssetCallback ): ListViewDataSource; + cloneWithRows( rowList: T[][] ): void; } - export interface ListViewStatic extends React.ComponentClass - { + export interface ListViewStatic extends React.ComponentClass { DataSource: ListViewDataSource; } - export interface ImageStatic extends React.ComponentClass - { + export interface ImageStatic extends React.ComponentClass { uri: string; } /** * @see */ - export interface TabBarItemProperties - { + export interface TabBarItemProperties { } - export interface TabBarItem extends React.ComponentClass - { + export interface TabBarItem extends React.ComponentClass { } /** * @see */ - export interface TabBarIOSProperties - { + export interface TabBarIOSProperties { } - export interface TabBarIOSStatic extends React.ComponentClass - { + export interface TabBarIOSStatic extends React.ComponentClass { Item: TabBarItem; } - export interface CameraRollFetchParams - { + export interface CameraRollFetchParams { first: number; groupTypes: string; after?: string; } - export interface CameraRollNodeInfo - { + export interface CameraRollNodeInfo { image: Image; group_name: string; timestamp: number; location: any; } - export interface CameraRollEdgeInfo - { + export interface CameraRollEdgeInfo { node: CameraRollNodeInfo; } - export interface CameraRollAssetInfo - { + export interface CameraRollAssetInfo { edges: CameraRollEdgeInfo[]; page_info: { has_next_page: boolean; @@ -811,25 +907,21 @@ declare namespace ReactNative { }; } - export interface CameraRollStatic extends React.ComponentClass - { - getPhotos(fetch: CameraRollFetchParams, - onAsset: (assetInfo: CameraRollAssetInfo) => void, - logError: ()=> void): void; + export interface CameraRollStatic extends React.ComponentClass { + getPhotos( fetch: CameraRollFetchParams, + onAsset: ( assetInfo: CameraRollAssetInfo ) => void, + logError: ()=> void ): void; } - export interface PanHandlers - { + export interface PanHandlers { } - export interface PanResponderEvent - { + export interface PanResponderEvent { } - export interface PanResponderGestureState - { + export interface PanResponderGestureState { stateID: number; moveX: number; moveY: number; @@ -875,104 +967,90 @@ declare namespace ReactNative { * accordingly. (numberActiveTouches) may not be totally accurate unless you * are the responder. */ - export interface PanResponderCallbacks - { - onMoveShouldSetPanResponder?: (e: PanResponderEvent, gestureState: PanResponderGestureState) => boolean; - onStartShouldSetPanResponder?: (e: PanResponderEvent, gestureState: PanResponderGestureState) => void; - onPanResponderGrant?: (e: PanResponderEvent, gestureState: PanResponderGestureState) => void; - onPanResponderMove?: (e: PanResponderEvent, gestureState: PanResponderGestureState) => void; - onPanResponderRelease?: (e: PanResponderEvent, gestureState: PanResponderGestureState) => void; - onPanResponderTerminate?: (e: PanResponderEvent, gestureState: PanResponderGestureState) => void; + export interface PanResponderCallbacks { + onMoveShouldSetPanResponder?: ( e: PanResponderEvent, gestureState: PanResponderGestureState ) => boolean; + onStartShouldSetPanResponder?: ( e: PanResponderEvent, gestureState: PanResponderGestureState ) => void; + onPanResponderGrant?: ( e: PanResponderEvent, gestureState: PanResponderGestureState ) => void; + onPanResponderMove?: ( e: PanResponderEvent, gestureState: PanResponderGestureState ) => void; + onPanResponderRelease?: ( e: PanResponderEvent, gestureState: PanResponderGestureState ) => void; + onPanResponderTerminate?: ( e: PanResponderEvent, gestureState: PanResponderGestureState ) => void; - onMoveShouldSetPanResponderCapture?: (e: PanResponderEvent, gestureState: PanResponderGestureState) => boolean; - onStartShouldSetPanResponderCapture?: (e: PanResponderEvent, gestureState: PanResponderGestureState) => boolean; - onPanResponderReject?: (e: PanResponderEvent, gestureState: PanResponderGestureState) => void; - onPanResponderStart?: (e: PanResponderEvent, gestureState: PanResponderGestureState) => void; - onPanResponderEnd?: (e: PanResponderEvent, gestureState: PanResponderGestureState) => void; - onPanResponderTerminationRequest?: (e: PanResponderEvent, gestureState: PanResponderGestureState) => void; + onMoveShouldSetPanResponderCapture?: ( e: PanResponderEvent, gestureState: PanResponderGestureState ) => boolean; + onStartShouldSetPanResponderCapture?: ( e: PanResponderEvent, gestureState: PanResponderGestureState ) => boolean; + onPanResponderReject?: ( e: PanResponderEvent, gestureState: PanResponderGestureState ) => void; + onPanResponderStart?: ( e: PanResponderEvent, gestureState: PanResponderGestureState ) => void; + onPanResponderEnd?: ( e: PanResponderEvent, gestureState: PanResponderGestureState ) => void; + onPanResponderTerminationRequest?: ( e: PanResponderEvent, gestureState: PanResponderGestureState ) => void; } - export interface PanResponderInstance - { + export interface PanResponderInstance { panHandlers: PanHandlers; } - export interface PanResponderStatic - { - create(callbacks: PanResponderCallbacks): PanResponderInstance; + export interface PanResponderStatic { + create( callbacks: PanResponderCallbacks ): PanResponderInstance; } - export interface PixelRatioStatic - { + export interface PixelRatioStatic { get(): number; } - export interface DeviceEventSubscriptionStatic - { + export interface DeviceEventSubscriptionStatic { remove(): void; } - export interface DeviceEventEmitterStatic - { - addListener(type:string, onReceived: (data:T) => void): DeviceEventSubscription; + export interface DeviceEventEmitterStatic { + addListener( type: string, onReceived: ( data: T ) => void ): DeviceEventSubscription; } // Used by Dimensions below - export interface ScaledSize - { + export interface ScaledSize { width: number; height: number; scale: number; } // @see https://facebook.github.io/react-native/docs/asyncstorage.html#content - export interface AsyncStorageStatic - { - getItem(key: string, callback?: (error?: Error, result?: string) => void): Promise; - setItem(key: string, value: string, callback?: (error?: Error) => void): Promise; - removeItem(key: string, callback?: (error?: Error) => void): Promise; - mergeItem(key: string, value: string, callback?: (error?: Error) => void): Promise; - clear(callback?: (error?: Error) => void): Promise; - getAllKeys(callback?: (error?: Error, keys?: string[]) => void): Promise; - multiGet(keys: string[], callback?: (errors?: Error[], result?: string[][]) => void): Promise; - multiSet(keyValuePairs: string[][], callback?: (errors?: Error[]) => void): Promise; - multiRemove(keys: string[], callback?: (errors?: Error[]) => void): Promise; - multiMerge(keyValuePairs: string[][], callback?: (errors?: Error[]) => void): Promise; + export interface AsyncStorageStatic { + getItem( key: string, callback?: ( error?: Error, result?: string ) => void ): Promise; + setItem( key: string, value: string, callback?: ( error?: Error ) => void ): Promise; + removeItem( key: string, callback?: ( error?: Error ) => void ): Promise; + mergeItem( key: string, value: string, callback?: ( error?: Error ) => void ): Promise; + clear( callback?: ( error?: Error ) => void ): Promise; + getAllKeys( callback?: ( error?: Error, keys?: string[] ) => void ): Promise; + multiGet( keys: string[], callback?: ( errors?: Error[], result?: string[][] ) => void ): Promise; + multiSet( keyValuePairs: string[][], callback?: ( errors?: Error[] ) => void ): Promise; + multiRemove( keys: string[], callback?: ( errors?: Error[] ) => void ): Promise; + multiMerge( keyValuePairs: string[][], callback?: ( errors?: Error[] ) => void ): Promise; } - export interface InteractionManagerStatic - { + export interface InteractionManagerStatic { runAfterInteractions( fn: () => void ): void; } - export interface ScrollViewProperties - { + export interface ScrollViewProperties { } - export interface NativeScrollRectangle - { + export interface NativeScrollRectangle { left: number; top: number; bottom: number; right: number; } - export interface NativeScrollPoint - { + export interface NativeScrollPoint { x: number; y: number; } - export interface NativeScrollSize - { + export interface NativeScrollSize { height: number; width: number; } - export interface NativeScrollEvent - { + export interface NativeScrollEvent { contentInset: NativeScrollRectangle; contentOffset: NativeScrollPoint; contentSize: NativeScrollSize; @@ -980,11 +1058,10 @@ declare namespace ReactNative { zoomScale: number; } - export interface AppStateIOSStatic - { + export interface AppStateIOSStatic { currentState: string; - addEventListener( type: string, listener: (state: string) => void ): void; - removeEventListener( type: string, listener: (state: string) => void ): void; + addEventListener( type: string, listener: ( state: string ) => void ): void; + removeEventListener( type: string, listener: ( state: string ) => void ): void; } // exported singletons: @@ -1025,11 +1102,11 @@ declare namespace ReactNative { //react re-exported export type ReactType = React.ReactType; - export interface ReactElement

extends React.ReactElement

{} + export interface ReactElement

extends React.ReactElement

{} - export interface ClassicElement

extends React.ClassicElement

{} + export interface ClassicElement

extends React.ClassicElement

{} - export interface DOMElement

extends React.DOMElement

{} + export interface DOMElement

extends React.DOMElement

{} export type HTMLElement =React.HTMLElement; export type SVGElement = React.SVGElement; @@ -1038,11 +1115,11 @@ declare namespace ReactNative { // Factories // ---------------------------------------------------------------------- - export interface Factory

extends React.Factory

{} + export interface Factory

extends React.Factory

{} - export interface ClassicFactory

extends React.ClassicFactory

{} + export interface ClassicFactory

extends React.ClassicFactory

{} - export interface DOMFactory

extends React.DOMFactory

{} + export interface DOMFactory

extends React.DOMFactory

{} export type HTMLFactory = React.HTMLFactory; export type SVGFactory = React.SVGFactory; @@ -1064,39 +1141,33 @@ declare namespace ReactNative { // Top Level API // ---------------------------------------------------------------------- - export function createClass(spec: React.ComponentSpec): React.ClassicComponentClass

; + export function createClass( spec: React.ComponentSpec ): React.ClassicComponentClass

; - export function createFactory

(type: string): React.DOMFactory

; - export function createFactory

(type: React.ClassicComponentClass

| string): React.ClassicFactory

; - export function createFactory

(type: React.ComponentClass

): React.Factory

; + export function createFactory

( type: string ): React.DOMFactory

; + export function createFactory

( type: React.ClassicComponentClass

| string ): React.ClassicFactory

; + export function createFactory

( type: React.ComponentClass

): React.Factory

; - export function createElement

( - type: string, - props?: P, - ...children: React.ReactNode[]): React.DOMElement

; - export function createElement

( - type: React.ClassicComponentClass

| string, - props?: P, - ...children: React.ReactNode[]): React.ClassicElement

; - export function createElement

( - type: React.ComponentClass

, - props?: P, - ...children: React.ReactNode[]): React.ReactElement

; + export function createElement

( type: string, + props?: P, + ...children: React.ReactNode[] ): React.DOMElement

; + export function createElement

( type: React.ClassicComponentClass

| string, + props?: P, + ...children: React.ReactNode[] ): React.ClassicElement

; + export function createElement

( type: React.ComponentClass

, + props?: P, + ...children: React.ReactNode[] ): React.ReactElement

; - export function cloneElement

( - element: React.DOMElement

, - props?: P, - ...children: React.ReactNode[]): React.DOMElement

; - export function cloneElement

( - element: React.ClassicElement

, - props?: P, - ...children: React.ReactNode[]): React.ClassicElement

; - export function cloneElement

( - element: React.ReactElement

, - props?: P, - ...children: React.ReactNode[]): React.ReactElement

; + export function cloneElement

( element: React.DOMElement

, + props?: P, + ...children: React.ReactNode[] ): React.DOMElement

; + export function cloneElement

( element: React.ClassicElement

, + props?: P, + ...children: React.ReactNode[] ): React.ClassicElement

; + export function cloneElement

( element: React.ReactElement

, + props?: P, + ...children: React.ReactNode[] ): React.ReactElement

; - export function isValidElement(object: {}): boolean; + export function isValidElement( object: {} ): boolean; export var DOM: React.ReactDOM; export var PropTypes: React.ReactPropTypes; @@ -1107,7 +1178,7 @@ declare namespace ReactNative { // ---------------------------------------------------------------------- // Base component for plain JS classes - export class Component extends React.Component{} + export class Component extends React.Component {} export interface ClassicComponent extends React.ClassicComponent {} @@ -1118,40 +1189,40 @@ declare namespace ReactNative { export type HTMLComponent = React.HTMLComponent; export type SVGComponent = React.SVGComponent - export interface ChildContextProvider extends React.ChildContextProvider{} + export interface ChildContextProvider extends React.ChildContextProvider {} // // Class Interfaces // ---------------------------------------------------------------------- - export interface ComponentClass

extends React.ComponentClass

{} + export interface ComponentClass

extends React.ComponentClass

{} - export interface ClassicComponentClass

extends React.ClassicComponentClass

{} + export interface ClassicComponentClass

extends React.ClassicComponentClass

{} // // Component Specs and Lifecycle // ---------------------------------------------------------------------- - export interface ComponentLifecycle extends React.ComponentLifecycle{} + export interface ComponentLifecycle extends React.ComponentLifecycle {} - export interface Mixin extends React.Mixin{} + export interface Mixin extends React.Mixin {} - export interface ComponentSpec extends React.ComponentSpec{} + export interface ComponentSpec extends React.ComponentSpec {} // // Event System // ---------------------------------------------------------------------- - export interface SyntheticEvent extends React.SyntheticEvent{} + export interface SyntheticEvent extends React.SyntheticEvent {} - export interface DragEvent extends React.DragEvent{} + export interface DragEvent extends React.DragEvent {} - export interface ClipboardEvent extends React.ClipboardEvent{} + export interface ClipboardEvent extends React.ClipboardEvent {} - export interface KeyboardEvent extends React.KeyboardEvent{} + export interface KeyboardEvent extends React.KeyboardEvent {} - export interface FocusEvent extends React.FocusEvent{} + export interface FocusEvent extends React.FocusEvent {} export interface FormEvent extends React.FormEvent {} @@ -1167,7 +1238,7 @@ declare namespace ReactNative { // Event Handler Types // ---------------------------------------------------------------------- - export interface EventHandler extends React.EventHandler{} + export interface EventHandler extends React.EventHandler {} export interface DragEventHandler extends React.DragEventHandler {} export interface ClipboardEventHandler extends React.ClipboardEventHandler {} @@ -1177,67 +1248,67 @@ declare namespace ReactNative { export interface MouseEventHandler extends React.MouseEventHandler {} export interface TouchEventHandler extends React.TouchEventHandler {} export interface UIEventHandler extends React.UIEventHandler {} - export interface WheelEventHandler extends React.WheelEventHandler{} + export interface WheelEventHandler extends React.WheelEventHandler {} // // Props / DOM Attributes // ---------------------------------------------------------------------- - export interface Props extends React.Props{} + export interface Props extends React.Props {} - export interface DOMAttributesBase extends React.DOMAttributesBase{} + export interface DOMAttributesBase extends React.DOMAttributesBase {} - export interface DOMAttributes extends React.DOMAttributes{} + export interface DOMAttributes extends React.DOMAttributes {} // This interface is not complete. Only properties accepting // unitless numbers are listed here (see CSSProperty.js in React) - export interface CSSProperties extends React.CSSProperties{} + export interface CSSProperties extends React.CSSProperties {} - export interface HTMLAttributesBase extends React.HTMLAttributesBase{} + export interface HTMLAttributesBase extends React.HTMLAttributesBase {} - export interface HTMLAttributes extends React.HTMLAttributes{} + export interface HTMLAttributes extends React.HTMLAttributes {} - export interface SVGElementAttributes extends React.SVGElementAttributes{} + export interface SVGElementAttributes extends React.SVGElementAttributes {} - export interface SVGAttributes extends React.SVGAttributes{} + export interface SVGAttributes extends React.SVGAttributes {} // // React.DOM // ---------------------------------------------------------------------- - export interface ReactDOM extends React.ReactDOM{} + export interface ReactDOM extends React.ReactDOM {} // // React.PropTypes // ---------------------------------------------------------------------- - export interface Validator extends React.Validator{} + export interface Validator extends React.Validator {} export interface Requireable extends React.Requireable {} - export interface ValidationMap extends React.ValidationMap{} + export interface ValidationMap extends React.ValidationMap {} - export interface ReactPropTypes extends React.ReactPropTypes{} + export interface ReactPropTypes extends React.ReactPropTypes {} // // React.Children // ---------------------------------------------------------------------- - export interface ReactChildren extends React.ReactChildren{} + export interface ReactChildren extends React.ReactChildren {} // // Browser Interfaces // https://github.com/nikeee/2048-typescript/blob/master/2048/js/touch.d.ts // ---------------------------------------------------------------------- - export interface AbstractView extends React.AbstractView{} + export interface AbstractView extends React.AbstractView {} - export interface Touch extends React.Touch{} + export interface Touch extends React.Touch {} - export interface TouchList extends React.TouchList{} + export interface TouchList extends React.TouchList {} - export function __spread(target:any, ...sources:any[]): any; + export function __spread( target: any, ...sources: any[] ): any; } declare module "react-native" { @@ -1246,14 +1317,11 @@ declare module "react-native" { } - -declare module "Dimensions" -{ +declare module "Dimensions" { import React from 'react-native'; - interface Dimensions - { - get(what:string): React.ScaledSize; + interface Dimensions { + get( what: string ): React.ScaledSize; } var ExportDimensions: Dimensions; From e4a4c668061c43ed9bb07b79c4f7fe7d0b56e18c Mon Sep 17 00:00:00 2001 From: bgrieder Date: Sun, 8 Nov 2015 07:46:36 +0100 Subject: [PATCH 06/15] additional definitions for Navigator and NavigatorIOS --- react-native/react-native.d.ts | 131 ++++++++++++++++++++++++++++++--- 1 file changed, 121 insertions(+), 10 deletions(-) diff --git a/react-native/react-native.d.ts b/react-native/react-native.d.ts index 592cecdaf..1432026c2 100644 --- a/react-native/react-native.d.ts +++ b/react-native/react-native.d.ts @@ -220,7 +220,7 @@ declare namespace ReactNative { } // @see https://facebook.github.io/react-native/docs/text.html#style - export interface TextStyle extends FlexStyle{ + export interface TextStyle extends FlexStyle { color?: string; containerBackgroundColor?: string; fontFamily?: string; @@ -485,12 +485,109 @@ declare namespace ReactNative { } /** - * @see + * @see https://facebook.github.io/react-native/docs/navigator.html#content */ export interface NavigatorProperties { - /// TODO + /** + * Optional function that allows configuration about scene animations and gestures. + * Will be invoked with the route and should return a scene configuration object + * @param route + */ + configureScene?: ( route: Route ) => SceneConfig + /** + * Specify a route to start on. + * A route is an object that the navigator will use to identify each scene to render. + * initialRoute must be a route in the initialRouteStack if both props are provided. + * The initialRoute will default to the last item in the initialRouteStack. + */ + initialRoute?: Route + /** + * Provide a set of routes to initially mount. + * Required if no initialRoute is provided. + * Otherwise, it will default to an array containing only the initialRoute + */ + initialRouteStack?: Route[] + + /** + * Optionally provide a navigation bar that persists across scene transitions + */ + navigationBar?: NavigationBar + + /** + * Optionally provide the navigator object from a parent Navigator + */ + navigator?: Navigator + + /** + * @deprecated Use navigationContext.addListener('willfocus', callback) instead. + */ + onDidFocus?: Function + + /** + * @deprecated Use navigationContext.addListener('willfocus', callback) instead. + */ + onWillFocus?: Function + + /** + * Required function which renders the scene for a given route. + * Will be invoked with the route and the navigator object + * @param route + * @param navigator + */ + renderScene: (route: Route, navigator: Navigator) => React.ComponentClass + + /** + * Styles to apply to the container of each scene + */ + sceneStyle: ViewStyle } + export interface NavigatorIOSProperties { + + /** + * NavigatorIOS uses "route" objects to identify child views, their props, and navigation bar configuration. + * "push" and all the other navigation operations expect routes to be like this + */ + initialRoute?: Route + + /** + * The default wrapper style for components in the navigator. + * A common use case is to set the backgroundColor for every page + */ + itemWrapperStyle?: ViewStyle + + /** + * A Boolean value that indicates whether the navigation bar is hidden + */ + navigationBarHidden?: boolean + + /** + * A Boolean value that indicates whether to hide the 1px hairline shadow + */ + shadowHidden?: boolean + + /** + * The color used for buttons in the navigation bar + */ + tintColor?: string + + /** + * The text color of the navigation bar title + */ + titleTextColor?: string + + /** + * A Boolean value that indicates whether the navigation bar is translucent + */ + translucent?: boolean + + /** + * NOT IN THE DOC BUT IN THE EXAMPLES + */ + style?: ViewStyle + } + + /** * @see */ @@ -559,7 +656,7 @@ declare namespace ReactNative { * Image style * @see https://facebook.github.io/react-native/docs/image.html#style */ - export interface ImageStyle extends FlexStyle{ + export interface ImageStyle extends FlexStyle { color?: string; containerBackgroundColor?: string; fontFamily?: string; @@ -812,8 +909,10 @@ declare namespace ReactNative { } export interface Route { - id: string; + component?: ComponentClass + id?: string; title?: string; + passProps?: Object } /** @@ -827,18 +926,26 @@ declare namespace ReactNative { } + /** + * @see https://facebook.github.io/react-native/docs/navigator.html + */ export interface NavigatorStatic extends React.ComponentClass { SceneConfigs: SceneConfigs; + NavigationBar: NavigationBar; getContext( self: any ): NavigatorStatic; + getCurrentRoutes(): Route[]; + jumpBack(): void; + jumpForward(): void; + jumpTo( route: Route ): void; push( route: Route ): void; pop(): void; - popToTop(): void; - popToRoute( route: Route ): void; + replace( route: Route ): void; + replaceAtIndex( route: Route, index: number ): void; + replacePrevious( route: Route ): void; immediatelyResetRouteStack( routes: Route[] ): void; - getCurrentRoutes(): Route[]; - - NavigationBar: NavigationBar; + popToRoute( route: Route ): void; + popToTop(): void; } export interface StyleSheetStatic extends React.ComponentClass { @@ -1079,6 +1186,7 @@ declare namespace ReactNative { export var Text: React.ComponentClass; export var View: React.ComponentClass; + export var NavigatorIOS: React.ComponentClass; export var AlertIOS: React.ComponentClass; export var SegmentedControlIOS: React.ComponentClass; export var SwitchIOS: React.ComponentClass; @@ -1307,6 +1415,9 @@ declare namespace ReactNative { export interface TouchList extends React.TouchList {} + // + // Additional ( and controversial) + // export function __spread( target: any, ...sources: any[] ): any; } From a6758d638b885c37d7bd5ef34ef254337f9dce96 Mon Sep 17 00:00:00 2001 From: bgrieder Date: Mon, 9 Nov 2015 11:36:09 +0100 Subject: [PATCH 07/15] Lots of fixes + TextInput + ScrollView + LstView --- react-native/react-native.d.ts | 752 ++++++++++++++++++++++++++++++++- 1 file changed, 731 insertions(+), 21 deletions(-) diff --git a/react-native/react-native.d.ts b/react-native/react-native.d.ts index 1432026c2..7f5832749 100644 --- a/react-native/react-native.d.ts +++ b/react-native/react-native.d.ts @@ -163,6 +163,7 @@ declare namespace ReactNative { /** * Flex Prop Types * @see https://facebook.github.io/react-native/docs/flexbox.html#proptypes + * @see LayoutPropTypes.js */ export interface FlexStyle { @@ -201,6 +202,19 @@ declare namespace ReactNative { } + export interface TransformsStyle { + + transform?: [{perspective: number}, {rotate: string}, {rotateX: string}, {rotateY: string}, {rotateZ: string}, {scale: number}, {scaleX: number}, {scaleY: number}, {translateX: number}, {translateY: number}, {skewX: string}, {skewY: string}] + transformMatrix?: Array + rotation?: number + scaleX?: number + scaleY?: number + translateX?: number + translateY?: number + + } + + export interface StyleSheetProperties { // TODO: } @@ -264,12 +278,230 @@ declare namespace ReactNative { style?: TextStyle; } + + /** + * IOS Specific properties for TextInput + * @see https://facebook.github.io/react-native/docs/textinput.html#props + */ + export interface TextInputIOSProperties { + + /** + * If true, the text field will blur when submitted. + * The default value is true. + */ + blurOnSubmit?: boolean + + /** + * enum('never', 'while-editing', 'unless-editing', 'always') + * When the clear button should appear on the right side of the text view + */ + clearButtonMode?: string + + /** + * If true, clears the text field automatically when editing begins + */ + clearTextOnFocus?: boolean + + /** + * If true, the keyboard disables the return key when there is no text and automatically enables it when there is text. + * The default value is false. + */ + enablesReturnKeyAutomatically?: boolean + + /** + * Callback that is called when a key is pressed. + * Pressed key value is passed as an argument to the callback handler. + * Fires before onChange callbacks. + */ + onKeyPress?: () => void + + /** + * enum('default', 'go', 'google', 'join', 'next', 'route', 'search', 'send', 'yahoo', 'done', 'emergency-call') + * Determines how the return key should look. + */ + returnKeyType?: string + + /** + * If true, all text will automatically be selected on focus + */ + selectTextOnFocus?: boolean + + /** + * //FIXME: require typing + * See DocumentSelectionState.js, some state that is responsible for maintaining selection information for a document + */ + selectionState?: any + + + } + + /** + * Android Specific properties for TextInput + * @see https://facebook.github.io/react-native/docs/textinput.html#props + */ + export interface TextInputAndroidProperties { + + /** + * Sets the number of lines for a TextInput. + * Use it with multiline set to true to be able to fill the lines. + */ + numberOfLines?: number + + /** + * enum('start', 'center', 'end') + * Set the position of the cursor from where editing will begin. + */ + textAlign?: string + + /** + * enum('top', 'center', 'bottom') + * Aligns text vertically within the TextInput. + */ + textAlignVertical?: string + + /** + * The color of the textInput underline. + */ + underlineColorAndroid?: string + } + + + /** + * @see https://facebook.github.io/react-native/docs/textinput.html#props + */ + export interface TextInputProperties extends TextInputIOSProperties, TextInputAndroidProperties { + + /** + * Can tell TextInput to automatically capitalize certain characters. + * characters: all characters, + * words: first letter of each word + * sentences: first letter of each sentence (default) + * none: don't auto capitalize anything + * + * https://facebook.github.io/react-native/docs/textinput.html#autocapitalize + */ + autoCapitalize?: string + + /** + * If false, disables auto-correct. + * The default value is true. + */ + autoCorrect?: boolean + + /** + * If true, focuses the input on componentDidMount. + * The default value is false. + */ + autoFocus?: boolean + + /** + * Provides an initial value that will change when the user starts typing. + * Useful for simple use-cases where you don't want to deal with listening to events + * and updating the value prop to keep the controlled state in sync. + */ + defaultValue?: string + + /** + * If false, text is not editable. The default value is true. + */ + editable?: boolean + + /** + * enum("default", 'numeric', 'email-address', "ascii-capable", 'numbers-and-punctuation', 'url', 'number-pad', 'phone-pad', 'name-phone-pad', 'decimal-pad', 'twitter', 'web-search') + * Determines which keyboard to open, e.g.numeric. + * The following values work across platforms: - default - numeric - email-address + */ + keyboardType?: string + + /** + * Limits the maximum number of characters that can be entered. + * Use this instead of implementing the logic in JS to avoid flicker. + */ + maxLength?: number + + /** + * If true, the text input can be multiple lines. The default value is false. + */ + multiline?: boolean + + /** + * Callback that is called when the text input is blurred + */ + onBlur?: () => void + + /** + * Callback that is called when the text input's text changes. + */ + onChange?: () => void + + /** + * Callback that is called when the text input's text changes. + * Changed text is passed as an argument to the callback handler. + */ + onChangeText?: () => void + + /** + * Callback that is called when text input ends. + */ + onEndEditing?: () => void + + /** + * Callback that is called when the text input is focused + */ + onFocus?: () => void + + /** + * Invoked on mount and layout changes with {x, y, width, height}. + */ + onLayout?: () => void + + /** + * Callback that is called when the text input's submit button is pressed. + */ + onSubmitEditing?: () => void + + /** + * The string that will be rendered before text input has been entered + */ + placeholder?: string + + /** + * The text color of the placeholder string + */ + placeholderTextColor?: string + + /** + * If true, the text input obscures the text entered so that sensitive text like passwords stay secure. + * The default value is false. + */ + secureTextEntry?: boolean + + /** + * Styles + */ + style?: TextStyle + + /** + * Used to locate this view in end-to-end tests + */ + testID?: string + + /** + * The value to show for the text input. TextInput is a controlled component, + * which means the native value will be forced to match this value prop if provided. + * For most uses this works great, but in some cases this may cause flickering - one common cause is preventing edits by keeping value the same. + * In addition to simply setting the same value, either set editable={false}, + * or set/update maxLength to prevent unwanted edits without flicker. + */ + value?: string + } + export interface AccessibilityTraits { // TODO } // @see https://facebook.github.io/react-native/docs/view.html#style - export interface ViewStyle extends FlexStyle { + export interface ViewStyle extends FlexStyle, TransformsStyle { backgroundColor?: string; borderBottomColor?: string; borderBottomLeftRadius?: number; @@ -292,7 +524,7 @@ declare namespace ReactNative { /** * @see https://facebook.github.io/react-native/docs/view.html#props */ - export interface ViewProperties { + export interface ViewProperties extends React.Props { /** * accessibilityLabel string * @@ -426,6 +658,10 @@ declare namespace ReactNative { testID?: string; } + interface ViewStatic extends React.ComponentClass { + + } + /** * @see https://facebook.github.io/react-native/docs/activityindicatorios.html#props */ @@ -487,7 +723,7 @@ declare namespace ReactNative { /** * @see https://facebook.github.io/react-native/docs/navigator.html#content */ - export interface NavigatorProperties { + export interface NavigatorProperties extends React.Props { /** * Optional function that allows configuration about scene animations and gestures. * Will be invoked with the route and should return a scene configuration object @@ -534,7 +770,7 @@ declare namespace ReactNative { * @param route * @param navigator */ - renderScene: (route: Route, navigator: Navigator) => React.ComponentClass + renderScene: ( route: Route, navigator: Navigator ) => React.ComponentClass /** * Styles to apply to the container of each scene @@ -542,7 +778,7 @@ declare namespace ReactNative { sceneStyle: ViewStyle } - export interface NavigatorIOSProperties { + export interface NavigatorIOSProperties extends React.Props { /** * NavigatorIOS uses "route" objects to identify child views, their props, and navigation bar configuration. @@ -587,6 +823,10 @@ declare namespace ReactNative { style?: ViewStyle } + interface NavigatorIOSStatic extends React.ComponentClass { + + } + /** * @see @@ -598,7 +838,7 @@ declare namespace ReactNative { /** * @see https://facebook.github.io/react-native/docs/sliderios.html */ - export interface SliderIOSProperties { + export interface SliderIOSProperties extends React.Props { /** maximumTrackTintColor string The color used for the track to the right of the button. Overrides the default blue gradient image. @@ -645,6 +885,10 @@ declare namespace ReactNative { value?: number; } + interface SliderIOSStatic extends React.ComponentClass { + + } + /** * @see */ @@ -672,7 +916,7 @@ declare namespace ReactNative { /** * @see https://facebook.github.io/react-native/docs/image.html */ - export interface ImageProperties { + export interface ImageProperties extends React.Props { /** * onLayout function * @@ -758,8 +1002,113 @@ declare namespace ReactNative { /** * @see */ - export interface ListViewProperties { - /// TODO + export interface ListViewProperties extends ScrollViewProperties, React.Props{ + + dataSource?: ListViewDataSource + + /** + * How many rows to render on initial component mount. Use this to make + * it so that the first screen worth of data apears at one time instead of + * over the course of multiple frames. + */ + initialListSize?: number + + /** + * (visibleRows, changedRows) => void + * + * Called when the set of visible rows changes. `visibleRows` maps + * { sectionID: { rowID: true }} for all the visible rows, and + * `changedRows` maps { sectionID: { rowID: true | false }} for the rows + * that have changed their visibility, with true indicating visible, and + * false indicating the view has moved out of view. + */ + onChangeVisibleRows?: (visibleRows: Array<{[sectionId: string]: {[rowID: string]: boolean}}>, changedRows: Array<{[sectionId: string]: {[rowID: string]: boolean}}>) => void + + /** + * Called when all rows have been rendered and the list has been scrolled + * to within onEndReachedThreshold of the bottom. The native scroll + * event is provided. + */ + onEndReached?: () => void + + /** + * Threshold in pixels for onEndReached. + */ + onEndReachedThreshold?: number + + /** + * Number of rows to render per event loop. + */ + pageSize?: number + + /** + * An experimental performance optimization for improving scroll perf of + * large lists, used in conjunction with overflow: 'hidden' on the row + * containers. Use at your own risk. + */ + removeClippedSubviews?: boolean + + /** + * () => renderable + * + * The header and footer are always rendered (if these props are provided) + * on every render pass. If they are expensive to re-render, wrap them + * in StaticContainer or other mechanism as appropriate. Footer is always + * at the bottom of the list, and header at the top, on every render pass. + */ + renderFooter?: () => React.ReactElement + + /** + * () => renderable + * + * The header and footer are always rendered (if these props are provided) + * on every render pass. If they are expensive to re-render, wrap them + * in StaticContainer or other mechanism as appropriate. Footer is always + * at the bottom of the list, and header at the top, on every render pass. + */ + renderHeader?: () => React.ReactElement + + /** + * (rowData, sectionID, rowID) => renderable + * Takes a data entry from the data source and its ids and should return + * a renderable component to be rendered as the row. By default the data + * is exactly what was put into the data source, but it's also possible to + * provide custom extractors. + */ + renderRow?: (rowData: any, sectionID: string, rowID: string, highlightRow?: boolean) => React.ReactElement + + + /** + * A function that returns the scrollable component in which the list rows are rendered. + * Defaults to returning a ScrollView with the given props. + */ + renderScrollComponent?: (props: ScrollViewProperties) => React.ReactElement + + /** + * (sectionData, sectionID) => renderable + * + * If provided, a sticky header is rendered for this section. The sticky + * behavior means that it will scroll with the content at the top of the + * section until it reaches the top of the screen, at which point it will + * stick to the top until it is pushed off the screen by the next section + * header. + */ + renderSectionHeader?: (sectionData: any, sectionId: string) => React.ReactElement + + + /** + * (sectionID, rowID, adjacentRowHighlighted) => renderable + * If provided, a renderable component to be rendered as the separator below each row + * but not the last row if there is a section header below. + * Take a sectionID and rowID of the row above and whether its adjacent row is highlighted. + */ + renderSeparator?: (sectionID: string, rowID: string, adjacentRowHighlighted?: boolean) => React.ReactElement + + /** + * How early to start rendering rows before they come on screen, in + * pixels. + */ + scrollRenderAheadDistance?: number } /** @@ -952,13 +1301,85 @@ declare namespace ReactNative { create( styles: T ): T; } + /** + * //FIXME: Could not find docs. Inferred from examples and jscode : ListViewDataSource.js + */ export interface DataSourceAssetCallback { - rowHasChanged: ( r1: any[], r2: any[] ) => boolean; + rowHasChanged?: ( r1: any, r2: any ) => boolean + sectionHeaderHasChanged?: ( h1: any, h2: any ) => boolean + getRowData?: ( dataBlob: any, sectionID: number | string, rowID: number | string ) => T + getSectionHeaderData?: ( dataBlob: any, sectionID: number | string ) => T } + /** + * //FIXME: Could not find docs. Inferred from examples and js code: ListViewDataSource.js + */ export interface ListViewDataSource { new( onAsset: DataSourceAssetCallback ): ListViewDataSource; - cloneWithRows( rowList: T[][] ): void; + /** + * Clones this `ListViewDataSource` with the specified `dataBlob` and + * `rowIdentities`. The `dataBlob` is just an aribitrary blob of data. At + * construction an extractor to get the interesting informatoin was defined + * (or the default was used). + * + * The `rowIdentities` is is a 2D array of identifiers for rows. + * ie. [['a1', 'a2'], ['b1', 'b2', 'b3'], ...]. If not provided, it's + * assumed that the keys of the section data are the row identities. + * + * Note: This function does NOT clone the data in this data source. It simply + * passes the functions defined at construction to a new data source with + * the data specified. If you wish to maintain the existing data you must + * handle merging of old and new data separately and then pass that into + * this function as the `dataBlob`. + */ + cloneWithRows( dataBlob: Array | {[key: string]: any}, rowIdentities?: Array ): ListViewDataSource + + /** + * This performs the same function as the `cloneWithRows` function but here + * you also specify what your `sectionIdentities` are. If you don't care + * about sections you should safely be able to use `cloneWithRows`. + * + * `sectionIdentities` is an array of identifiers for sections. + * ie. ['s1', 's2', ...]. If not provided, it's assumed that the + * keys of dataBlob are the section identities. + * + * Note: this returns a new object! + */ + cloneWithRowsAndSections( dataBlob: Array | {[key: string]: any}, sectionIdentities?: Array, rowIdentities?: Array> ): ListViewDataSource + + getRowCount(): number + + /** + * Gets the data required to render the row. + */ + getRowData( sectionIndex: number, rowIndex: number ): any + + /** + * Gets the rowID at index provided if the dataSource arrays were flattened, + * or null of out of range indexes. + */ + getRowIDForFlatIndex( index: number ): string + + /** + * Gets the sectionID at index provided if the dataSource arrays were flattened, + * or null for out of range indexes. + */ + getSectionIDForFlatIndex( index: number ): string + + /** + * Returns an array containing the number of rows in each section + */ + getSectionLengths(): Array + + /** + * Returns if the section header is dirtied and needs to be rerendered + */ + sectionHeaderShouldUpdate( sectionIndex: number ): boolean + + /** + * Gets the data required to render the section header + */ + getSectionHeaderData( sectionIndex: number ): any } export interface ListViewStatic extends React.ComponentClass { @@ -1135,7 +1556,279 @@ declare namespace ReactNative { runAfterInteractions( fn: () => void ): void; } - export interface ScrollViewProperties { + + export interface ScrollViewStyle extends FlexStyle, TransformsStyle { + + backfaceVisibility?:string //enum('visible', 'hidden') + backgroundColor?: string + borderColor?: string + borderTopColor?: string + borderRightColor?: string + borderBottomColor?: string + borderLeftColor?: string + borderRadius?: number + borderTopLeftRadius?: number + borderTopRightRadius?: number + borderBottomLeftRadius?: number + borderBottomRightRadius?: number + borderStyle?: string //enum('solid', 'dotted', 'dashed') + borderWidth?: number + borderTopWidth?: number + borderRightWidth?: number + borderBottomWidth?: number + borderLeftWidth?: number + opacity?: number + overflow?: string //enum('visible', 'hidden') + shadowColor?: string + shadowOffset?: {width: number; height: number} + shadowOpacity?: number + shadowRadius?: number + } + + export interface EdgeInsetsProperties { + top: number + left: number + bottom: number + right: number + } + + export interface PointProperties { + x: number + y: number + } + + export interface ScrollViewIOSProperties { + + /** + * When true the scroll view bounces horizontally when it reaches the end + * even if the content is smaller than the scroll view itself. The default + * value is true when `horizontal={true}` and false otherwise. + */ + alwaysBounceHorizontal?: boolean + /** + * When true the scroll view bounces vertically when it reaches the end + * even if the content is smaller than the scroll view itself. The default + * value is false when `horizontal={true}` and true otherwise. + */ + alwaysBounceVertical?: boolean + + /** + * Controls whether iOS should automatically adjust the content inset for scroll views that are placed behind a navigation bar or tab bar/ toolbar. + * The default value is true. + */ + automaticallyAdjustContentInsets?: boolean // true + + /** + * When true the scroll view bounces when it reaches the end of the + * content if the content is larger then the scroll view along the axis of + * the scroll direction. When false it disables all bouncing even if + * the `alwaysBounce*` props are true. The default value is true. + */ + bounces?: boolean + /** + * When true gestures can drive zoom past min/max and the zoom will animate + * to the min/max value at gesture end otherwise the zoom will not exceed + * the limits. + */ + bouncesZoom?: boolean + + /** + * When false once tracking starts won't try to drag if the touch moves. + * The default value is true. + */ + canCancelContentTouches?: boolean + + /** + * When true the scroll view automatically centers the content when the + * content is smaller than the scroll view bounds; when the content is + * larger than the scroll view this property has no effect. The default + * value is false. + */ + centerContent?: boolean + + + /** + * The amount by which the scroll view content is inset from the edges of the scroll view. + * Defaults to {0, 0, 0, 0}. + */ + contentInset?: EdgeInsetsProperties // zeros + + /** + * Used to manually set the starting scroll offset. + * The default value is {x: 0, y: 0} + */ + contentOffset?: PointProperties // zeros + + /** + * A floating-point number that determines how quickly the scroll view + * decelerates after the user lifts their finger. Reasonable choices include + * - Normal: 0.998 (the default) + * - Fast: 0.9 + */ + decelerationRate?: number + + /** + * When true the ScrollView will try to lock to only vertical or horizontal + * scrolling while dragging. The default value is false. + */ + directionalLockEnabled?: boolean + + /** + * The maximum allowed zoom scale. The default value is 1.0. + */ + maximumZoomScale?: number + + /** + * The minimum allowed zoom scale. The default value is 1.0. + */ + minimumZoomScale?: number + + /** + * Called when a scrolling animation ends. + */ + onScrollAnimationEnd?: () => void + + /** + * When true the scroll view stops on multiples of the scroll view's size + * when scrolling. This can be used for horizontal pagination. The default + * value is false. + */ + pagingEnabled?: boolean + + /** + * When false, the content does not scroll. The default value is true + */ + scrollEnabled?: boolean // true + + /** + * This controls how often the scroll event will be fired while scrolling (in events per seconds). + * A higher number yields better accuracy for code that is tracking the scroll position, + * but can lead to scroll performance problems due to the volume of information being send over the bridge. + * The default value is zero, which means the scroll event will be sent only once each time the view is scrolled. + */ + scrollEventThrottle?: number // null + + /** + * The amount by which the scroll view indicators are inset from the edges of the scroll view. + * This should normally be set to the same value as the contentInset. + * Defaults to {0, 0, 0, 0}. + */ + scrollIndicatorInsets?: EdgeInsetsProperties //zeroes + + /** + * When true the scroll view scrolls to top when the status bar is tapped. + * The default value is true. + */ + scrollsToTop?: boolean + + /** + * When snapToInterval is set, snapToAlignment will define the relationship of the the snapping to the scroll view. + * - start (the default) will align the snap at the left (horizontal) or top (vertical) + * - center will align the snap in the center + * - end will align the snap at the right (horizontal) or bottom (vertical) + */ + snapToAlignment?: string + + /** + * When set, causes the scroll view to stop at multiples of the value of snapToInterval. + * This can be used for paginating through children that have lengths smaller than the scroll view. + * Used in combination with snapToAlignment. + */ + snapToInterval?: number + + /** + * An array of child indices determining which children get docked to the + * top of the screen when scrolling. For example passing + * `stickyHeaderIndices={[0]}` will cause the first child to be fixed to the + * top of the scroll view. This property is not supported in conjunction + * with `horizontal={true}`. + */ + stickyHeaderIndices?: number[] + + /** + * The current scale of the scroll view content. The default value is 1.0. + */ + zoomScale?: number + } + + export interface ScrollViewProperties extends ScrollViewIOSProperties { + + /** + * These styles will be applied to the scroll view content container which + * wraps all of the child views. Example: + * + * return ( + * + * + * ); + * ... + * var styles = StyleSheet.create({ + * contentContainer: { + * paddingVertical: 20 + * } + * }); + */ + contentContainerStyle?: ViewStyle + + /** + * When true the scroll view's children are arranged horizontally in a row + * instead of vertically in a column. The default value is false. + */ + horizontal?: boolean + + /** + * Determines whether the keyboard gets dismissed in response to a drag. + * - 'none' (the default) drags do not dismiss the keyboard. + * - 'onDrag' the keyboard is dismissed when a drag begins. + * - 'interactive' the keyboard is dismissed interactively with the drag + * and moves in synchrony with the touch; dragging upwards cancels the + * dismissal. + */ + keyboardDismissMode?: string + + /** + * When false tapping outside of the focused text input when the keyboard + * is up dismisses the keyboard. When true the scroll view will not catch + * taps and the keyboard will not dismiss automatically. The default value + * is false. + */ + keyboardShouldPersistTaps?: boolean + + /** + * Fires at most once per frame during scrolling. + * The frequency of the events can be contolled using the scrollEventThrottle prop. + */ + onScroll?: () => void + + /** + * Experimental: When true offscreen child views (whose `overflow` value is + * `hidden`) are removed from their native backing superview when offscreen. + * This canimprove scrolling performance on long lists. The default value is + * false. + */ + removeClippedSubviews?: boolean + + /** + * When true, shows a horizontal scroll indicator. + */ + showsHorizontalScrollIndicator?: boolean + + /** + * When true, shows a vertical scroll indicator. + */ + showsVerticalScrollIndicator?: boolean + + /** + * Style + */ + style?: ScrollViewStyle + } + + export interface ScrollViewProps extends ScrollViewProperties, React.Props { + + } + + interface ScrollViewStatic extends React.ComponentClass { } @@ -1173,20 +1866,23 @@ declare namespace ReactNative { // exported singletons: // export var AppRegistry: AppRegistryStatic; - export var StyleSheet: StyleSheetStatic; - export var Navigator: NavigatorStatic; - export type Navigator = NavigatorStatic; - export var ListView: ListViewStatic; + export var AsyncStorage: AsyncStorageStatic; export var CameraRoll: CameraRollStatic; export var Image: ImageStatic; export type Image = ImageStatic; + export var ListView: ListViewStatic; + export type Navigator = NavigatorStatic; + export var Navigator: NavigatorStatic; + export var NavigatorIOS: NavigatorIOSStatic; + export var SliderIOS: SliderIOSStatic; + export var ScrollView: ScrollViewStatic + export var StyleSheet: StyleSheetStatic; export var TabBarIOS: TabBarIOSStatic; export type TabBarIOS = TabBarIOSStatic; - export var AsyncStorage: AsyncStorageStatic; + export var View: ViewStatic; export var Text: React.ComponentClass; - export var View: React.ComponentClass; - export var NavigatorIOS: React.ComponentClass; + export var TextInput: React.ComponentClass; export var AlertIOS: React.ComponentClass; export var SegmentedControlIOS: React.ComponentClass; export var SwitchIOS: React.ComponentClass; @@ -1201,9 +1897,7 @@ declare namespace ReactNative { export var DeviceEventSubscription: DeviceEventSubscriptionStatic; export type DeviceEventSubscription = DeviceEventSubscriptionStatic; export var InteractionManager: InteractionManagerStatic; - export var ScrollView: React.ComponentClass; export var PanResponder: PanResponderStatic; - export var SliderIOS: React.ComponentClass; export var AppStateIOS: AppStateIOSStatic; @@ -1420,6 +2114,20 @@ declare namespace ReactNative { // export function __spread( target: any, ...sources: any[] ): any; + + + export interface GlobalStatic { + + /** + * Accepts a function as its only argument and calls that function before the next repaint. + * It is an essential building block for animations that underlies all of the JavaScript-based animation APIs. + * In general, you shouldn't need to call this yourself - the animation API's will manage frame updates for you. + * @see https://facebook.github.io/react-native/docs/animations.html#requestanimationframe + */ + requestAnimationFrame( fn: () => void ) : void; + + } + } declare module "react-native" { @@ -1438,3 +2146,5 @@ declare module "Dimensions" { var ExportDimensions: Dimensions; export = ExportDimensions; } + +declare var global: ReactNative.GlobalStatic From c4d09a5d1c0f09c27bceaebc7b96bd060234dd8c Mon Sep 17 00:00:00 2001 From: bgrieder Date: Mon, 9 Nov 2015 12:16:08 +0100 Subject: [PATCH 08/15] More Fixes + TouchableHighlight + TouchableOpacity + TouchableWithoutFeedback --- react-native/react-native.d.ts | 131 ++++++++++++++++++++------------- 1 file changed, 78 insertions(+), 53 deletions(-) diff --git a/react-native/react-native.d.ts b/react-native/react-native.d.ts index 7f5832749..92ad7a217 100644 --- a/react-native/react-native.d.ts +++ b/react-native/react-native.d.ts @@ -369,7 +369,7 @@ declare namespace ReactNative { /** * @see https://facebook.github.io/react-native/docs/textinput.html#props */ - export interface TextInputProperties extends TextInputIOSProperties, TextInputAndroidProperties { + export interface TextInputProperties extends TextInputIOSProperties, TextInputAndroidProperties, React.Props { /** * Can tell TextInput to automatically capitalize certain characters. @@ -438,7 +438,7 @@ declare namespace ReactNative { * Callback that is called when the text input's text changes. * Changed text is passed as an argument to the callback handler. */ - onChangeText?: () => void + onChangeText?: (text: string) => void /** * Callback that is called when text input ends. @@ -496,6 +496,10 @@ declare namespace ReactNative { value?: string } + export interface TextInputStatic extends React.ComponentClass { + + } + export interface AccessibilityTraits { // TODO } @@ -658,7 +662,7 @@ declare namespace ReactNative { testID?: string; } - interface ViewStatic extends React.ComponentClass { + export interface ViewStatic extends React.ComponentClass { } @@ -823,7 +827,7 @@ declare namespace ReactNative { style?: ViewStyle } - interface NavigatorIOSStatic extends React.ComponentClass { + export interface NavigatorIOSStatic extends React.ComponentClass { } @@ -885,7 +889,7 @@ declare namespace ReactNative { value?: number; } - interface SliderIOSStatic extends React.ComponentClass { + export interface SliderIOSStatic extends React.ComponentClass { } @@ -1000,7 +1004,7 @@ declare namespace ReactNative { } /** - * @see + * @see https://facebook.github.io/react-native/docs/listview.html#props */ export interface ListViewProperties extends ScrollViewProperties, React.Props{ @@ -1111,47 +1115,12 @@ declare namespace ReactNative { scrollRenderAheadDistance?: number } - /** - * @see https://facebook.github.io/react-native/docs/touchablehighlight.html#props - */ - export interface TouchableHighlightProperties { - /** - * activeOpacity number - * - * Determines what the opacity of the wrapped view should be when touch is active. - */ - activeOpacity?: number; - - /** - * onHideUnderlay function - * - * Called immediately after the underlay is hidden - */ - - onHideUnderlay?: () => void; - - - /** - * onShowUnderlay function - * - * Called immediately after the underlay is shown - */ - - /** - * @see https://facebook.github.io/react-native/docs/view.html#style - */ - style?: ViewStyle; - - - /** - * underlayColor string - * - * The color of the underlay that will show through when the touch is active. - */ - underlayColor?: string; - + export interface ListViewStatic extends React.ComponentClass { + DataSource: ListViewDataSource; } + + /** * @see https://facebook.github.io/react-native/docs/touchablewithoutfeedback.html */ @@ -1205,10 +1174,65 @@ declare namespace ReactNative { } + export interface TouchableWithoutFeedbackProps extends TouchableWithoutFeedbackProperties, React.Props { + + } + + export interface TouchableWithoutFeedbackStatic extends React.ComponentClass { + + } + + + /** + * @see https://facebook.github.io/react-native/docs/touchablehighlight.html#props + */ + export interface TouchableHighlightProperties extends TouchableWithoutFeedbackProperties, React.Props { + /** + * activeOpacity number + * + * Determines what the opacity of the wrapped view should be when touch is active. + */ + activeOpacity?: number + + /** + * onHideUnderlay function + * + * Called immediately after the underlay is hidden + */ + + onHideUnderlay?: () => void + + + /** + * onShowUnderlay function + * + * Called immediately after the underlay is shown + */ + onShowUnderlay?: () => void + + /** + * @see https://facebook.github.io/react-native/docs/view.html#style + */ + style?: ViewStyle + + + /** + * underlayColor string + * + * The color of the underlay that will show through when the touch is active. + */ + underlayColor?: string + + } + + export interface TouchableHighlightStatic extends React.ComponentClass { + } + + /** * @see https://facebook.github.io/react-native/docs/touchableopacity.html#props */ - export interface TouchableOpacityProperties { + export interface TouchableOpacityProperties extends TouchableWithoutFeedbackProperties, React.Props { /** * activeOpacity number * @@ -1217,6 +1241,10 @@ declare namespace ReactNative { activeOpacity?: number; } + export interface TouchableOpacityStatic extends React.ComponentClass { + } + + export interface LeftToRightGesture { @@ -1382,9 +1410,6 @@ declare namespace ReactNative { getSectionHeaderData( sectionIndex: number ): any } - export interface ListViewStatic extends React.ComponentClass { - DataSource: ListViewDataSource; - } export interface ImageStatic extends React.ComponentClass { uri: string; @@ -1879,16 +1904,16 @@ declare namespace ReactNative { export var StyleSheet: StyleSheetStatic; export var TabBarIOS: TabBarIOSStatic; export type TabBarIOS = TabBarIOSStatic; + export var TextInput: TextInputStatic + export var TouchableHighlight: TouchableHighlightStatic; + export var TouchableOpacity:TouchableOpacityStatic; + export var TouchableWithoutFeedback: TouchableWithoutFeedbackStatic; export var View: ViewStatic; export var Text: React.ComponentClass; - export var TextInput: React.ComponentClass; export var AlertIOS: React.ComponentClass; export var SegmentedControlIOS: React.ComponentClass; export var SwitchIOS: React.ComponentClass; - export var TouchableHighlight: React.ComponentClass; - export var TouchableOpacity: React.ComponentClass; - export var TouchableWithoutFeedback: React.ComponentClass; export var ActivityIndicatorIOS: React.ComponentClass; From 6dedc3d5b555473b065579462865658358db11e3 Mon Sep 17 00:00:00 2001 From: bgrieder Date: Mon, 9 Nov 2015 12:35:14 +0100 Subject: [PATCH 09/15] Fixes to Text Component --- react-native/react-native.d.ts | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/react-native/react-native.d.ts b/react-native/react-native.d.ts index 92ad7a217..15cf5312b 100644 --- a/react-native/react-native.d.ts +++ b/react-native/react-native.d.ts @@ -5,12 +5,12 @@ /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // -// This work is mostly based on the work made by Bernd Paradies: https://github.com/bparadie +// This work is based on an original work made by Bernd Paradies: https://github.com/bparadie // -// These definitions are meant to be used with the compiler target set to ES6 +// These definitions are meant to be used with the TSC compiler target set to ES6 // // WARNING: this work is very much beta: -// -it may be missing react-native definitions +// -it is still missing react-native definitions // -it re-exports the whole of react 0.14 which may not be what react-native actually does // /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -248,7 +248,7 @@ declare namespace ReactNative { } // https://facebook.github.io/react-native/docs/text.html#props - export interface TextProperties { + export interface TextProperties extends React.Props { /** * numberOfLines number * @@ -278,6 +278,10 @@ declare namespace ReactNative { style?: TextStyle; } + export interface TextStatic extends React.ComponentClass { + + } + /** * IOS Specific properties for TextInput @@ -1904,13 +1908,13 @@ declare namespace ReactNative { export var StyleSheet: StyleSheetStatic; export var TabBarIOS: TabBarIOSStatic; export type TabBarIOS = TabBarIOSStatic; + export var Text: TextStatic; export var TextInput: TextInputStatic export var TouchableHighlight: TouchableHighlightStatic; export var TouchableOpacity:TouchableOpacityStatic; export var TouchableWithoutFeedback: TouchableWithoutFeedbackStatic; export var View: ViewStatic; - export var Text: React.ComponentClass; export var AlertIOS: React.ComponentClass; export var SegmentedControlIOS: React.ComponentClass; export var SwitchIOS: React.ComponentClass; From 34a93a77af56554417d960e7138fbc59514a889a Mon Sep 17 00:00:00 2001 From: bgrieder Date: Mon, 9 Nov 2015 14:48:00 +0100 Subject: [PATCH 10/15] Improvements to Route and NavigatorIOS --- react-native/react-native.d.ts | 69 +++++++++++++++++++++++++++++++++- 1 file changed, 67 insertions(+), 2 deletions(-) diff --git a/react-native/react-native.d.ts b/react-native/react-native.d.ts index 15cf5312b..5a3481b1d 100644 --- a/react-native/react-native.d.ts +++ b/react-native/react-native.d.ts @@ -831,7 +831,62 @@ declare namespace ReactNative { style?: ViewStyle } - export interface NavigatorIOSStatic extends React.ComponentClass { + /** + * A navigator is an object of navigation functions that a view can call. + * It is passed as a prop to any component rendered by NavigatorIOS. + * + * Navigator functions are also available on the NavigatorIOS component: + * + * @see https://facebook.github.io/react-native/docs/navigatorios.html#navigator + */ + export interface NavigationIOS { + /** + * Navigate forward to a new route + */ + push: (route: Route) => void + + /** + * Go back one page + */ + pop: () => void + + /** + * Go back N pages at once. When N=1, behavior matches pop() + */ + popN: (n: number) => void + + /** + * Replace the route for the current page and immediately load the view for the new route + */ + replace: (route: Route) => void + + /** + * Replace the route/view for the previous page + */ + replacePrevious: (route: Route) => void + + /** + * Replaces the previous route/view and transitions back to it + */ + replacePreviousAndPop: (route: Route) => void + + /** + * Replaces the top item and popToTop + */ + resetTo: (route: Route) => void + + /** + * Go back to the item for a particular route object + */ + popToRoute(route: Route): void + + /** + * Go back to the top item + */ + popToTop(): void + } + + export interface NavigatorIOSStatic extends NavigationIOS, React.ComponentClass { } @@ -1293,7 +1348,17 @@ declare namespace ReactNative { component?: ComponentClass id?: string; title?: string; - passProps?: Object + passProps?: Object; + + //anything else + [key: string]: any + + //Commonly found properties + backButtonTitle?: string; + rightButtonTitle?: string; + onRightButtonPress?: () => void; + wrapperStyle?: any; //FIXME needs typing + index?: number; } /** From d6c0b99afe073160a05902efb7e526cc87e65e8b Mon Sep 17 00:00:00 2001 From: bgrieder Date: Tue, 10 Nov 2015 08:53:19 +0100 Subject: [PATCH 11/15] Fixes to Navigator. Added NavigatorStatic.NavigationBar --- react-native/react-native.d.ts | 300 +++++++++++++++++++++++---------- 1 file changed, 208 insertions(+), 92 deletions(-) diff --git a/react-native/react-native.d.ts b/react-native/react-native.d.ts index 5a3481b1d..c82a94013 100644 --- a/react-native/react-native.d.ts +++ b/react-native/react-native.d.ts @@ -442,7 +442,7 @@ declare namespace ReactNative { * Callback that is called when the text input's text changes. * Changed text is passed as an argument to the callback handler. */ - onChangeText?: (text: string) => void + onChangeText?: ( text: string ) => void /** * Callback that is called when text input ends. @@ -728,63 +728,6 @@ declare namespace ReactNative { /// TODO } - /** - * @see https://facebook.github.io/react-native/docs/navigator.html#content - */ - export interface NavigatorProperties extends React.Props { - /** - * Optional function that allows configuration about scene animations and gestures. - * Will be invoked with the route and should return a scene configuration object - * @param route - */ - configureScene?: ( route: Route ) => SceneConfig - /** - * Specify a route to start on. - * A route is an object that the navigator will use to identify each scene to render. - * initialRoute must be a route in the initialRouteStack if both props are provided. - * The initialRoute will default to the last item in the initialRouteStack. - */ - initialRoute?: Route - /** - * Provide a set of routes to initially mount. - * Required if no initialRoute is provided. - * Otherwise, it will default to an array containing only the initialRoute - */ - initialRouteStack?: Route[] - - /** - * Optionally provide a navigation bar that persists across scene transitions - */ - navigationBar?: NavigationBar - - /** - * Optionally provide the navigator object from a parent Navigator - */ - navigator?: Navigator - - /** - * @deprecated Use navigationContext.addListener('willfocus', callback) instead. - */ - onDidFocus?: Function - - /** - * @deprecated Use navigationContext.addListener('willfocus', callback) instead. - */ - onWillFocus?: Function - - /** - * Required function which renders the scene for a given route. - * Will be invoked with the route and the navigator object - * @param route - * @param navigator - */ - renderScene: ( route: Route, navigator: Navigator ) => React.ComponentClass - - /** - * Styles to apply to the container of each scene - */ - sceneStyle: ViewStyle - } export interface NavigatorIOSProperties extends React.Props { @@ -843,7 +786,7 @@ declare namespace ReactNative { /** * Navigate forward to a new route */ - push: (route: Route) => void + push: ( route: Route ) => void /** * Go back one page @@ -853,32 +796,32 @@ declare namespace ReactNative { /** * Go back N pages at once. When N=1, behavior matches pop() */ - popN: (n: number) => void + popN: ( n: number ) => void /** * Replace the route for the current page and immediately load the view for the new route */ - replace: (route: Route) => void + replace: ( route: Route ) => void /** * Replace the route/view for the previous page */ - replacePrevious: (route: Route) => void + replacePrevious: ( route: Route ) => void /** * Replaces the previous route/view and transitions back to it */ - replacePreviousAndPop: (route: Route) => void + replacePreviousAndPop: ( route: Route ) => void /** * Replaces the top item and popToTop */ - resetTo: (route: Route) => void + resetTo: ( route: Route ) => void /** * Go back to the item for a particular route object */ - popToRoute(route: Route): void + popToRoute( route: Route ): void /** * Go back to the top item @@ -887,7 +830,6 @@ declare namespace ReactNative { } export interface NavigatorIOSStatic extends NavigationIOS, React.ComponentClass { - } @@ -979,7 +921,7 @@ declare namespace ReactNative { /** * @see https://facebook.github.io/react-native/docs/image.html */ - export interface ImageProperties extends React.Props { + export interface ImageProperties extends React.Props { /** * onLayout function * @@ -1065,7 +1007,7 @@ declare namespace ReactNative { /** * @see https://facebook.github.io/react-native/docs/listview.html#props */ - export interface ListViewProperties extends ScrollViewProperties, React.Props{ + export interface ListViewProperties extends ScrollViewProperties, React.Props { dataSource?: ListViewDataSource @@ -1085,7 +1027,7 @@ declare namespace ReactNative { * that have changed their visibility, with true indicating visible, and * false indicating the view has moved out of view. */ - onChangeVisibleRows?: (visibleRows: Array<{[sectionId: string]: {[rowID: string]: boolean}}>, changedRows: Array<{[sectionId: string]: {[rowID: string]: boolean}}>) => void + onChangeVisibleRows?: ( visibleRows: Array<{[sectionId: string]: {[rowID: string]: boolean}}>, changedRows: Array<{[sectionId: string]: {[rowID: string]: boolean}}> ) => void /** * Called when all rows have been rendered and the list has been scrolled @@ -1138,14 +1080,14 @@ declare namespace ReactNative { * is exactly what was put into the data source, but it's also possible to * provide custom extractors. */ - renderRow?: (rowData: any, sectionID: string, rowID: string, highlightRow?: boolean) => React.ReactElement + renderRow?: ( rowData: any, sectionID: string, rowID: string, highlightRow?: boolean ) => React.ReactElement /** * A function that returns the scrollable component in which the list rows are rendered. * Defaults to returning a ScrollView with the given props. */ - renderScrollComponent?: (props: ScrollViewProperties) => React.ReactElement + renderScrollComponent?: ( props: ScrollViewProperties ) => React.ReactElement /** * (sectionData, sectionID) => renderable @@ -1156,7 +1098,7 @@ declare namespace ReactNative { * stick to the top until it is pushed off the screen by the next section * header. */ - renderSectionHeader?: (sectionData: any, sectionId: string) => React.ReactElement + renderSectionHeader?: ( sectionData: any, sectionId: string ) => React.ReactElement /** @@ -1165,7 +1107,7 @@ declare namespace ReactNative { * but not the last row if there is a section header below. * Take a sectionID and rowID of the row above and whether its adjacent row is highlighted. */ - renderSeparator?: (sectionID: string, rowID: string, adjacentRowHighlighted?: boolean) => React.ReactElement + renderSeparator?: ( sectionID: string, rowID: string, adjacentRowHighlighted?: boolean ) => React.ReactElement /** * How early to start rendering rows before they come on screen, in @@ -1179,7 +1121,6 @@ declare namespace ReactNative { } - /** * @see https://facebook.github.io/react-native/docs/touchablewithoutfeedback.html */ @@ -1237,7 +1178,7 @@ declare namespace ReactNative { } - export interface TouchableWithoutFeedbackStatic extends React.ComponentClass { + export interface TouchableWithoutFeedbackStatic extends React.ComponentClass { } @@ -1304,7 +1245,6 @@ declare namespace ReactNative { } - export interface LeftToRightGesture { } @@ -1346,54 +1286,202 @@ declare namespace ReactNative { export interface Route { component?: ComponentClass - id?: string; - title?: string; + id?: string + title?: string passProps?: Object; //anything else [key: string]: any //Commonly found properties - backButtonTitle?: string; - rightButtonTitle?: string; - onRightButtonPress?: () => void; - wrapperStyle?: any; //FIXME needs typing - index?: number; + backButtonTitle?: string + content?: string + message?: string; + index?: number + onRightButtonPress?: () => void + rightButtonTitle?: string + sceneConfig?: SceneConfig + wrapperStyle?: any } + /** - * @see + * @see https://facebook.github.io/react-native/docs/navigator.html#content */ - export interface NavigatorBarProperties { + export interface NavigatorProperties extends React.Props { + /** + * Optional function that allows configuration about scene animations and gestures. + * Will be invoked with the route and should return a scene configuration object + * @param route + */ + configureScene?: ( route: Route ) => SceneConfig + /** + * Specify a route to start on. + * A route is an object that the navigator will use to identify each scene to render. + * initialRoute must be a route in the initialRouteStack if both props are provided. + * The initialRoute will default to the last item in the initialRouteStack. + */ + initialRoute?: Route + /** + * Provide a set of routes to initially mount. + * Required if no initialRoute is provided. + * Otherwise, it will default to an array containing only the initialRoute + */ + initialRouteStack?: Route[] - } + /** + * Optionally provide a navigation bar that persists across scene transitions + */ + navigationBar?: React.ReactElement - export interface NavigationBar extends React.ComponentClass { + /** + * Optionally provide the navigator object from a parent Navigator + */ + navigator?: Navigator + + /** + * @deprecated Use navigationContext.addListener('willfocus', callback) instead. + */ + onDidFocus?: Function + + /** + * @deprecated Use navigationContext.addListener('willfocus', callback) instead. + */ + onWillFocus?: Function + + /** + * Required function which renders the scene for a given route. + * Will be invoked with the route and the navigator object + * @param route + * @param navigator + */ + renderScene?: ( route: Route, navigator: Navigator ) => React.ReactElement + + /** + * Styles to apply to the container of each scene + */ + sceneStyle?: ViewStyle + + /** + * //FIXME: not found in doc but found in examples + */ + debugOverlay?: boolean } /** + * Use Navigator to transition between different scenes in your app. + * To accomplish this, provide route objects to the navigator to identify each scene, + * and also a renderScene function that the navigator can use to render the scene for a given route. + * + * To change the animation or gesture properties of the scene, provide a configureScene prop to get the config object for a given route. + * See Navigator.SceneConfigs for default animations and more info on scene config options. * @see https://facebook.github.io/react-native/docs/navigator.html */ export interface NavigatorStatic extends React.ComponentClass { SceneConfigs: SceneConfigs; - NavigationBar: NavigationBar; + NavigationBar: NavigatorStatic.NavigationBar; + getContext( self: any ): NavigatorStatic; + /** + * returns the current list of routes + */ getCurrentRoutes(): Route[]; + + /** + * Jump backward without unmounting the current scen + */ jumpBack(): void; + + /** + * Jump forward to the next scene in the route stack + */ jumpForward(): void; + + /** + * Transition to an existing scene without unmounting + */ jumpTo( route: Route ): void; + + /** + * Navigate forward to a new scene, squashing any scenes that you could jumpForward to + */ push( route: Route ): void; + + /** + * Transition back and unmount the current scene + */ pop(): void; + + /** + * Replace the current scene with a new route + */ replace( route: Route ): void; + + /** + * Replace a scene as specified by an index + */ replaceAtIndex( route: Route, index: number ): void; + + /** + * Replace the previous scene + */ replacePrevious( route: Route ): void; + + /** + * Reset every scene with an array of routes + */ immediatelyResetRouteStack( routes: Route[] ): void; + + /** + * Pop to a particular scene, as specified by its route. All scenes after it will be unmounted + */ popToRoute( route: Route ): void; + + /** + * Pop to the first scene in the stack, unmounting every other scene + */ popToTop(): void; } + module NavigatorStatic { + + + export interface NavState { + routeStack: Route[] + idStack: number[] + presentedIndex: number + } + + export interface NavigationBarStyle { + //TODO @see NavigationBarStyle.ios.js + } + + /** + * @see NavigatorNavigationBar.js + */ + export interface NavigationBarProperties extends React.Props{ + navigator?: Navigator + routeMapper?: ({ + Title: ( route: Route, nav: Navigator, index: number, navState: NavState ) => React.ReactElement; + LeftButton: ( route: Route, nav: Navigator, index: number, navState: NavState )=> React.ReactElement; + RightButton: ( route: Route, nav: Navigator, index: number, navState: NavState )=> React.ReactElement; + }) + navState?: NavState + style?: ViewStyle + } + + export interface NavigationBarStatic extends React.ComponentClass { + Styles?: NavigationBarStyle + + } + + export var NavigationBar: NavigationBarStatic + export type NavigationBar = NavigationBarStatic + } + + export interface StyleSheetStatic extends React.ComponentClass { create( styles: T ): T; } @@ -1961,30 +2049,56 @@ declare namespace ReactNative { // exported singletons: // export var AppRegistry: AppRegistryStatic; export var AsyncStorage: AsyncStorageStatic; + export type AsyncStorage = AsyncStorageStatic; + export var CameraRoll: CameraRollStatic; + export type CameraRoll = CameraRollStatic; + export var Image: ImageStatic; export type Image = ImageStatic; + export var ListView: ListViewStatic; - export type Navigator = NavigatorStatic; + export type ListView = ListViewStatic; + export var Navigator: NavigatorStatic; + export type Navigator = NavigatorStatic; + export var NavigatorIOS: NavigatorIOSStatic; + export type NavigatorIOS = NavigatorIOSStatic; + export var SliderIOS: SliderIOSStatic; + export type SliderIOS = SliderIOSStatic; + export var ScrollView: ScrollViewStatic + export type ScrollView = ScrollViewStatic + export var StyleSheet: StyleSheetStatic; + export type StyleSheet = StyleSheetStatic; + export var TabBarIOS: TabBarIOSStatic; export type TabBarIOS = TabBarIOSStatic; + export var Text: TextStatic; + export type Text = TextStatic; + export var TextInput: TextInputStatic + export type TextInput = TextInputStatic + export var TouchableHighlight: TouchableHighlightStatic; - export var TouchableOpacity:TouchableOpacityStatic; + export type TouchableHighlight = TouchableHighlightStatic; + + export var TouchableOpacity: TouchableOpacityStatic; + export type TouchableOpacity = TouchableOpacityStatic; + export var TouchableWithoutFeedback: TouchableWithoutFeedbackStatic; + export type TouchableWithoutFeedback= TouchableWithoutFeedbackStatic; + export var View: ViewStatic; + export type View = ViewStatic; export var AlertIOS: React.ComponentClass; export var SegmentedControlIOS: React.ComponentClass; export var SwitchIOS: React.ComponentClass; - - export var ActivityIndicatorIOS: React.ComponentClass; export var PixelRatio: PixelRatioStatic; export var DeviceEventEmitter: DeviceEventEmitterStatic; @@ -2242,3 +2356,5 @@ declare module "Dimensions" { } declare var global: ReactNative.GlobalStatic + +declare function require(name: string): any From 303486394ff000e036ffce9472b74e4b5be00861 Mon Sep 17 00:00:00 2001 From: bgrieder Date: Tue, 10 Nov 2015 17:26:29 +0100 Subject: [PATCH 12/15] Fixes to NavigationBar and BreadcrumbNavigationBar --- react-native/react-native.d.ts | 62 ++++++++++++++++++++++++++++------ 1 file changed, 52 insertions(+), 10 deletions(-) diff --git a/react-native/react-native.d.ts b/react-native/react-native.d.ts index c82a94013..f3120c004 100644 --- a/react-native/react-native.d.ts +++ b/react-native/react-native.d.ts @@ -1380,7 +1380,8 @@ declare namespace ReactNative { */ export interface NavigatorStatic extends React.ComponentClass { SceneConfigs: SceneConfigs; - NavigationBar: NavigatorStatic.NavigationBar; + NavigationBar: NavigatorStatic.NavigationBarStatic; + BreadcrumbNavigationBar: NavigatorStatic.BreadcrumbNavigationBarStatic getContext( self: any ): NavigatorStatic; @@ -1443,9 +1444,10 @@ declare namespace ReactNative { * Pop to the first scene in the stack, unmounting every other scene */ popToTop(): void; + } - module NavigatorStatic { + namespace NavigatorStatic { export interface NavState { @@ -1458,27 +1460,61 @@ declare namespace ReactNative { //TODO @see NavigationBarStyle.ios.js } + + export interface NavigationBarRouteMapper { + Title: ( route: Route, nav: Navigator, index: number, navState: NavState ) => React.ReactElement; + LeftButton: ( route: Route, nav: Navigator, index: number, navState: NavState )=> React.ReactElement; + RightButton: ( route: Route, nav: Navigator, index: number, navState: NavState )=> React.ReactElement; + } + /** * @see NavigatorNavigationBar.js */ - export interface NavigationBarProperties extends React.Props{ + export interface NavigationBarProperties extends React.Props{ navigator?: Navigator - routeMapper?: ({ - Title: ( route: Route, nav: Navigator, index: number, navState: NavState ) => React.ReactElement; - LeftButton: ( route: Route, nav: Navigator, index: number, navState: NavState )=> React.ReactElement; - RightButton: ( route: Route, nav: Navigator, index: number, navState: NavState )=> React.ReactElement; - }) + routeMapper?: NavigationBarRouteMapper navState?: NavState style?: ViewStyle } export interface NavigationBarStatic extends React.ComponentClass { - Styles?: NavigationBarStyle + Styles: NavigationBarStyle } - export var NavigationBar: NavigationBarStatic export type NavigationBar = NavigationBarStatic + export var NavigationBar: NavigationBarStatic + + + export interface BreadcrumbNavigationBarStyle { + //TODO &see NavigatorBreadcrumbNavigationBar.js + } + + export interface BreadcrumbNavigationBarRouteMapper { + rightContentForRoute: (route: Route, navigator: Navigator) => React.ReactElement + titleContentForRoute: (route: Route, navigator: Navigator) => React.ReactElement + iconForRoute: (route: Route, navigator: Navigator) => React.ReactElement + //in samples... + separatorForRoute: (route: Route, navigator: Navigator) => React.ReactElement + } + + /** + * @see NavigatorNavigationBar.js + */ + export interface BreadcrumbNavigationBarProperties extends React.Props{ + navigator?: Navigator + routeMapper?: BreadcrumbNavigationBarRouteMapper + navState?: NavState + style?: ViewStyle + } + + export interface BreadcrumbNavigationBarStatic extends React.ComponentClass { + Styles: BreadcrumbNavigationBarStyle + } + + export type BreadcrumbNavigationBar = BreadcrumbNavigationBarStatic + var BreadcrumbNavigationBar: BreadcrumbNavigationBarStatic + } @@ -2063,6 +2099,12 @@ declare namespace ReactNative { export var Navigator: NavigatorStatic; export type Navigator = NavigatorStatic; + //export var NavigationBar: NavigationBarStatic + //export type NavigationBar = NavigationBarStatic + + //export var BreadcrumbNavigationBar: BreadcrumbNavigationBarStatic + //export type BreadcrumbNavigationBar = BreadcrumbNavigationBarStatic + export var NavigatorIOS: NavigatorIOSStatic; export type NavigatorIOS = NavigatorIOSStatic; From a3631563a87205e404e1dccb7b6aec14337793c3 Mon Sep 17 00:00:00 2001 From: bgrieder Date: Wed, 11 Nov 2015 06:42:07 +0100 Subject: [PATCH 13/15] added ActivityIndicatorsIOS --- react-native/react-native.d.ts | 63 +++++++++++++++++++++++++++------- 1 file changed, 50 insertions(+), 13 deletions(-) diff --git a/react-native/react-native.d.ts b/react-native/react-native.d.ts index f3120c004..10cfb50c5 100644 --- a/react-native/react-native.d.ts +++ b/react-native/react-native.d.ts @@ -5,10 +5,10 @@ /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // -// This work is based on an original work made by Bernd Paradies: https://github.com/bparadie -// // These definitions are meant to be used with the TSC compiler target set to ES6 // +// This work is based on an original work made by Bernd Paradies: https://github.com/bparadie +// // WARNING: this work is very much beta: // -it is still missing react-native definitions // -it re-exports the whole of react 0.14 which may not be what react-native actually does @@ -834,10 +834,42 @@ declare namespace ReactNative { /** - * @see + * @see https://facebook.github.io/react-native/docs/activityindicatorios.html#props */ - export interface ActivityIndicatorIOSProperties { - /// TODO + export interface ActivityIndicatorIOSProperties extends React.Props { + + /** + * Whether to show the indicator (true, the default) or hide it (false). + */ + animating?: boolean + + /** + * The foreground color of the spinner (default is gray). + */ + color?: string + + /** + * Whether the indicator should hide when not animating (true by default). + */ + hidesWhenStopped?: boolean + + /** + * Invoked on mount and layout changes with + */ + onLayout?: ( event: {nativeEvent: { layout: {x: number, y: number , width: number, height: number}}} ) => void + + /** + * Size of the indicator. + * Small has a height of 20, large has a height of 36. + * + * enum('small', 'large') + */ + size?: string + + style?: ViewStyle + } + + export interface ActivityIndicatorIOSStatic extends React.ComponentClass { } /** @@ -1470,7 +1502,7 @@ declare namespace ReactNative { /** * @see NavigatorNavigationBar.js */ - export interface NavigationBarProperties extends React.Props{ + export interface NavigationBarProperties extends React.Props { navigator?: Navigator routeMapper?: NavigationBarRouteMapper navState?: NavState @@ -1491,17 +1523,17 @@ declare namespace ReactNative { } export interface BreadcrumbNavigationBarRouteMapper { - rightContentForRoute: (route: Route, navigator: Navigator) => React.ReactElement - titleContentForRoute: (route: Route, navigator: Navigator) => React.ReactElement - iconForRoute: (route: Route, navigator: Navigator) => React.ReactElement + rightContentForRoute: ( route: Route, navigator: Navigator ) => React.ReactElement + titleContentForRoute: ( route: Route, navigator: Navigator ) => React.ReactElement + iconForRoute: ( route: Route, navigator: Navigator ) => React.ReactElement //in samples... - separatorForRoute: (route: Route, navigator: Navigator) => React.ReactElement + separatorForRoute: ( route: Route, navigator: Navigator ) => React.ReactElement } /** * @see NavigatorNavigationBar.js */ - export interface BreadcrumbNavigationBarProperties extends React.Props{ + export interface BreadcrumbNavigationBarProperties extends React.Props { navigator?: Navigator routeMapper?: BreadcrumbNavigationBarRouteMapper navState?: NavState @@ -2084,6 +2116,11 @@ declare namespace ReactNative { // exported singletons: // export var AppRegistry: AppRegistryStatic; + + + export var ActivityIndicatorIOS: ActivityIndicatorIOSStatic; + export type ActivityIndicatorIOS = ActivityIndicatorIOSStatic; + export var AsyncStorage: AsyncStorageStatic; export type AsyncStorage = AsyncStorageStatic; @@ -2141,7 +2178,7 @@ declare namespace ReactNative { export var AlertIOS: React.ComponentClass; export var SegmentedControlIOS: React.ComponentClass; export var SwitchIOS: React.ComponentClass; - export var ActivityIndicatorIOS: React.ComponentClass; + export var PixelRatio: PixelRatioStatic; export var DeviceEventEmitter: DeviceEventEmitterStatic; export var DeviceEventSubscription: DeviceEventSubscriptionStatic; @@ -2399,4 +2436,4 @@ declare module "Dimensions" { declare var global: ReactNative.GlobalStatic -declare function require(name: string): any +declare function require( name: string ): any From 91c74c1cf6a693c7688d8ce41ca602d03aa610ab Mon Sep 17 00:00:00 2001 From: bgrieder Date: Wed, 11 Nov 2015 07:44:36 +0100 Subject: [PATCH 14/15] Added DatePickerIOS + fixes to TextInput + TestModule (minimal) --- react/react-addons-tests.ts | 2875 ++++++++++++++++++++++++++++++----- 1 file changed, 2483 insertions(+), 392 deletions(-) diff --git a/react/react-addons-tests.ts b/react/react-addons-tests.ts index 4d8ed3212..668c7d7d2 100644 --- a/react/react-addons-tests.ts +++ b/react/react-addons-tests.ts @@ -1,415 +1,2506 @@ -/// -import React = require("react/addons"); - -import TestUtils = React.addons.TestUtils; - -interface Props extends React.Props { - hello: string; - world?: string; - foo: number; - bar: boolean; -} - -interface State { - inputValue?: string; - seconds?: number; -} - -interface Context { - someValue?: string; -} - -interface ChildContext { - someOtherValue: string; -} - -interface MyComponent extends React.Component { - reset(): void; -} - -var props: Props = { - key: 42, - ref: "myComponent42", - hello: "world", - foo: 42, - bar: true -}; - -var container: Element; +// Type definitions for react-native 0.14 +// Project: https://github.com/facebook/react-native +// Definitions by: Bruno Grieder +// Definitions: https://github.com/borisyankov/DefinitelyTyped +/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // -// Top-Level API -// -------------------------------------------------------------------------- +// These definitions are meant to be used with the TSC compiler target set to ES6 +// +// This work is based on an original work made by Bernd Paradies: https://github.com/bparadie +// +// WARNING: this work is very much beta: +// -it is still missing react-native definitions +// -it re-exports the whole of react 0.14 which may not be what react-native actually does +// +/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -var ClassicComponent: React.ClassicComponentClass = - React.createClass({ - getDefaultProps: () => { - return { - hello: undefined, - world: "peace", - foo: undefined, - bar: undefined - }; +/// + +import React = __React; + +declare namespace ReactNative { + + + /** + * Represents the completion of an asynchronous operation + * @see lib.es6.d.ts + */ + export interface Promise { + /** + * Attaches callbacks for the resolution and/or rejection of the Promise. + * @param onfulfilled The callback to execute when the Promise is resolved. + * @param onrejected The callback to execute when the Promise is rejected. + * @returns A Promise for the completion of which ever callback is executed. + */ + then( onfulfilled?: ( value: T ) => TResult | Promise, onrejected?: ( reason: any ) => TResult | Promise ): Promise; + + /** + * Attaches a callback for only the rejection of the Promise. + * @param onrejected The callback to execute when the Promise is rejected. + * @returns A Promise for the completion of the callback. + */ + catch( onrejected?: ( reason: any ) => T | Promise ): Promise; + + + // not in lib.es6.d.ts but called by react-native + done(): void; + } + + export interface PromiseConstructor { + /** + * A reference to the prototype. + */ + prototype: Promise; + + /** + * Creates a new Promise. + * @param init A callback used to initialize the promise. This callback is passed two arguments: + * a resolve callback used resolve the promise with a value or the result of another promise, + * and a reject callback used to reject the promise with a provided reason or error. + */ + new ( init: ( resolve: ( value?: T | Promise ) => void, reject: ( reason?: any ) => void ) => void ): Promise; + + ( init: ( resolve: ( value?: T | Promise ) => void, reject: ( reason?: any ) => void ) => void ): Promise; + + /** + * Creates a Promise that is resolved with an array of results when all of the provided Promises + * resolve, or rejected when any Promise is rejected. + * @param values An array of Promises. + * @returns A new Promise. + */ + all( values: (T | Promise)[] ): Promise; + + /** + * Creates a Promise that is resolved with an array of results when all of the provided Promises + * resolve, or rejected when any Promise is rejected. + * @param values An array of values. + * @returns A new Promise. + */ + all( values: Promise[] ): Promise; + + /** + * Creates a Promise that is resolved or rejected when any of the provided Promises are resolved + * or rejected. + * @param values An array of Promises. + * @returns A new Promise. + */ + race( values: (T | Promise)[] ): Promise; + + /** + * Creates a new rejected promise for the provided reason. + * @param reason The reason the promise was rejected. + * @returns A new rejected Promise. + */ + reject( reason: any ): Promise; + + /** + * Creates a new rejected promise for the provided reason. + * @param reason The reason the promise was rejected. + * @returns A new rejected Promise. + */ + reject( reason: any ): Promise; + + /** + * Creates a new resolved promise for the provided value. + * @param value A promise. + * @returns A promise whose internal state matches the provided promise. + */ + resolve( value: T | Promise ): Promise; + + /** + * Creates a new resolved promise . + * @returns A resolved promise. + */ + resolve(): Promise; + } + + // @see lib.es6.d.ts + export var Promise: PromiseConstructor; + + // node_modules/react-tools/src/classic/class/ReactClass.js + export interface ReactClass { + // TODO: + } + + // see react-jsx.d.ts + export function createElement

( type: React.ReactType, + props?: P, + ...children: React.ReactNode[] ): React.ReactElement

; + + + export type Runnable = ( appParameters: any ) => void; + + export type AppConfig = { + appKey: string; + component: ReactClass; + run?: Runnable; + } + + // https://github.com/facebook/react-native/blob/master/Libraries/AppRegistry/AppRegistry.js + export class AppRegistry { + static registerConfig( config: AppConfig[] ): void; + + static registerComponent( appKey: string, getComponentFunc: () => React.ComponentClass ): string; + + static registerRunnable( appKey: string, func: Runnable ): string; + + static runApplication( appKey: string, appParameters: any ): void; + } + + /* + export interface ReactPropTypes extends React.ReactPropTypes + { + + } + + export interface PropTypes + { + [key:string]: React.Requireable; + } + */ + + /** + * Flex Prop Types + * @see https://facebook.github.io/react-native/docs/flexbox.html#proptypes + * @see LayoutPropTypes.js + */ + export interface FlexStyle { + + alignItems?: string; //enum('flex-start', 'flex-end', 'center', 'stretch') + alignSelf?: string// enum('auto', 'flex-start', 'flex-end', 'center', 'stretch') + borderBottomWidth?: number + borderLeftWidth?: number + borderRightWidth?: number + borderTopWidth?: number + borderWidth?: number + bottom?: number + flex?: number + flexDirection?: string // enum('row', 'column') + flexWrap?: string // enum('wrap', 'nowrap') + height?: number + justifyContent?: string // enum('flex-start', 'flex-end', 'center', 'space-between', 'space-around') + left?: number + margin?: number + marginBottom?: number + marginHorizontal?: number + marginLeft?: number + marginRight?: number + marginTop?: number + marginVertical?: number + padding?: number + paddingBottom?: number + paddingHorizontal?: number + paddingLeft?: number + paddingRight?: number + paddingTop?: number + paddingVertical?: number + position?: string // enum('absolute', 'relative') + right?: number + top?: number + width?: number + } + + + export interface TransformsStyle { + + transform?: [{perspective: number}, {rotate: string}, {rotateX: string}, {rotateY: string}, {rotateZ: string}, {scale: number}, {scaleX: number}, {scaleY: number}, {translateX: number}, {translateY: number}, {skewX: string}, {skewY: string}] + transformMatrix?: Array + rotation?: number + scaleX?: number + scaleY?: number + translateX?: number + translateY?: number + + } + + + export interface StyleSheetProperties { + // TODO: + } + + export interface LayoutRectangle { + x: number; + y: number; + width: number; + height: number; + } + + // @see TextProperties.onLayout + export interface LayoutChangeEvent { + nativeEvent: { + layout: LayoutRectangle + } + } + + // @see https://facebook.github.io/react-native/docs/text.html#style + export interface TextStyle extends FlexStyle { + color?: string; + containerBackgroundColor?: string; + fontFamily?: string; + fontSize?: number; + fontStyle?: string; // 'normal' | 'italic'; + fontWeight?: string; // enum("normal", 'bold', '100', '200', '300', '400', '500', '600', '700', '800', '900') + letterSpacing?: number; + lineHeight?: number; + textAlign?: string; // enum("auto", 'left', 'right', 'center') + writingDirection?: string; //enum("auto", 'ltr', 'rtl') + } + + // https://facebook.github.io/react-native/docs/text.html#props + export interface TextProperties extends React.Props { + /** + * numberOfLines number + * + * Used to truncate the text with an elipsis after computing the text layout, including line wrapping, such that the total number of lines does not exceed this number. + */ + numberOfLines?: number; + + /** + * onLayout function + * + * Invoked on mount and layout changes with + * + * {nativeEvent: { layout: {x, y, width, height}}}. + */ + onLayout?: ( event: LayoutChangeEvent ) => void; + + /** + * onPress function + * + * This function is called on press. Text intrinsically supports press handling with a default highlight state (which can be disabled with suppressHighlighting). + */ + onPress?: () => void; + + /** + * @see https://facebook.github.io/react-native/docs/text.html#style + */ + style?: TextStyle; + } + + export interface TextStatic extends React.ComponentClass { + + } + + + /** + * IOS Specific properties for TextInput + * @see https://facebook.github.io/react-native/docs/textinput.html#props + */ + export interface TextInputIOSProperties { + + /** + * If true, the text field will blur when submitted. + * The default value is true. + */ + blurOnSubmit?: boolean + + /** + * enum('never', 'while-editing', 'unless-editing', 'always') + * When the clear button should appear on the right side of the text view + */ + clearButtonMode?: string + + /** + * If true, clears the text field automatically when editing begins + */ + clearTextOnFocus?: boolean + + /** + * If true, the keyboard disables the return key when there is no text and automatically enables it when there is text. + * The default value is false. + */ + enablesReturnKeyAutomatically?: boolean + + /** + * Callback that is called when a key is pressed. + * Pressed key value is passed as an argument to the callback handler. + * Fires before onChange callbacks. + */ + onKeyPress?: () => void + + /** + * enum('default', 'go', 'google', 'join', 'next', 'route', 'search', 'send', 'yahoo', 'done', 'emergency-call') + * Determines how the return key should look. + */ + returnKeyType?: string + + /** + * If true, all text will automatically be selected on focus + */ + selectTextOnFocus?: boolean + + /** + * //FIXME: require typing + * See DocumentSelectionState.js, some state that is responsible for maintaining selection information for a document + */ + selectionState?: any + + + } + + /** + * Android Specific properties for TextInput + * @see https://facebook.github.io/react-native/docs/textinput.html#props + */ + export interface TextInputAndroidProperties { + + /** + * Sets the number of lines for a TextInput. + * Use it with multiline set to true to be able to fill the lines. + */ + numberOfLines?: number + + /** + * enum('start', 'center', 'end') + * Set the position of the cursor from where editing will begin. + */ + textAlign?: string + + /** + * enum('top', 'center', 'bottom') + * Aligns text vertically within the TextInput. + */ + textAlignVertical?: string + + /** + * The color of the textInput underline. + */ + underlineColorAndroid?: string + } + + + /** + * @see https://facebook.github.io/react-native/docs/textinput.html#props + */ + export interface TextInputProperties extends TextInputIOSProperties, TextInputAndroidProperties, React.Props { + + /** + * Can tell TextInput to automatically capitalize certain characters. + * characters: all characters, + * words: first letter of each word + * sentences: first letter of each sentence (default) + * none: don't auto capitalize anything + * + * https://facebook.github.io/react-native/docs/textinput.html#autocapitalize + */ + autoCapitalize?: string + + /** + * If false, disables auto-correct. + * The default value is true. + */ + autoCorrect?: boolean + + /** + * If true, focuses the input on componentDidMount. + * The default value is false. + */ + autoFocus?: boolean + + /** + * Provides an initial value that will change when the user starts typing. + * Useful for simple use-cases where you don't want to deal with listening to events + * and updating the value prop to keep the controlled state in sync. + */ + defaultValue?: string + + /** + * If false, text is not editable. The default value is true. + */ + editable?: boolean + + /** + * enum("default", 'numeric', 'email-address', "ascii-capable", 'numbers-and-punctuation', 'url', 'number-pad', 'phone-pad', 'name-phone-pad', 'decimal-pad', 'twitter', 'web-search') + * Determines which keyboard to open, e.g.numeric. + * The following values work across platforms: - default - numeric - email-address + */ + keyboardType?: string + + /** + * Limits the maximum number of characters that can be entered. + * Use this instead of implementing the logic in JS to avoid flicker. + */ + maxLength?: number + + /** + * If true, the text input can be multiple lines. The default value is false. + */ + multiline?: boolean + + /** + * Callback that is called when the text input is blurred + */ + onBlur?: () => void + + /** + * Callback that is called when the text input's text changes. + */ + onChange?: (event: {nativeEvent: {text: string}}) => void + + /** + * Callback that is called when the text input's text changes. + * Changed text is passed as an argument to the callback handler. + */ + onChangeText?: ( text: string ) => void + + /** + * Callback that is called when text input ends. + */ + onEndEditing?: (event: {nativeEvent: {text: string}}) => void + + /** + * Callback that is called when the text input is focused + */ + onFocus?: () => void + + /** + * Invoked on mount and layout changes with {x, y, width, height}. + */ + onLayout?: (event: {nativeEvent: {x: number, y: number, width: number, height: number}}) => void + + /** + * Callback that is called when the text input's submit button is pressed. + */ + onSubmitEditing?: (event: {nativeEvent: {text: string}}) => void + + /** + * The string that will be rendered before text input has been entered + */ + placeholder?: string + + /** + * The text color of the placeholder string + */ + placeholderTextColor?: string + + /** + * If true, the text input obscures the text entered so that sensitive text like passwords stay secure. + * The default value is false. + */ + secureTextEntry?: boolean + + /** + * Styles + */ + style?: TextStyle + + /** + * Used to locate this view in end-to-end tests + */ + testID?: string + + /** + * The value to show for the text input. TextInput is a controlled component, + * which means the native value will be forced to match this value prop if provided. + * For most uses this works great, but in some cases this may cause flickering - one common cause is preventing edits by keeping value the same. + * In addition to simply setting the same value, either set editable={false}, + * or set/update maxLength to prevent unwanted edits without flicker. + */ + value?: string + } + + export interface TextInputStatic extends React.ComponentClass { + + } + + export interface AccessibilityTraits { + // TODO + } + + // @see https://facebook.github.io/react-native/docs/view.html#style + export interface ViewStyle extends FlexStyle, TransformsStyle { + backgroundColor?: string; + borderBottomColor?: string; + borderBottomLeftRadius?: number; + borderBottomRightRadius?: number; + borderColor?: string; + borderLeftColor?: string; + borderRadius?: number; + borderRightColor?: string; + borderTopColor?: string; + borderTopLeftRadius?: number; + borderTopRightRadius?: number; + opacity?: number; + overflow?: string; // enum('visible', 'hidden') + shadowColor?: string; + shadowOffset?: {width: number, height: number}; + shadowOpacity?: number; + shadowRadius?: number; + } + + /** + * @see https://facebook.github.io/react-native/docs/view.html#props + */ + export interface ViewProperties extends React.Props { + /** + * accessibilityLabel string + * + * Overrides the text that's read by the screen reader when the user interacts with the element. By default, the label is constructed by traversing all the children and accumulating all the Text nodes separated by space. + * + */ + + accessibilityLabel?: string; + + + /** + * accessibilityTraits AccessibilityTraits, [AccessibilityTraits] + * Provides additional traits to screen reader. By default no traits are provided unless specified otherwise in element + */ + + accessibilityTraits?: AccessibilityTraits; + + /** + * accessible bool + * + * When true, indicates that the view is an accessibility element. By default, all the touchable elements are accessible. + */ + + accessible?: boolean; + + /** + * onAcccessibilityTap function + * When accessible is true, the system will try to invoke this function when the user performs accessibility tap gesture. + * + */ + + onAcccessibilityTap?: () => void; + + /** + * onLayout function + * + * Invoked on mount and layout changes with + * + * {nativeEvent: { layout: {x, y, width, height}}}. + */ + onLayout?: ( event: LayoutChangeEvent ) => void; + + /** + * onMagicTap function + * + * When accessible is true, the system will invoke this function when the user performs the magic tap gesture. + */ + + onMagicTap?: () => void; + + /** + * onMoveShouldSetResponder function + * + * For most touch interactions, you'll simply want to wrap your component in TouchableHighlight or TouchableOpacity. Check out Touchable.js, ScrollResponder.js and ResponderEventPlugin.js for more discussion. + */ + onMoveShouldSetResponder?: () => void; + + onResponderGrant?: () => void; + + onResponderMove?: () => void; + + onResponderReject?: () => void; + + onResponderRelease?: () => void; + + onResponderTerminate?: () => void; + + onResponderTerminationRequest?: () => void; + + onStartShouldSetResponder?: () => void; + + onStartShouldSetResponderCapture?: () => void; + + /** + * pointerEvents enum('box-none', 'none', 'box-only', 'auto') + * + * In the absence of auto property, none is much like CSS's none value. box-none is as if you had applied the CSS class: + * + * .box-none { + * pointer-events: none; + * } + * .box-none * { + * pointer-events: all; + * } + * + * box-only is the equivalent of + * + * .box-only { + * pointer-events: all; + * } + * .box-only * { + * pointer-events: none; + * } + * + * But since pointerEvents does not affect layout/appearance, and we are already deviating from the spec by adding additional modes, + * we opt to not include pointerEvents on style. On some platforms, we would need to implement it as a className anyways. Using style or not is an implementation detail of the platform. + */ + + pointerEvents?: string; + + /** + * removeClippedSubviews bool + * + * This is a special performance property exposed by RCTView and is useful for scrolling content when there are many subviews, + * most of which are offscreen. For this property to be effective, it must be applied to a view that contains many subviews that extend outside its bound. + * The subviews must also have overflow: hidden, as should the containing view (or one of its superviews). + */ + + removeClippedSubviews?: boolean + + /** + * renderToHardwareTextureAndroid bool + * + * Whether this view should render itself (and all of its children) into a single hardware texture on the GPU. + * + * On Android, this is useful for animations and interactions that only modify opacity, rotation, translation, and/or scale: + * in those cases, the view doesn't have to be redrawn and display lists don't need to be re-executed. The texture can just be + * re-used and re-composited with different parameters. The downside is that this can use up limited video memory, so this prop should be set back to false at the end of the interaction/animation. + */ + + renderToHardwareTextureAndroid?: boolean; + + style?: ViewStyle; + + /** + * testID string + * + * Used to locate this view in end-to-end tests. + */ + + testID?: string; + } + + export interface ViewStatic extends React.ComponentClass { + + } + + /** + * @see https://facebook.github.io/react-native/docs/activityindicatorios.html#props + */ + export interface AlertIOSProperties { + /** + * animating bool + * + * Whether to show the indicator (true, the default) or hide it (false). + */ + animating?: boolean; + + /** + * color string + * + * The foreground color of the spinner (default is gray). + */ + + color?: string; + + /** + * hidesWhenStopped bool + * + * Whether the indicator should hide when not animating (true by default). + */ + + hidesWhenStopped?: boolean; + + /** + * onLayout function + * + * Invoked on mount and layout changes with + * + * {nativeEvent: { layout: {x, y, width, height}}}. + */ + onLayout?: ( event: LayoutChangeEvent ) => void; + + /** + * size enum('small', 'large') + * + * Size of the indicator. Small has a height of 20, large has a height of 36. + */ + size: string; // enum('small', 'large') + } + + /** + * @see + */ + export interface SegmentedControlIOSProperties { + /// TODO + } + + /** + * @see + */ + export interface SwitchIOSProperties { + /// TODO + } + + + export interface NavigatorIOSProperties extends React.Props { + + /** + * NavigatorIOS uses "route" objects to identify child views, their props, and navigation bar configuration. + * "push" and all the other navigation operations expect routes to be like this + */ + initialRoute?: Route + + /** + * The default wrapper style for components in the navigator. + * A common use case is to set the backgroundColor for every page + */ + itemWrapperStyle?: ViewStyle + + /** + * A Boolean value that indicates whether the navigation bar is hidden + */ + navigationBarHidden?: boolean + + /** + * A Boolean value that indicates whether to hide the 1px hairline shadow + */ + shadowHidden?: boolean + + /** + * The color used for buttons in the navigation bar + */ + tintColor?: string + + /** + * The text color of the navigation bar title + */ + titleTextColor?: string + + /** + * A Boolean value that indicates whether the navigation bar is translucent + */ + translucent?: boolean + + /** + * NOT IN THE DOC BUT IN THE EXAMPLES + */ + style?: ViewStyle + } + + /** + * A navigator is an object of navigation functions that a view can call. + * It is passed as a prop to any component rendered by NavigatorIOS. + * + * Navigator functions are also available on the NavigatorIOS component: + * + * @see https://facebook.github.io/react-native/docs/navigatorios.html#navigator + */ + export interface NavigationIOS { + /** + * Navigate forward to a new route + */ + push: ( route: Route ) => void + + /** + * Go back one page + */ + pop: () => void + + /** + * Go back N pages at once. When N=1, behavior matches pop() + */ + popN: ( n: number ) => void + + /** + * Replace the route for the current page and immediately load the view for the new route + */ + replace: ( route: Route ) => void + + /** + * Replace the route/view for the previous page + */ + replacePrevious: ( route: Route ) => void + + /** + * Replaces the previous route/view and transitions back to it + */ + replacePreviousAndPop: ( route: Route ) => void + + /** + * Replaces the top item and popToTop + */ + resetTo: ( route: Route ) => void + + /** + * Go back to the item for a particular route object + */ + popToRoute( route: Route ): void + + /** + * Go back to the top item + */ + popToTop(): void + } + + export interface NavigatorIOSStatic extends NavigationIOS, React.ComponentClass { + } + + + /** + * @see https://facebook.github.io/react-native/docs/activityindicatorios.html#props + */ + export interface ActivityIndicatorIOSProperties extends React.Props { + + /** + * Whether to show the indicator (true, the default) or hide it (false). + */ + animating?: boolean + + /** + * The foreground color of the spinner (default is gray). + */ + color?: string + + /** + * Whether the indicator should hide when not animating (true by default). + */ + hidesWhenStopped?: boolean + + /** + * Invoked on mount and layout changes with + */ + onLayout?: ( event: {nativeEvent: { layout: {x: number, y: number , width: number, height: number}}} ) => void + + /** + * Size of the indicator. + * Small has a height of 20, large has a height of 36. + * + * enum('small', 'large') + */ + size?: string + + style?: ViewStyle + } + + export interface ActivityIndicatorIOSStatic extends React.ComponentClass { + } + + + export interface DatePickerIOSProperties extends React.Props { + + /** + * The currently selected date. + */ + date?: Date + + + /** + * Maximum date. + * Restricts the range of possible date/time values. + */ + maximumDate?: Date + + /** + * Maximum date. + * Restricts the range of possible date/time values. + */ + minimumDate?: Date + + /** + * enum(1, 2, 3, 4, 5, 6, 10, 12, 15, 20, 30) + * The interval at which minutes can be selected. + */ + minuteInterval?: number + + /** + * enum('date', 'time', 'datetime') + * The date picker mode. + */ + mode?: string + + /** + * Date change handler. + * This is called when the user changes the date or time in the UI. + * The first and only argument is a Date object representing the new date and time. + */ + onDateChange?: (newDate: Date) => void + + /** + * Timezone offset in minutes. + * By default, the date picker will use the device's timezone. With this parameter, it is possible to force a certain timezone offset. + * For instance, to show times in Pacific Standard Time, pass -7 * 60. + */ + timeZoneOffsetInMinutes?: number + + } + + export interface DatePickerIOSStatic extends React.ComponentClass { + } + + /** + * @see https://facebook.github.io/react-native/docs/sliderios.html + */ + export interface SliderIOSProperties extends React.Props { + /** + maximumTrackTintColor string + The color used for the track to the right of the button. Overrides the default blue gradient image. + */ + maximumTrackTintColor?: string; + + /** + maximumValue number + + Initial maximum value of the slider. Default value is 1. + */ + maximumValue?: number; + + /** + minimumTrackTintColor string + The color used for the track to the left of the button. Overrides the default blue gradient image. + */ + minimumTrackTintColor?: string; + + /** + minimumValue number + Initial minimum value of the slider. Default value is 0. + */ + minimumValue?: number; + + /** + onSlidingComplete function + Callback called when the user finishes changing the value (e.g. when the slider is released). + */ + onSlidingComplete?: () => void; + + /** + onValueChange function + Callback continuously called while the user is dragging the slider. + */ + onValueChange?: ( value: number ) => void; + + /** + value number + Initial value of the slider. The value should be between minimumValue and maximumValue, which default to 0 and 1 respectively. Default value is 0. + + This is not a controlled component, e.g. if you don't update the value, the component won't be reset to its inital value. + */ + value?: number; + } + + export interface SliderIOSStatic extends React.ComponentClass { + + } + + /** + * @see + */ + export interface CameraRollProperties { + /// TODO + } + + /** + * Image style + * @see https://facebook.github.io/react-native/docs/image.html#style + */ + export interface ImageStyle extends FlexStyle { + color?: string; + containerBackgroundColor?: string; + fontFamily?: string; + fontSize?: number; + fontStyle?: string; // 'normal' | 'italic'; + fontWeight?: string; // enum("normal", 'bold', '100', '200', '300', '400', '500', '600', '700', '800', '900') + letterSpacing?: number; + lineHeight?: number; + textAlign?: string; // enum("auto", 'left', 'right', 'center') + writingDirection?: string; //enum("auto", 'ltr', 'rtl') + } + + /** + * @see https://facebook.github.io/react-native/docs/image.html + */ + export interface ImageProperties extends React.Props { + /** + * onLayout function + * + * Invoked on mount and layout changes with + * + * {nativeEvent: { layout: {x, y, width, height}}}. + */ + onLayout?: ( event: LayoutChangeEvent ) => void; + + + /** + * Determines how to resize the image when the frame doesn't match the raw image dimensions. + */ + resizeMode?: string; // enum('cover', 'contain', 'stretch') + + /** + * uri is a string representing the resource identifier for the image, + * which could be an http address, a local file path, + * or the name of a static image resource (which should be wrapped in the require('image!name') function). + */ + source: {uri: string} | string; + + /** + * + * Style + */ + style?: ImageStyle; + + /** + * A unique identifier for this element to be used in UI Automation testing scripts. + */ + testID?: string; + + /** + * The text that's read by the screen reader when the user interacts with the image. + */ + iosaccessibilityLabel?: string; + + /** + * When true, indicates the image is an accessibility element. + */ + iosaccessible?: boolean; + + /** + * When the image is resized, the corners of the size specified by capInsets will stay a fixed size, + * but the center content and borders of the image will be stretched. + * This is useful for creating resizable rounded buttons, shadows, and other resizable assets. + * More info on Apple documentation + */ + ioscapInsets?: {top: number, left: number, bottom: number, right: number} + + /** + * A static image to display while downloading the final image off the network. + */ + iosdefaultSource?: {uri: string} + + /** + * Invoked on load error with {nativeEvent: {error}} + */ + iosonError?: ( error: {nativeEvent: any} ) => void + + /** + * Invoked when load completes successfully + */ + iosonLoad?: () => void + + /** + * Invoked when load either succeeds or fails + */ + iosonLoadEnd?: () => void + + /** + * Invoked on load start + */ + iosonLoadStart?: () => void + + /** + * Invoked on download progress with {nativeEvent: {loaded, total}} + */ + iosonProgress?: ()=> void + } + + /** + * @see https://facebook.github.io/react-native/docs/listview.html#props + */ + export interface ListViewProperties extends ScrollViewProperties, React.Props { + + dataSource?: ListViewDataSource + + /** + * How many rows to render on initial component mount. Use this to make + * it so that the first screen worth of data apears at one time instead of + * over the course of multiple frames. + */ + initialListSize?: number + + /** + * (visibleRows, changedRows) => void + * + * Called when the set of visible rows changes. `visibleRows` maps + * { sectionID: { rowID: true }} for all the visible rows, and + * `changedRows` maps { sectionID: { rowID: true | false }} for the rows + * that have changed their visibility, with true indicating visible, and + * false indicating the view has moved out of view. + */ + onChangeVisibleRows?: ( visibleRows: Array<{[sectionId: string]: {[rowID: string]: boolean}}>, changedRows: Array<{[sectionId: string]: {[rowID: string]: boolean}}> ) => void + + /** + * Called when all rows have been rendered and the list has been scrolled + * to within onEndReachedThreshold of the bottom. The native scroll + * event is provided. + */ + onEndReached?: () => void + + /** + * Threshold in pixels for onEndReached. + */ + onEndReachedThreshold?: number + + /** + * Number of rows to render per event loop. + */ + pageSize?: number + + /** + * An experimental performance optimization for improving scroll perf of + * large lists, used in conjunction with overflow: 'hidden' on the row + * containers. Use at your own risk. + */ + removeClippedSubviews?: boolean + + /** + * () => renderable + * + * The header and footer are always rendered (if these props are provided) + * on every render pass. If they are expensive to re-render, wrap them + * in StaticContainer or other mechanism as appropriate. Footer is always + * at the bottom of the list, and header at the top, on every render pass. + */ + renderFooter?: () => React.ReactElement + + /** + * () => renderable + * + * The header and footer are always rendered (if these props are provided) + * on every render pass. If they are expensive to re-render, wrap them + * in StaticContainer or other mechanism as appropriate. Footer is always + * at the bottom of the list, and header at the top, on every render pass. + */ + renderHeader?: () => React.ReactElement + + /** + * (rowData, sectionID, rowID) => renderable + * Takes a data entry from the data source and its ids and should return + * a renderable component to be rendered as the row. By default the data + * is exactly what was put into the data source, but it's also possible to + * provide custom extractors. + */ + renderRow?: ( rowData: any, sectionID: string, rowID: string, highlightRow?: boolean ) => React.ReactElement + + + /** + * A function that returns the scrollable component in which the list rows are rendered. + * Defaults to returning a ScrollView with the given props. + */ + renderScrollComponent?: ( props: ScrollViewProperties ) => React.ReactElement + + /** + * (sectionData, sectionID) => renderable + * + * If provided, a sticky header is rendered for this section. The sticky + * behavior means that it will scroll with the content at the top of the + * section until it reaches the top of the screen, at which point it will + * stick to the top until it is pushed off the screen by the next section + * header. + */ + renderSectionHeader?: ( sectionData: any, sectionId: string ) => React.ReactElement + + + /** + * (sectionID, rowID, adjacentRowHighlighted) => renderable + * If provided, a renderable component to be rendered as the separator below each row + * but not the last row if there is a section header below. + * Take a sectionID and rowID of the row above and whether its adjacent row is highlighted. + */ + renderSeparator?: ( sectionID: string, rowID: string, adjacentRowHighlighted?: boolean ) => React.ReactElement + + /** + * How early to start rendering rows before they come on screen, in + * pixels. + */ + scrollRenderAheadDistance?: number + } + + export interface ListViewStatic extends React.ComponentClass { + DataSource: ListViewDataSource; + } + + + /** + * @see https://facebook.github.io/react-native/docs/touchablewithoutfeedback.html + */ + export interface TouchableWithoutFeedbackProperties { + /* + accessible bool + + Called when the touch is released, but not if cancelled (e.g. by a scroll that steals the responder lock). + */ + accessible?: boolean; + /* + delayLongPress number + + Delay in ms, from onPressIn, before onLongPress is called. + */ + delayLongPress?: number; + + /* + delayPressIn number + + Delay in ms, from the start of the touch, before onPressIn is called. + */ + delayPressIn?: number; + + /* + delayPressOut number + + Delay in ms, from the release of the touch, before onPressOut is called. + */ + delayPressOut?: number; + + /* + onLongPress function + */ + onLongPress?: () => void; + + /* + onPress function + */ + onPress?: () => void; + + /* + onPressIn function + */ + onPressIn?: () => void; + + /* + onPressOut function + */ + onPressOut?: () => void; + } + + + export interface TouchableWithoutFeedbackProps extends TouchableWithoutFeedbackProperties, React.Props { + + } + + export interface TouchableWithoutFeedbackStatic extends React.ComponentClass { + + } + + + /** + * @see https://facebook.github.io/react-native/docs/touchablehighlight.html#props + */ + export interface TouchableHighlightProperties extends TouchableWithoutFeedbackProperties, React.Props { + /** + * activeOpacity number + * + * Determines what the opacity of the wrapped view should be when touch is active. + */ + activeOpacity?: number + + /** + * onHideUnderlay function + * + * Called immediately after the underlay is hidden + */ + + onHideUnderlay?: () => void + + + /** + * onShowUnderlay function + * + * Called immediately after the underlay is shown + */ + onShowUnderlay?: () => void + + /** + * @see https://facebook.github.io/react-native/docs/view.html#style + */ + style?: ViewStyle + + + /** + * underlayColor string + * + * The color of the underlay that will show through when the touch is active. + */ + underlayColor?: string + + } + + export interface TouchableHighlightStatic extends React.ComponentClass { + } + + + /** + * @see https://facebook.github.io/react-native/docs/touchableopacity.html#props + */ + export interface TouchableOpacityProperties extends TouchableWithoutFeedbackProperties, React.Props { + /** + * activeOpacity number + * + * Determines what the opacity of the wrapped view should be when touch is active. + */ + activeOpacity?: number; + } + + export interface TouchableOpacityStatic extends React.ComponentClass { + } + + + export interface LeftToRightGesture { + + } + + export interface AnimationInterpolator { + + } + + // see /NavigatorSceneConfigs.js + export interface SceneConfig { + // A list of all gestures that are enabled on this scene + gestures: { + pop: LeftToRightGesture, }, - getInitialState: () => { - return { - inputValue: this.context.someValue, - seconds: this.props.foo - }; - }, - // NOTE https://github.com/borisyankov/DefinitelyTyped/pull/5590 - // reset: () => { - // this.replaceState(this.getInitialState()); - // }, - render: () => { - return React.DOM.div(null, - React.DOM.input({ - ref: input => this._input = input, - value: this.state.inputValue - })); + + // Rebound spring parameters when transitioning FROM this scene + springFriction: number; + springTension: number; + + // Velocity to start at when transitioning without gesture + defaultTransitionVelocity: number; + + // Animation interpolators for horizontal transitioning: + animationInterpolators: { + into: AnimationInterpolator, + out: AnimationInterpolator + }; + + } + + // see /NavigatorSceneConfigs.js + export interface SceneConfigs { + FloatFromBottom: SceneConfig; + FloatFromRight: SceneConfig; + PushFromRight: SceneConfig; + FloatFromLeft: SceneConfig; + HorizontalSwipeJump: SceneConfig; + } + + export interface Route { + component?: ComponentClass + id?: string + title?: string + passProps?: Object; + + //anything else + [key: string]: any + + //Commonly found properties + backButtonTitle?: string + content?: string + message?: string; + index?: number + onRightButtonPress?: () => void + rightButtonTitle?: string + sceneConfig?: SceneConfig + wrapperStyle?: any + } + + + /** + * @see https://facebook.github.io/react-native/docs/navigator.html#content + */ + export interface NavigatorProperties extends React.Props { + /** + * Optional function that allows configuration about scene animations and gestures. + * Will be invoked with the route and should return a scene configuration object + * @param route + */ + configureScene?: ( route: Route ) => SceneConfig + /** + * Specify a route to start on. + * A route is an object that the navigator will use to identify each scene to render. + * initialRoute must be a route in the initialRouteStack if both props are provided. + * The initialRoute will default to the last item in the initialRouteStack. + */ + initialRoute?: Route + /** + * Provide a set of routes to initially mount. + * Required if no initialRoute is provided. + * Otherwise, it will default to an array containing only the initialRoute + */ + initialRouteStack?: Route[] + + /** + * Optionally provide a navigation bar that persists across scene transitions + */ + navigationBar?: React.ReactElement + + /** + * Optionally provide the navigator object from a parent Navigator + */ + navigator?: Navigator + + /** + * @deprecated Use navigationContext.addListener('willfocus', callback) instead. + */ + onDidFocus?: Function + + /** + * @deprecated Use navigationContext.addListener('willfocus', callback) instead. + */ + onWillFocus?: Function + + /** + * Required function which renders the scene for a given route. + * Will be invoked with the route and the navigator object + * @param route + * @param navigator + */ + renderScene?: ( route: Route, navigator: Navigator ) => React.ReactElement + + /** + * Styles to apply to the container of each scene + */ + sceneStyle?: ViewStyle + + /** + * //FIXME: not found in doc but found in examples + */ + debugOverlay?: boolean + + } + + /** + * Use Navigator to transition between different scenes in your app. + * To accomplish this, provide route objects to the navigator to identify each scene, + * and also a renderScene function that the navigator can use to render the scene for a given route. + * + * To change the animation or gesture properties of the scene, provide a configureScene prop to get the config object for a given route. + * See Navigator.SceneConfigs for default animations and more info on scene config options. + * @see https://facebook.github.io/react-native/docs/navigator.html + */ + export interface NavigatorStatic extends React.ComponentClass { + SceneConfigs: SceneConfigs; + NavigationBar: NavigatorStatic.NavigationBarStatic; + BreadcrumbNavigationBar: NavigatorStatic.BreadcrumbNavigationBarStatic + + getContext( self: any ): NavigatorStatic; + + /** + * returns the current list of routes + */ + getCurrentRoutes(): Route[]; + + /** + * Jump backward without unmounting the current scen + */ + jumpBack(): void; + + /** + * Jump forward to the next scene in the route stack + */ + jumpForward(): void; + + /** + * Transition to an existing scene without unmounting + */ + jumpTo( route: Route ): void; + + /** + * Navigate forward to a new scene, squashing any scenes that you could jumpForward to + */ + push( route: Route ): void; + + /** + * Transition back and unmount the current scene + */ + pop(): void; + + /** + * Replace the current scene with a new route + */ + replace( route: Route ): void; + + /** + * Replace a scene as specified by an index + */ + replaceAtIndex( route: Route, index: number ): void; + + /** + * Replace the previous scene + */ + replacePrevious( route: Route ): void; + + /** + * Reset every scene with an array of routes + */ + immediatelyResetRouteStack( routes: Route[] ): void; + + /** + * Pop to a particular scene, as specified by its route. All scenes after it will be unmounted + */ + popToRoute( route: Route ): void; + + /** + * Pop to the first scene in the stack, unmounting every other scene + */ + popToTop(): void; + + } + + namespace NavigatorStatic { + + + export interface NavState { + routeStack: Route[] + idStack: number[] + presentedIndex: number } - }); -class ModernComponent extends React.Component - implements React.ChildContextProvider { - - static propTypes: React.ValidationMap = { - foo: React.PropTypes.number - } - - static contextTypes: React.ValidationMap = { - someValue: React.PropTypes.string - } - - static childContextTypes: React.ValidationMap = { - someOtherValue: React.PropTypes.string - } - - static defaultProps: Props; - - context: Context; - - getChildContext() { - return { - someOtherValue: 'foo' + export interface NavigationBarStyle { + //TODO @see NavigationBarStyle.ios.js } + + + export interface NavigationBarRouteMapper { + Title: ( route: Route, nav: Navigator, index: number, navState: NavState ) => React.ReactElement; + LeftButton: ( route: Route, nav: Navigator, index: number, navState: NavState )=> React.ReactElement; + RightButton: ( route: Route, nav: Navigator, index: number, navState: NavState )=> React.ReactElement; + } + + /** + * @see NavigatorNavigationBar.js + */ + export interface NavigationBarProperties extends React.Props { + navigator?: Navigator + routeMapper?: NavigationBarRouteMapper + navState?: NavState + style?: ViewStyle + } + + export interface NavigationBarStatic extends React.ComponentClass { + Styles: NavigationBarStyle + + } + + export type NavigationBar = NavigationBarStatic + export var NavigationBar: NavigationBarStatic + + + export interface BreadcrumbNavigationBarStyle { + //TODO &see NavigatorBreadcrumbNavigationBar.js + } + + export interface BreadcrumbNavigationBarRouteMapper { + rightContentForRoute: ( route: Route, navigator: Navigator ) => React.ReactElement + titleContentForRoute: ( route: Route, navigator: Navigator ) => React.ReactElement + iconForRoute: ( route: Route, navigator: Navigator ) => React.ReactElement + //in samples... + separatorForRoute: ( route: Route, navigator: Navigator ) => React.ReactElement + } + + /** + * @see NavigatorNavigationBar.js + */ + export interface BreadcrumbNavigationBarProperties extends React.Props { + navigator?: Navigator + routeMapper?: BreadcrumbNavigationBarRouteMapper + navState?: NavState + style?: ViewStyle + } + + export interface BreadcrumbNavigationBarStatic extends React.ComponentClass { + Styles: BreadcrumbNavigationBarStyle + } + + export type BreadcrumbNavigationBar = BreadcrumbNavigationBarStatic + var BreadcrumbNavigationBar: BreadcrumbNavigationBarStatic + } - state = { - inputValue: this.context.someValue, - seconds: this.props.foo + + export interface StyleSheetStatic extends React.ComponentClass { + create( styles: T ): T; } - reset() { - this.setState({ - inputValue: this.context.someValue, - seconds: this.props.foo - }); + /** + * //FIXME: Could not find docs. Inferred from examples and jscode : ListViewDataSource.js + */ + export interface DataSourceAssetCallback { + rowHasChanged?: ( r1: any, r2: any ) => boolean + sectionHeaderHasChanged?: ( h1: any, h2: any ) => boolean + getRowData?: ( dataBlob: any, sectionID: number | string, rowID: number | string ) => T + getSectionHeaderData?: ( dataBlob: any, sectionID: number | string ) => T } - private _input: React.HTMLComponent; + /** + * //FIXME: Could not find docs. Inferred from examples and js code: ListViewDataSource.js + */ + export interface ListViewDataSource { + new( onAsset: DataSourceAssetCallback ): ListViewDataSource; + /** + * Clones this `ListViewDataSource` with the specified `dataBlob` and + * `rowIdentities`. The `dataBlob` is just an aribitrary blob of data. At + * construction an extractor to get the interesting informatoin was defined + * (or the default was used). + * + * The `rowIdentities` is is a 2D array of identifiers for rows. + * ie. [['a1', 'a2'], ['b1', 'b2', 'b3'], ...]. If not provided, it's + * assumed that the keys of the section data are the row identities. + * + * Note: This function does NOT clone the data in this data source. It simply + * passes the functions defined at construction to a new data source with + * the data specified. If you wish to maintain the existing data you must + * handle merging of old and new data separately and then pass that into + * this function as the `dataBlob`. + */ + cloneWithRows( dataBlob: Array | {[key: string]: any}, rowIdentities?: Array ): ListViewDataSource - render() { - return React.DOM.div(null, - React.DOM.input({ - ref: input => this._input = input, - value: this.state.inputValue - })); + /** + * This performs the same function as the `cloneWithRows` function but here + * you also specify what your `sectionIdentities` are. If you don't care + * about sections you should safely be able to use `cloneWithRows`. + * + * `sectionIdentities` is an array of identifiers for sections. + * ie. ['s1', 's2', ...]. If not provided, it's assumed that the + * keys of dataBlob are the section identities. + * + * Note: this returns a new object! + */ + cloneWithRowsAndSections( dataBlob: Array | {[key: string]: any}, sectionIdentities?: Array, rowIdentities?: Array> ): ListViewDataSource + + getRowCount(): number + + /** + * Gets the data required to render the row. + */ + getRowData( sectionIndex: number, rowIndex: number ): any + + /** + * Gets the rowID at index provided if the dataSource arrays were flattened, + * or null of out of range indexes. + */ + getRowIDForFlatIndex( index: number ): string + + /** + * Gets the sectionID at index provided if the dataSource arrays were flattened, + * or null for out of range indexes. + */ + getSectionIDForFlatIndex( index: number ): string + + /** + * Returns an array containing the number of rows in each section + */ + getSectionLengths(): Array + + /** + * Returns if the section header is dirtied and needs to be rerendered + */ + sectionHeaderShouldUpdate( sectionIndex: number ): boolean + + /** + * Gets the data required to render the section header + */ + getSectionHeaderData( sectionIndex: number ): any } + + + export interface ImageStatic extends React.ComponentClass { + uri: string; + } + + /** + * @see + */ + export interface TabBarItemProperties { + + } + + export interface TabBarItem extends React.ComponentClass { + } + + /** + * @see + */ + export interface TabBarIOSProperties { + } + + export interface TabBarIOSStatic extends React.ComponentClass { + Item: TabBarItem; + } + + export interface CameraRollFetchParams { + first: number; + groupTypes: string; + after?: string; + } + + export interface CameraRollNodeInfo { + image: Image; + group_name: string; + timestamp: number; + location: any; + } + + export interface CameraRollEdgeInfo { + node: CameraRollNodeInfo; + } + + export interface CameraRollAssetInfo { + edges: CameraRollEdgeInfo[]; + page_info: { + has_next_page: boolean; + end_cursor: string; + }; + } + + export interface CameraRollStatic extends React.ComponentClass { + getPhotos( fetch: CameraRollFetchParams, + onAsset: ( assetInfo: CameraRollAssetInfo ) => void, + logError: ()=> void ): void; + } + + export interface PanHandlers { + + } + + export interface PanResponderEvent { + + } + + export interface PanResponderGestureState { + stateID: number; + moveX: number; + moveY: number; + x0: number; + y0: number; + dx: number; + dy: number; + vx: number; + vy: number; + numberActiveTouches: number; + // All `gestureState` accounts for timeStamps up until: + _accountsForMovesUpTo: number; + } + + /** + * @param {object} config Enhanced versions of all of the responder callbacks + * that provide not only the typical `ResponderSyntheticEvent`, but also the + * `PanResponder` gesture state. Simply replace the word `Responder` with + * `PanResponder` in each of the typical `onResponder*` callbacks. For + * example, the `config` object would look like: + * + * - `onMoveShouldSetPanResponder: (e, gestureState) => {...}` + * - `onMoveShouldSetPanResponderCapture: (e, gestureState) => {...}` + * - `onStartShouldSetPanResponder: (e, gestureState) => {...}` + * - `onStartShouldSetPanResponderCapture: (e, gestureState) => {...}` + * - `onPanResponderReject: (e, gestureState) => {...}` + * - `onPanResponderGrant: (e, gestureState) => {...}` + * - `onPanResponderStart: (e, gestureState) => {...}` + * - `onPanResponderEnd: (e, gestureState) => {...}` + * - `onPanResponderRelease: (e, gestureState) => {...}` + * - `onPanResponderMove: (e, gestureState) => {...}` + * - `onPanResponderTerminate: (e, gestureState) => {...}` + * - `onPanResponderTerminationRequest: (e, gestureState) => {...}` + * + * In general, for events that have capture equivalents, we update the + * gestureState once in the capture phase and can use it in the bubble phase + * as well. + * + * Be careful with onStartShould* callbacks. They only reflect updated + * `gestureState` for start/end events that bubble/capture to the Node. + * Once the node is the responder, you can rely on every start/end event + * being processed by the gesture and `gestureState` being updated + * accordingly. (numberActiveTouches) may not be totally accurate unless you + * are the responder. + */ + export interface PanResponderCallbacks { + onMoveShouldSetPanResponder?: ( e: PanResponderEvent, gestureState: PanResponderGestureState ) => boolean; + onStartShouldSetPanResponder?: ( e: PanResponderEvent, gestureState: PanResponderGestureState ) => void; + onPanResponderGrant?: ( e: PanResponderEvent, gestureState: PanResponderGestureState ) => void; + onPanResponderMove?: ( e: PanResponderEvent, gestureState: PanResponderGestureState ) => void; + onPanResponderRelease?: ( e: PanResponderEvent, gestureState: PanResponderGestureState ) => void; + onPanResponderTerminate?: ( e: PanResponderEvent, gestureState: PanResponderGestureState ) => void; + + onMoveShouldSetPanResponderCapture?: ( e: PanResponderEvent, gestureState: PanResponderGestureState ) => boolean; + onStartShouldSetPanResponderCapture?: ( e: PanResponderEvent, gestureState: PanResponderGestureState ) => boolean; + onPanResponderReject?: ( e: PanResponderEvent, gestureState: PanResponderGestureState ) => void; + onPanResponderStart?: ( e: PanResponderEvent, gestureState: PanResponderGestureState ) => void; + onPanResponderEnd?: ( e: PanResponderEvent, gestureState: PanResponderGestureState ) => void; + onPanResponderTerminationRequest?: ( e: PanResponderEvent, gestureState: PanResponderGestureState ) => void; + } + + export interface PanResponderInstance { + panHandlers: PanHandlers; + } + + export interface PanResponderStatic { + create( callbacks: PanResponderCallbacks ): PanResponderInstance; + } + + export interface PixelRatioStatic { + get(): number; + } + + export interface DeviceEventSubscriptionStatic { + remove(): void; + } + + export interface DeviceEventEmitterStatic { + addListener( type: string, onReceived: ( data: T ) => void ): DeviceEventSubscription; + } + + // Used by Dimensions below + export interface ScaledSize { + width: number; + height: number; + scale: number; + } + + // @see https://facebook.github.io/react-native/docs/asyncstorage.html#content + export interface AsyncStorageStatic { + getItem( key: string, callback?: ( error?: Error, result?: string ) => void ): Promise; + setItem( key: string, value: string, callback?: ( error?: Error ) => void ): Promise; + removeItem( key: string, callback?: ( error?: Error ) => void ): Promise; + mergeItem( key: string, value: string, callback?: ( error?: Error ) => void ): Promise; + clear( callback?: ( error?: Error ) => void ): Promise; + getAllKeys( callback?: ( error?: Error, keys?: string[] ) => void ): Promise; + multiGet( keys: string[], callback?: ( errors?: Error[], result?: string[][] ) => void ): Promise; + multiSet( keyValuePairs: string[][], callback?: ( errors?: Error[] ) => void ): Promise; + multiRemove( keys: string[], callback?: ( errors?: Error[] ) => void ): Promise; + multiMerge( keyValuePairs: string[][], callback?: ( errors?: Error[] ) => void ): Promise; + } + + export interface InteractionManagerStatic { + runAfterInteractions( fn: () => void ): void; + } + + + export interface ScrollViewStyle extends FlexStyle, TransformsStyle { + + backfaceVisibility?:string //enum('visible', 'hidden') + backgroundColor?: string + borderColor?: string + borderTopColor?: string + borderRightColor?: string + borderBottomColor?: string + borderLeftColor?: string + borderRadius?: number + borderTopLeftRadius?: number + borderTopRightRadius?: number + borderBottomLeftRadius?: number + borderBottomRightRadius?: number + borderStyle?: string //enum('solid', 'dotted', 'dashed') + borderWidth?: number + borderTopWidth?: number + borderRightWidth?: number + borderBottomWidth?: number + borderLeftWidth?: number + opacity?: number + overflow?: string //enum('visible', 'hidden') + shadowColor?: string + shadowOffset?: {width: number; height: number} + shadowOpacity?: number + shadowRadius?: number + } + + export interface EdgeInsetsProperties { + top: number + left: number + bottom: number + right: number + } + + export interface PointProperties { + x: number + y: number + } + + export interface ScrollViewIOSProperties { + + /** + * When true the scroll view bounces horizontally when it reaches the end + * even if the content is smaller than the scroll view itself. The default + * value is true when `horizontal={true}` and false otherwise. + */ + alwaysBounceHorizontal?: boolean + /** + * When true the scroll view bounces vertically when it reaches the end + * even if the content is smaller than the scroll view itself. The default + * value is false when `horizontal={true}` and true otherwise. + */ + alwaysBounceVertical?: boolean + + /** + * Controls whether iOS should automatically adjust the content inset for scroll views that are placed behind a navigation bar or tab bar/ toolbar. + * The default value is true. + */ + automaticallyAdjustContentInsets?: boolean // true + + /** + * When true the scroll view bounces when it reaches the end of the + * content if the content is larger then the scroll view along the axis of + * the scroll direction. When false it disables all bouncing even if + * the `alwaysBounce*` props are true. The default value is true. + */ + bounces?: boolean + /** + * When true gestures can drive zoom past min/max and the zoom will animate + * to the min/max value at gesture end otherwise the zoom will not exceed + * the limits. + */ + bouncesZoom?: boolean + + /** + * When false once tracking starts won't try to drag if the touch moves. + * The default value is true. + */ + canCancelContentTouches?: boolean + + /** + * When true the scroll view automatically centers the content when the + * content is smaller than the scroll view bounds; when the content is + * larger than the scroll view this property has no effect. The default + * value is false. + */ + centerContent?: boolean + + + /** + * The amount by which the scroll view content is inset from the edges of the scroll view. + * Defaults to {0, 0, 0, 0}. + */ + contentInset?: EdgeInsetsProperties // zeros + + /** + * Used to manually set the starting scroll offset. + * The default value is {x: 0, y: 0} + */ + contentOffset?: PointProperties // zeros + + /** + * A floating-point number that determines how quickly the scroll view + * decelerates after the user lifts their finger. Reasonable choices include + * - Normal: 0.998 (the default) + * - Fast: 0.9 + */ + decelerationRate?: number + + /** + * When true the ScrollView will try to lock to only vertical or horizontal + * scrolling while dragging. The default value is false. + */ + directionalLockEnabled?: boolean + + /** + * The maximum allowed zoom scale. The default value is 1.0. + */ + maximumZoomScale?: number + + /** + * The minimum allowed zoom scale. The default value is 1.0. + */ + minimumZoomScale?: number + + /** + * Called when a scrolling animation ends. + */ + onScrollAnimationEnd?: () => void + + /** + * When true the scroll view stops on multiples of the scroll view's size + * when scrolling. This can be used for horizontal pagination. The default + * value is false. + */ + pagingEnabled?: boolean + + /** + * When false, the content does not scroll. The default value is true + */ + scrollEnabled?: boolean // true + + /** + * This controls how often the scroll event will be fired while scrolling (in events per seconds). + * A higher number yields better accuracy for code that is tracking the scroll position, + * but can lead to scroll performance problems due to the volume of information being send over the bridge. + * The default value is zero, which means the scroll event will be sent only once each time the view is scrolled. + */ + scrollEventThrottle?: number // null + + /** + * The amount by which the scroll view indicators are inset from the edges of the scroll view. + * This should normally be set to the same value as the contentInset. + * Defaults to {0, 0, 0, 0}. + */ + scrollIndicatorInsets?: EdgeInsetsProperties //zeroes + + /** + * When true the scroll view scrolls to top when the status bar is tapped. + * The default value is true. + */ + scrollsToTop?: boolean + + /** + * When snapToInterval is set, snapToAlignment will define the relationship of the the snapping to the scroll view. + * - start (the default) will align the snap at the left (horizontal) or top (vertical) + * - center will align the snap in the center + * - end will align the snap at the right (horizontal) or bottom (vertical) + */ + snapToAlignment?: string + + /** + * When set, causes the scroll view to stop at multiples of the value of snapToInterval. + * This can be used for paginating through children that have lengths smaller than the scroll view. + * Used in combination with snapToAlignment. + */ + snapToInterval?: number + + /** + * An array of child indices determining which children get docked to the + * top of the screen when scrolling. For example passing + * `stickyHeaderIndices={[0]}` will cause the first child to be fixed to the + * top of the scroll view. This property is not supported in conjunction + * with `horizontal={true}`. + */ + stickyHeaderIndices?: number[] + + /** + * The current scale of the scroll view content. The default value is 1.0. + */ + zoomScale?: number + } + + export interface ScrollViewProperties extends ScrollViewIOSProperties { + + /** + * These styles will be applied to the scroll view content container which + * wraps all of the child views. Example: + * + * return ( + * + * + * ); + * ... + * var styles = StyleSheet.create({ + * contentContainer: { + * paddingVertical: 20 + * } + * }); + */ + contentContainerStyle?: ViewStyle + + /** + * When true the scroll view's children are arranged horizontally in a row + * instead of vertically in a column. The default value is false. + */ + horizontal?: boolean + + /** + * Determines whether the keyboard gets dismissed in response to a drag. + * - 'none' (the default) drags do not dismiss the keyboard. + * - 'onDrag' the keyboard is dismissed when a drag begins. + * - 'interactive' the keyboard is dismissed interactively with the drag + * and moves in synchrony with the touch; dragging upwards cancels the + * dismissal. + */ + keyboardDismissMode?: string + + /** + * When false tapping outside of the focused text input when the keyboard + * is up dismisses the keyboard. When true the scroll view will not catch + * taps and the keyboard will not dismiss automatically. The default value + * is false. + */ + keyboardShouldPersistTaps?: boolean + + /** + * Fires at most once per frame during scrolling. + * The frequency of the events can be contolled using the scrollEventThrottle prop. + */ + onScroll?: () => void + + /** + * Experimental: When true offscreen child views (whose `overflow` value is + * `hidden`) are removed from their native backing superview when offscreen. + * This canimprove scrolling performance on long lists. The default value is + * false. + */ + removeClippedSubviews?: boolean + + /** + * When true, shows a horizontal scroll indicator. + */ + showsHorizontalScrollIndicator?: boolean + + /** + * When true, shows a vertical scroll indicator. + */ + showsVerticalScrollIndicator?: boolean + + /** + * Style + */ + style?: ScrollViewStyle + } + + export interface ScrollViewProps extends ScrollViewProperties, React.Props { + + } + + interface ScrollViewStatic extends React.ComponentClass { + + } + + + export interface NativeScrollRectangle { + left: number; + top: number; + bottom: number; + right: number; + } + + export interface NativeScrollPoint { + x: number; + y: number; + } + + export interface NativeScrollSize { + height: number; + width: number; + } + + export interface NativeScrollEvent { + contentInset: NativeScrollRectangle; + contentOffset: NativeScrollPoint; + contentSize: NativeScrollSize; + layoutMeasurement: NativeScrollSize; + zoomScale: number; + } + + export interface AppStateIOSStatic { + currentState: string; + addEventListener( type: string, listener: ( state: string ) => void ): void; + removeEventListener( type: string, listener: ( state: string ) => void ): void; + } + + // exported singletons: + // export var AppRegistry: AppRegistryStatic; + + + export var ActivityIndicatorIOS: ActivityIndicatorIOSStatic; + export type ActivityIndicatorIOS = ActivityIndicatorIOSStatic; + + export var AsyncStorage: AsyncStorageStatic; + export type AsyncStorage = AsyncStorageStatic; + + export var CameraRoll: CameraRollStatic; + export type CameraRoll = CameraRollStatic; + + export var DatePickerIOS: DatePickerIOSStatic + export type DatePickerIOS = DatePickerIOSStatic + + export var Image: ImageStatic; + export type Image = ImageStatic; + + export var ListView: ListViewStatic; + export type ListView = ListViewStatic; + + export var Navigator: NavigatorStatic; + export type Navigator = NavigatorStatic; + + export var NavigatorIOS: NavigatorIOSStatic; + export type NavigatorIOS = NavigatorIOSStatic; + + export var SliderIOS: SliderIOSStatic; + export type SliderIOS = SliderIOSStatic; + + export var ScrollView: ScrollViewStatic + export type ScrollView = ScrollViewStatic + + export var StyleSheet: StyleSheetStatic; + export type StyleSheet = StyleSheetStatic; + + export var TabBarIOS: TabBarIOSStatic; + export type TabBarIOS = TabBarIOSStatic; + + export var Text: TextStatic; + export type Text = TextStatic; + + export var TextInput: TextInputStatic + export type TextInput = TextInputStatic + + export var TouchableHighlight: TouchableHighlightStatic; + export type TouchableHighlight = TouchableHighlightStatic; + + export var TouchableOpacity: TouchableOpacityStatic; + export type TouchableOpacity = TouchableOpacityStatic; + + export var TouchableWithoutFeedback: TouchableWithoutFeedbackStatic; + export type TouchableWithoutFeedback= TouchableWithoutFeedbackStatic; + + export var View: ViewStatic; + export type View = ViewStatic; + + export var AlertIOS: React.ComponentClass; + export var SegmentedControlIOS: React.ComponentClass; + export var SwitchIOS: React.ComponentClass; + + export var PixelRatio: PixelRatioStatic; + export var DeviceEventEmitter: DeviceEventEmitterStatic; + export var DeviceEventSubscription: DeviceEventSubscriptionStatic; + export type DeviceEventSubscription = DeviceEventSubscriptionStatic; + export var InteractionManager: InteractionManagerStatic; + export var PanResponder: PanResponderStatic; + export var AppStateIOS: AppStateIOSStatic; + + + //react re-exported + export type ReactType = React.ReactType; + + export interface ReactElement

extends React.ReactElement

{} + + export interface ClassicElement

extends React.ClassicElement

{} + + export interface DOMElement

extends React.DOMElement

{} + + export type HTMLElement =React.HTMLElement; + export type SVGElement = React.SVGElement; + + // + // Factories + // ---------------------------------------------------------------------- + + export interface Factory

extends React.Factory

{} + + export interface ClassicFactory

extends React.ClassicFactory

{} + + export interface DOMFactory

extends React.DOMFactory

{} + + export type HTMLFactory = React.HTMLFactory; + export type SVGFactory = React.SVGFactory; + export type SVGElementFactory = React.SVGElementFactory; + + // + // React Nodes + // http://facebook.github.io/react/docs/glossary.html + // ---------------------------------------------------------------------- + + export type ReactText = React.ReactText; + export type ReactChild = React.ReactChild; + + // Should be Array but type aliases cannot be recursive + export type ReactFragment = React.ReactFragment; + export type ReactNode = React.ReactNode; + + // + // Top Level API + // ---------------------------------------------------------------------- + + export function createClass( spec: React.ComponentSpec ): React.ClassicComponentClass

; + + export function createFactory

( type: string ): React.DOMFactory

; + export function createFactory

( type: React.ClassicComponentClass

| string ): React.ClassicFactory

; + export function createFactory

( type: React.ComponentClass

): React.Factory

; + + export function createElement

( type: string, + props?: P, + ...children: React.ReactNode[] ): React.DOMElement

; + export function createElement

( type: React.ClassicComponentClass

| string, + props?: P, + ...children: React.ReactNode[] ): React.ClassicElement

; + export function createElement

( type: React.ComponentClass

, + props?: P, + ...children: React.ReactNode[] ): React.ReactElement

; + + export function cloneElement

( element: React.DOMElement

, + props?: P, + ...children: React.ReactNode[] ): React.DOMElement

; + export function cloneElement

( element: React.ClassicElement

, + props?: P, + ...children: React.ReactNode[] ): React.ClassicElement

; + export function cloneElement

( element: React.ReactElement

, + props?: P, + ...children: React.ReactNode[] ): React.ReactElement

; + + export function isValidElement( object: {} ): boolean; + + export var DOM: React.ReactDOM; + export var PropTypes: React.ReactPropTypes; + export var Children: React.ReactChildren; + + // + // Component API + // ---------------------------------------------------------------------- + + // Base component for plain JS classes + export class Component extends React.Component {} + + export interface ClassicComponent extends React.ClassicComponent {} + + export interface DOMComponent

extends ClassicComponent { + tagName: string; + } + + export type HTMLComponent = React.HTMLComponent; + export type SVGComponent = React.SVGComponent + + export interface ChildContextProvider extends React.ChildContextProvider {} + + // + // Class Interfaces + // ---------------------------------------------------------------------- + + export interface ComponentClass

extends React.ComponentClass

{} + + export interface ClassicComponentClass

extends React.ClassicComponentClass

{} + + // + // Component Specs and Lifecycle + // ---------------------------------------------------------------------- + + export interface ComponentLifecycle extends React.ComponentLifecycle {} + + export interface Mixin extends React.Mixin {} + + export interface ComponentSpec extends React.ComponentSpec {} + + // + // Event System + // ---------------------------------------------------------------------- + + export interface SyntheticEvent extends React.SyntheticEvent {} + + export interface DragEvent extends React.DragEvent {} + + export interface ClipboardEvent extends React.ClipboardEvent {} + + export interface KeyboardEvent extends React.KeyboardEvent {} + + + export interface FocusEvent extends React.FocusEvent {} + + export interface FormEvent extends React.FormEvent {} + + export interface MouseEvent extends React.MouseEvent {} + + export interface TouchEvent extends React.TouchEvent {} + + export interface UIEvent extends React.UIEvent {} + + export interface WheelEvent extends React.WheelEvent {} + + // + // Event Handler Types + // ---------------------------------------------------------------------- + + export interface EventHandler extends React.EventHandler {} + + export interface DragEventHandler extends React.DragEventHandler {} + export interface ClipboardEventHandler extends React.ClipboardEventHandler {} + export interface KeyboardEventHandler extends React.KeyboardEventHandler {} + export interface FocusEventHandler extends React.FocusEventHandler {} + export interface FormEventHandler extends React.FormEventHandler {} + export interface MouseEventHandler extends React.MouseEventHandler {} + export interface TouchEventHandler extends React.TouchEventHandler {} + export interface UIEventHandler extends React.UIEventHandler {} + export interface WheelEventHandler extends React.WheelEventHandler {} + + // + // Props / DOM Attributes + // ---------------------------------------------------------------------- + + export interface Props extends React.Props {} + + export interface DOMAttributesBase extends React.DOMAttributesBase {} + + export interface DOMAttributes extends React.DOMAttributes {} + + // This interface is not complete. Only properties accepting + // unitless numbers are listed here (see CSSProperty.js in React) + export interface CSSProperties extends React.CSSProperties {} + + export interface HTMLAttributesBase extends React.HTMLAttributesBase {} + + export interface HTMLAttributes extends React.HTMLAttributes {} + + export interface SVGElementAttributes extends React.SVGElementAttributes {} + + export interface SVGAttributes extends React.SVGAttributes {} + + // + // React.DOM + // ---------------------------------------------------------------------- + + export interface ReactDOM extends React.ReactDOM {} + + // + // React.PropTypes + // ---------------------------------------------------------------------- + + export interface Validator extends React.Validator {} + + export interface Requireable extends React.Requireable {} + + export interface ValidationMap extends React.ValidationMap {} + + export interface ReactPropTypes extends React.ReactPropTypes {} + + // + // React.Children + // ---------------------------------------------------------------------- + + export interface ReactChildren extends React.ReactChildren {} + + // + // Browser Interfaces + // https://github.com/nikeee/2048-typescript/blob/master/2048/js/touch.d.ts + // ---------------------------------------------------------------------- + + export interface AbstractView extends React.AbstractView {} + + export interface Touch extends React.Touch {} + + export interface TouchList extends React.TouchList {} + + // + // Additional ( and controversial) + // + + export function __spread( target: any, ...sources: any[] ): any; + + + export interface GlobalStatic { + + /** + * Accepts a function as its only argument and calls that function before the next repaint. + * It is an essential building block for animations that underlies all of the JavaScript-based animation APIs. + * In general, you shouldn't need to call this yourself - the animation API's will manage frame updates for you. + * @see https://facebook.github.io/react-native/docs/animations.html#requestanimationframe + */ + requestAnimationFrame( fn: () => void ) : void; + + } + + // + // Add-Ons + // + namespace addons { + + //FIXME: Documentation ? + export interface TestModuleStatic { + + verifySnapshot: (done: (indicator?: any) => void) => void + markTestPassed: (indicator: any) => void + markTestCompleted: () => void + } + + export var TestModule: TestModuleStatic + export type TestModule = TestModuleStatic + } + + } -// React.createFactory -var factory: React.Factory = - React.createFactory(ModernComponent); -var factoryElement: React.ReactElement = - factory(props); +declare module "react-native" { -var classicFactory: React.ClassicFactory = - React.createFactory(ClassicComponent); -var classicFactoryElement: React.ClassicElement = - classicFactory(props); - -var domFactory: React.DOMFactory = - React.createFactory("foo"); -var domFactoryElement: React.DOMElement = - domFactory(); - -// React.createElement -var element: React.ReactElement = - React.createElement(ModernComponent, props); -var classicElement: React.ClassicElement = - React.createElement(ClassicComponent, props); -var domElement: React.HTMLElement = - React.createElement("div"); - -// React.cloneElement -var clonedElement: React.ReactElement = - React.cloneElement(element, props); -var clonedClassicElement: React.ClassicElement = - React.cloneElement(classicElement, props); -var clonedDOMElement: React.HTMLElement = - React.cloneElement(domElement); - -// React.render -var component: React.Component = - React.render(element, container); -var classicComponent: React.ClassicComponent = - React.render(classicElement, container); -var domComponent: React.DOMComponent = - React.render(domElement, container); - -// Other Top-Level API -var unmounted: boolean = React.unmountComponentAtNode(container); -var str: string = React.renderToString(element); -var markup: string = React.renderToStaticMarkup(element); -var notValid: boolean = React.isValidElement(props); // false -var isValid = React.isValidElement(element); // true -React.initializeTouchEvents(true); -var domNode: Element = React.findDOMNode(component); -domNode = React.findDOMNode(domNode); - -// -// React Elements -// -------------------------------------------------------------------------- - -var type = element.type; -var elementProps: Props = element.props; -var key = element.key; - -// -// React Components -// -------------------------------------------------------------------------- - -var displayName: string = ClassicComponent.displayName; -var defaultProps: Props = ClassicComponent.getDefaultProps(); -var propTypes: React.ValidationMap = ClassicComponent.propTypes; - -// -// Component API -// -------------------------------------------------------------------------- - -// modern -var componentState: State = component.state; -component.setState({ inputValue: "!!!" }); -component.forceUpdate(); - -// classic -var htmlElement: Element = classicComponent.getDOMNode(); -var divElement: HTMLDivElement = classicComponent.getDOMNode(); -var isMounted: boolean = classicComponent.isMounted(); -classicComponent.setProps(elementProps); -classicComponent.replaceProps(props); -classicComponent.replaceState({ inputValue: "???", seconds: 60 }); - -var myComponent = component; -myComponent.reset(); - -// -// Attributes -// -------------------------------------------------------------------------- - -var children: any[] = ["Hello world", [null], React.DOM.span(null)]; -var divStyle: React.CSSProperties = { // CSSProperties - flex: "1 1 main-size", - backgroundImage: "url('hello.png')" -}; -var htmlAttr: React.HTMLAttributes = { - key: 36, - ref: "htmlComponent", - children: children, - className: "test-attr", - style: divStyle, - onClick: (event: React.MouseEvent) => { - event.preventDefault(); - event.stopPropagation(); - }, - dangerouslySetInnerHTML: { - __html: "STRONG" - } -}; -React.DOM.div(htmlAttr); -React.DOM.span(htmlAttr); -React.DOM.input(htmlAttr); - -React.DOM.svg({ viewBox: "0 0 48 48" }, - React.DOM.rect({ - x: 22, - y: 10, - width: 4, - height: 28 - }), - React.DOM.rect({ - x: 10, - y: 22, - width: 28, - height: 4 - })); - -// -// React.PropTypes -// -------------------------------------------------------------------------- - -var PropTypesSpecification: React.ComponentSpec = { - propTypes: { - optionalArray: React.PropTypes.array, - optionalBool: React.PropTypes.bool, - optionalFunc: React.PropTypes.func, - optionalNumber: React.PropTypes.number, - optionalObject: React.PropTypes.object, - optionalString: React.PropTypes.string, - optionalNode: React.PropTypes.node, - optionalElement: React.PropTypes.element, - optionalMessage: React.PropTypes.instanceOf(Date), - optionalEnum: React.PropTypes.oneOf(["News", "Photos"]), - optionalUnion: React.PropTypes.oneOfType([ - React.PropTypes.string, - React.PropTypes.number, - React.PropTypes.instanceOf(Date) - ]), - optionalArrayOf: React.PropTypes.arrayOf(React.PropTypes.number), - optionalObjectOf: React.PropTypes.objectOf(React.PropTypes.number), - optionalObjectWithShape: React.PropTypes.shape({ - color: React.PropTypes.string, - fontSize: React.PropTypes.number - }), - requiredFunc: React.PropTypes.func.isRequired, - requiredAny: React.PropTypes.any.isRequired, - customProp: function(props: any, propName: string, componentName: string) { - if (!/matchme/.test(props[propName])) { - return new Error("Validation failed!"); - } - return null; - } - }, - render: (): React.ReactElement => { - return null; - } -}; - -// -// ContextTypes -// -------------------------------------------------------------------------- - -var ContextTypesSpecification: React.ComponentSpec = { - contextTypes: { - optionalArray: React.PropTypes.array, - optionalBool: React.PropTypes.bool, - optionalFunc: React.PropTypes.func, - optionalNumber: React.PropTypes.number, - optionalObject: React.PropTypes.object, - optionalString: React.PropTypes.string, - optionalNode: React.PropTypes.node, - optionalElement: React.PropTypes.element, - optionalMessage: React.PropTypes.instanceOf(Date), - optionalEnum: React.PropTypes.oneOf(["News", "Photos"]), - optionalUnion: React.PropTypes.oneOfType([ - React.PropTypes.string, - React.PropTypes.number, - React.PropTypes.instanceOf(Date) - ]), - optionalArrayOf: React.PropTypes.arrayOf(React.PropTypes.number), - optionalObjectOf: React.PropTypes.objectOf(React.PropTypes.number), - optionalObjectWithShape: React.PropTypes.shape({ - color: React.PropTypes.string, - fontSize: React.PropTypes.number - }), - requiredFunc: React.PropTypes.func.isRequired, - requiredAny: React.PropTypes.any.isRequired, - customProp: function(props: any, propName: string, componentName: string) { - if (!/matchme/.test(props[propName])) { - return new Error("Validation failed!"); - } - return null; - } - }, - render: (): React.ReactElement => { - return null; - } -}; - -// -// React.Children -// -------------------------------------------------------------------------- - -var childMap: { [key: string]: number } = - React.Children.map(children, (child) => { return 42; }); -React.Children.forEach(children, (child) => {}); -var nChildren: number = React.Children.count(children); -var onlyChild = React.Children.only([null, [[["Hallo"], true]], false]); - -// -// Example from http://facebook.github.io/react/ -// -------------------------------------------------------------------------- - -interface TimerState { - secondsElapsed: number; + export default ReactNative } -class Timer extends React.Component, TimerState> { - state = { - secondsElapsed: 0 - } - private _interval: number; - tick() { - this.setState((prevState, props) => ({ - secondsElapsed: prevState.secondsElapsed + 1 - })); - } - componentDidMount() { - this._interval = setInterval(() => this.tick(), 1000); - } - componentWillUnmount() { - clearInterval(this._interval); - } - render() { - return React.DOM.div( - null, - "Seconds Elapsed: ", - this.state.secondsElapsed - ); + + +declare module "Dimensions" { + import React from 'react-native'; + + interface Dimensions { + get( what: string ): React.ScaledSize; } + + var ExportDimensions: Dimensions; + export = ExportDimensions; } -React.render(React.createElement(Timer), container); -// -// React.addons -// -------------------------------------------------------------------------- +declare var global: ReactNative.GlobalStatic -var cx = React.addons.classSet; -var className: string = cx({ a: true, b: false, c: true }); -className = cx("a", null, "b"); - -React.addons.createFragment({ - a: React.DOM.div(), - b: ["a", false, React.createElement("span")] -}); - -// -// React.addons (Transitions) -// -------------------------------------------------------------------------- - -React.createFactory(React.addons.TransitionGroup)({ component: "div" }); -React.createFactory(React.addons.CSSTransitionGroup)({ - component: React.createClass({ - render: (): React.ReactElement => null - }), - childFactory: (c) => c, - transitionName: "transition", - transitionAppear: false, - transitionEnter: true, - transitionLeave: true -}); - -// -// React.addons.TestUtils -// -------------------------------------------------------------------------- - -var node: Element; -TestUtils.Simulate.click(node); -TestUtils.Simulate.change(node); -TestUtils.Simulate.keyDown(node, { key: "Enter" }); - -var renderer: React.ShallowRenderer = - TestUtils.createRenderer(); -renderer.render(React.createElement(Timer)); -var output: React.ReactElement> = - renderer.getRenderOutput(); +declare function require( name: string ): any From c8ad4f59ef31ee057841988c3985128fddf952a2 Mon Sep 17 00:00:00 2001 From: bgrieder Date: Wed, 11 Nov 2015 10:34:31 +0100 Subject: [PATCH 15/15] Image fixes & add ImageResize --- react-native/react-native.d.ts | 241 +++++++++++++++++++++++---------- 1 file changed, 168 insertions(+), 73 deletions(-) diff --git a/react-native/react-native.d.ts b/react-native/react-native.d.ts index 10cfb50c5..485fdf5c0 100644 --- a/react-native/react-native.d.ts +++ b/react-native/react-native.d.ts @@ -436,7 +436,7 @@ declare namespace ReactNative { /** * Callback that is called when the text input's text changes. */ - onChange?: () => void + onChange?: (event: {nativeEvent: {text: string}}) => void /** * Callback that is called when the text input's text changes. @@ -447,7 +447,7 @@ declare namespace ReactNative { /** * Callback that is called when text input ends. */ - onEndEditing?: () => void + onEndEditing?: (event: {nativeEvent: {text: string}}) => void /** * Callback that is called when the text input is focused @@ -457,12 +457,12 @@ declare namespace ReactNative { /** * Invoked on mount and layout changes with {x, y, width, height}. */ - onLayout?: () => void + onLayout?: (event: {nativeEvent: {x: number, y: number, width: number, height: number}}) => void /** * Callback that is called when the text input's submit button is pressed. */ - onSubmitEditing?: () => void + onSubmitEditing?: (event: {nativeEvent: {text: string}}) => void /** * The string that will be rendered before text input has been entered @@ -872,6 +872,58 @@ declare namespace ReactNative { export interface ActivityIndicatorIOSStatic extends React.ComponentClass { } + + export interface DatePickerIOSProperties extends React.Props { + + /** + * The currently selected date. + */ + date?: Date + + + /** + * Maximum date. + * Restricts the range of possible date/time values. + */ + maximumDate?: Date + + /** + * Maximum date. + * Restricts the range of possible date/time values. + */ + minimumDate?: Date + + /** + * enum(1, 2, 3, 4, 5, 6, 10, 12, 15, 20, 30) + * The interval at which minutes can be selected. + */ + minuteInterval?: number + + /** + * enum('date', 'time', 'datetime') + * The date picker mode. + */ + mode?: string + + /** + * Date change handler. + * This is called when the user changes the date or time in the UI. + * The first and only argument is a Date object representing the new date and time. + */ + onDateChange?: (newDate: Date) => void + + /** + * Timezone offset in minutes. + * By default, the date picker will use the device's timezone. With this parameter, it is possible to force a certain timezone offset. + * For instance, to show times in Pacific Standard Time, pass -7 * 60. + */ + timeZoneOffsetInMinutes?: number + + } + + export interface DatePickerIOSStatic extends React.ComponentClass { + } + /** * @see https://facebook.github.io/react-native/docs/sliderios.html */ @@ -933,27 +985,97 @@ declare namespace ReactNative { /// TODO } + /** + * @see ImageResizeMode.js + */ + export interface ImageResizeModeStatic { + /** + * contain - The image will be resized such that it will be completely + * visible, contained within the frame of the View. + */ + contain: string + /** + * cover - The image will be resized such that the entire area of the view + * is covered by the image, potentially clipping parts of the image. + */ + cover: string + /** + * stretch - The image will be stretched to fill the entire frame of the + * view without clipping. This may change the aspect ratio of the image, + * distoring it. Only supported on iOS. + */ + stretch: string + } + /** * Image style * @see https://facebook.github.io/react-native/docs/image.html#style */ - export interface ImageStyle extends FlexStyle { - color?: string; - containerBackgroundColor?: string; - fontFamily?: string; - fontSize?: number; - fontStyle?: string; // 'normal' | 'italic'; - fontWeight?: string; // enum("normal", 'bold', '100', '200', '300', '400', '500', '600', '700', '800', '900') - letterSpacing?: number; - lineHeight?: number; - textAlign?: string; // enum("auto", 'left', 'right', 'center') - writingDirection?: string; //enum("auto", 'ltr', 'rtl') + export interface ImageStyle extends FlexStyle, TransformsStyle { + resizeMode?: string //Object.keys(ImageResizeMode) + backgroundColor?: string + borderColor?: string + borderWidth?: number + borderRadius?: number + overflow?: string // enum('visible', 'hidden') + tintColor?: string + opacity?: number + } + + export interface ImagePropertiesIOS { + /** + * The text that's read by the screen reader when the user interacts with the image. + */ + accessibilityLabel?: string; + + /** + * When true, indicates the image is an accessibility element. + */ + accessible?: boolean; + + /** + * When the image is resized, the corners of the size specified by capInsets will stay a fixed size, + * but the center content and borders of the image will be stretched. + * This is useful for creating resizable rounded buttons, shadows, and other resizable assets. + * More info on Apple documentation + */ + capInsets?: {top: number, left: number, bottom: number, right: number} + + /** + * A static image to display while downloading the final image off the network. + */ + defaultSource?: {uri: string} + + /** + * Invoked on load error with {nativeEvent: {error}} + */ + onError?: ( error: {nativeEvent: any} ) => void + + /** + * Invoked when load completes successfully + */ + onLoad?: () => void + + /** + * Invoked when load either succeeds or fails + */ + onLoadEnd?: () => void + + /** + * Invoked on load start + */ + onLoadStart?: () => void + + /** + * Invoked on download progress with {nativeEvent: {loaded, total}} + */ + onProgress?: ()=> void } /** * @see https://facebook.github.io/react-native/docs/image.html */ - export interface ImageProperties extends React.Props { + export interface ImageProperties extends ImagePropertiesIOS, React.Props { /** * onLayout function * @@ -966,8 +1088,10 @@ declare namespace ReactNative { /** * Determines how to resize the image when the frame doesn't match the raw image dimensions. + * + * enum('cover', 'contain', 'stretch') */ - resizeMode?: string; // enum('cover', 'contain', 'stretch') + resizeMode?: string; /** * uri is a string representing the resource identifier for the image, @@ -987,55 +1111,14 @@ declare namespace ReactNative { */ testID?: string; - /** - * The text that's read by the screen reader when the user interacts with the image. - */ - iosaccessibilityLabel?: string; - - /** - * When true, indicates the image is an accessibility element. - */ - iosaccessible?: boolean; - - /** - * When the image is resized, the corners of the size specified by capInsets will stay a fixed size, - * but the center content and borders of the image will be stretched. - * This is useful for creating resizable rounded buttons, shadows, and other resizable assets. - * More info on Apple documentation - */ - ioscapInsets?: {top: number, left: number, bottom: number, right: number} - - /** - * A static image to display while downloading the final image off the network. - */ - iosdefaultSource?: {uri: string} - - /** - * Invoked on load error with {nativeEvent: {error}} - */ - iosonError?: ( error: {nativeEvent: any} ) => void - - /** - * Invoked when load completes successfully - */ - iosonLoad?: () => void - - /** - * Invoked when load either succeeds or fails - */ - iosonLoadEnd?: () => void - - /** - * Invoked on load start - */ - iosonLoadStart?: () => void - - /** - * Invoked on download progress with {nativeEvent: {loaded, total}} - */ - iosonProgress?: ()=> void } + export interface ImageStatic extends React.ComponentClass { + uri: string; + resizeMode: ImageResizeModeStatic + } + + /** * @see https://facebook.github.io/react-native/docs/listview.html#props */ @@ -1636,9 +1719,6 @@ declare namespace ReactNative { } - export interface ImageStatic extends React.ComponentClass { - uri: string; - } /** * @see @@ -2127,6 +2207,9 @@ declare namespace ReactNative { export var CameraRoll: CameraRollStatic; export type CameraRoll = CameraRollStatic; + export var DatePickerIOS: DatePickerIOSStatic + export type DatePickerIOS = DatePickerIOSStatic + export var Image: ImageStatic; export type Image = ImageStatic; @@ -2136,12 +2219,6 @@ declare namespace ReactNative { export var Navigator: NavigatorStatic; export type Navigator = NavigatorStatic; - //export var NavigationBar: NavigationBarStatic - //export type NavigationBar = NavigationBarStatic - - //export var BreadcrumbNavigationBar: BreadcrumbNavigationBarStatic - //export type BreadcrumbNavigationBar = BreadcrumbNavigationBarStatic - export var NavigatorIOS: NavigatorIOSStatic; export type NavigatorIOS = NavigatorIOSStatic; @@ -2415,6 +2492,24 @@ declare namespace ReactNative { } + // + // Add-Ons + // + namespace addons { + + //FIXME: Documentation ? + export interface TestModuleStatic { + + verifySnapshot: (done: (indicator?: any) => void) => void + markTestPassed: (indicator: any) => void + markTestCompleted: () => void + } + + export var TestModule: TestModuleStatic + export type TestModule = TestModuleStatic + } + + } declare module "react-native" {