Skip to content

Commit

Permalink
flowified Libraries from Avik
Browse files Browse the repository at this point in the history
  • Loading branch information
Basil Hosmer committed Mar 25, 2015
1 parent 18b6d5c commit 95deed5
Show file tree
Hide file tree
Showing 22 changed files with 238 additions and 99 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* of patent rights can be found in the PATENTS file in the same directory.
*
* @providesModule ActivityIndicatorIOS
* @flow
*/
'use strict';

Expand All @@ -29,6 +30,12 @@ var SpinnerSize = keyMirror({

var GRAY = '#999999';

type DefaultProps = {
animating: boolean;
size: 'small' | 'large';
color: string;
};

var ActivityIndicatorIOS = React.createClass({
mixins: [NativeMethodsMixin],

Expand All @@ -51,7 +58,7 @@ var ActivityIndicatorIOS = React.createClass({
]),
},

getDefaultProps: function() {
getDefaultProps: function(): DefaultProps {
return {
animating: true,
size: SpinnerSize.small,
Expand Down
11 changes: 9 additions & 2 deletions Libraries/Components/DatePicker/DatePickerIOS.ios.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* of patent rights can be found in the PATENTS file in the same directory.
*
* @providesModule DatePickerIOS
* @flow
*
* This is a controlled component version of RCTDatePickerIOS
*/
Expand All @@ -26,6 +27,12 @@ var merge = require('merge');

var DATEPICKER = 'datepicker';

type DefaultProps = {
mode: 'date' | 'time' | 'datetime';
};

type Event = Object;

/**
* Use `DatePickerIOS` to render a date/time picker (selector) on iOS. This is
* a controlled component, so you must hook in to the `onDateChange` callback
Expand Down Expand Up @@ -85,13 +92,13 @@ var DatePickerIOS = React.createClass({
timeZoneOffsetInMinutes: PropTypes.number,
},

getDefaultProps: function() {
getDefaultProps: function(): DefaultProps {
return {
mode: 'datetime',
};
},

_onChange: function(event) {
_onChange: function(event: Event) {
var nativeTimeStamp = event.nativeEvent.timestamp;
this.props.onDateChange && this.props.onDateChange(
new Date(nativeTimeStamp)
Expand Down
5 changes: 4 additions & 1 deletion Libraries/Components/MapView/MapView.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* of patent rights can be found in the PATENTS file in the same directory.
*
* @providesModule MapView
* @flow
*/
'use strict';

Expand All @@ -21,6 +22,8 @@ var deepDiffer = require('deepDiffer');
var insetsDiffer = require('insetsDiffer');
var merge = require('merge');

type Event = Object;

var MapView = React.createClass({
mixins: [NativeMethodsMixin],

Expand Down Expand Up @@ -119,7 +122,7 @@ var MapView = React.createClass({
onRegionChangeComplete: React.PropTypes.func,
},

_onChange: function(event) {
_onChange: function(event: Event) {
if (event.nativeEvent.continuous) {
this.props.onRegionChange &&
this.props.onRegionChange(event.nativeEvent.region);
Expand Down
76 changes: 56 additions & 20 deletions Libraries/Components/Navigation/NavigatorIOS.ios.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* of patent rights can be found in the PATENTS file in the same directory.
*
* @providesModule NavigatorIOS
* @flow
*/
'use strict';

Expand Down Expand Up @@ -59,7 +60,7 @@ var RCTNavigatorItem = createReactIOSNativeComponentClass({
var NavigatorTransitionerIOS = React.createClass({
requestSchedulingNavigation: function(cb) {
RCTNavigatorManager.requestSchedulingJavaScriptNavigation(
this.getNodeHandle(),
(this: any).getNodeHandle(),
logError,
cb
);
Expand All @@ -72,6 +73,29 @@ var NavigatorTransitionerIOS = React.createClass({
},
});

type Route = {
component: Function;
title: string;
passProps: Object;
backButtonTitle: string;
rightButtonTitle: string;
onRightButtonPress: Function;
wrapperStyle: any;
};

type State = {
idStack: Array<number>;
routeStack: Array<Route>;
requestedTopOfStack: number;
observedTopOfStack: number;
progress: number;
fromIndex: number;
toIndex: number;
makingNavigatorRequest: boolean;
updatingAllIndicesAtOrBeyond: number;
}

type Event = Object;

/**
* Think of `<NavigatorIOS>` as simply a component that renders an
Expand Down Expand Up @@ -224,6 +248,8 @@ var NavigatorIOS = React.createClass({

},

navigator: (undefined: ?Object),

componentWillMount: function() {
// Precompute a pack of callbacks that's frequently generated and passed to
// instances.
Expand All @@ -240,7 +266,7 @@ var NavigatorIOS = React.createClass({
};
},

getInitialState: function() {
getInitialState: function(): State {
return {
idStack: [getuid()],
routeStack: [this.props.initialRoute],
Expand All @@ -266,22 +292,32 @@ var NavigatorIOS = React.createClass({
};
},

_handleFocusRequest: function(item) {
_toFocusOnNavigationComplete: (undefined: any),

_handleFocusRequest: function(item: any) {
if (this.state.makingNavigatorRequest) {
this._toFocusOnNavigationComplete = item;
} else {
this._getFocusEmitter().emit('focus', item);
}
},

_getFocusEmitter: function() {
if (!this._focusEmitter) {
this._focusEmitter = new EventEmitter();
_focusEmitter: (undefined: ?EventEmitter),

_getFocusEmitter: function(): EventEmitter {
// Flow not yet tracking assignments to instance fields.
var focusEmitter = this._focusEmitter;
if (!focusEmitter) {
focusEmitter = new EventEmitter();
this._focusEmitter = focusEmitter;
}
return this._focusEmitter;
return focusEmitter;
},

getChildContext: function() {
getChildContext: function(): {
onFocusRequested: Function;
focusEmitter: EventEmitter;
} {
return {
onFocusRequested: this._handleFocusRequest,
focusEmitter: this._getFocusEmitter(),
Expand All @@ -293,13 +329,13 @@ var NavigatorIOS = React.createClass({
focusEmitter: React.PropTypes.instanceOf(EventEmitter),
},

_tryLockNavigator: function(cb) {
_tryLockNavigator: function(cb: () => void) {
this.refs[TRANSITIONER_REF].requestSchedulingNavigation(
(acquiredLock) => acquiredLock && cb()
);
},

_handleNavigatorStackChanged: function(e) {
_handleNavigatorStackChanged: function(e: Event) {
var newObservedTopOfStack = e.nativeEvent.stackLength - 1;
invariant(
newObservedTopOfStack <= this.state.requestedTopOfStack,
Expand Down Expand Up @@ -352,7 +388,7 @@ var NavigatorIOS = React.createClass({
});
},

push: function(route) {
push: function(route: Route) {
invariant(!!route, 'Must supply route to push');
// Make sure all previous requests are caught up first. Otherwise reject.
if (this.state.requestedTopOfStack === this.state.observedTopOfStack) {
Expand All @@ -372,7 +408,7 @@ var NavigatorIOS = React.createClass({
}
},

popN: function(n) {
popN: function(n: number) {
if (n === 0) {
return;
}
Expand Down Expand Up @@ -406,7 +442,7 @@ var NavigatorIOS = React.createClass({
* `index` specifies the route in the stack that should be replaced.
* If it's negative, it counts from the back.
*/
replaceAtIndex: function(route, index) {
replaceAtIndex: function(route: Route, index: number) {
invariant(!!route, 'Must supply route to replace');
if (index < 0) {
index += this.state.routeStack.length;
Expand Down Expand Up @@ -434,22 +470,22 @@ var NavigatorIOS = React.createClass({
/**
* Replaces the top of the navigation stack.
*/
replace: function(route) {
replace: function(route: Route) {
this.replaceAtIndex(route, -1);
},

/**
* Replace the current route's parent.
*/
replacePrevious: function(route) {
replacePrevious: function(route: Route) {
this.replaceAtIndex(route, -2);
},

popToTop: function() {
this.popToRoute(this.state.routeStack[0]);
},

popToRoute: function(route) {
popToRoute: function(route: Route) {
var indexOfRoute = this.state.routeStack.indexOf(route);
invariant(
indexOfRoute !== -1,
Expand All @@ -459,7 +495,7 @@ var NavigatorIOS = React.createClass({
this.popN(numToPop);
},

replacePreviousAndPop: function(route) {
replacePreviousAndPop: function(route: Route) {
// Make sure all previous requests are caught up first. Otherwise reject.
if (this.state.requestedTopOfStack !== this.state.observedTopOfStack) {
return;
Expand All @@ -476,7 +512,7 @@ var NavigatorIOS = React.createClass({
});
},

resetTo: function(route) {
resetTo: function(route: Route) {
invariant(!!route, 'Must supply route to push');
// Make sure all previous requests are caught up first. Otherwise reject.
if (this.state.requestedTopOfStack !== this.state.observedTopOfStack) {
Expand All @@ -486,15 +522,15 @@ var NavigatorIOS = React.createClass({
this.popToRoute(route);
},

handleNavigationComplete: function(e) {
handleNavigationComplete: function(e: Event) {
if (this._toFocusOnNavigationComplete) {
this._getFocusEmitter().emit('focus', this._toFocusOnNavigationComplete);
this._toFocusOnNavigationComplete = null;
}
this._handleNavigatorStackChanged(e);
},

_routeToStackItem: function(route, i) {
_routeToStackItem: function(route: Route, i: number) {
var Component = route.component;
var shouldUpdateChild = this.state.updatingAllIndicesAtOrBeyond !== null &&
this.state.updatingAllIndicesAtOrBeyond >= i;
Expand Down
Loading

0 comments on commit 95deed5

Please sign in to comment.