11//React Native wrapper
2- import { ReactNativeWrapper } from "./../wrapper/wrapper" ;
32import { ReactNativeWrapperImpl } from './../wrapper/wrapper_impl' ;
43
54//Dependencies
6- import 'reflect-metadata' ;
7- // Zone.js
8- import { Zone } from 'zone.js/build/lib/core' ;
9- global . Zone = Zone ;
10- global . zone = new Zone ( ) ;
11- import { patchSetClearFunction } from 'zone.js/build/lib/patch/functions' ;
12- import { apply } from 'zone.js/build/lib/patch/promise' ;
13- patchSetClearFunction ( global , global . Zone ,
14- [ [ 'setTimeout' , 'clearTimeout' , false , false ] ,
15- [ 'setInterval' , 'clearInterval' , true , false ] ,
16- [ 'setImmediate' , 'clearImmediate' , false , false ] ] ) ;
5+ import 'reflect-metadata'
176
18- //Needed for Android or iOS, but to be imported after zone.js, and
19- var originalIsExtensible = Object . isExtensible ;
20- import 'es6-shim' ;
21- Object . isExtensible = originalIsExtensible ;
22- //Patch promises after es6-shim overrides them
23- apply ( ) ;
7+ //Zone.js, patching RN's polyfill of XMLHttpRequest is needed to make it compatible with Zone.js
8+ var onreadystatechangeGetter = function ( ) { return this . _onreadystatechange ; } ;
9+ var onreadystatechangeSetter = function ( v : any ) { this . _onreadystatechange = v ; } ;
10+ Object . defineProperty ( XMLHttpRequest . prototype , 'onreadystatechange' , {
11+ get : onreadystatechangeGetter ,
12+ set : onreadystatechangeSetter ,
13+ configurable : true
14+ } ) ;
15+ import 'zone.js/dist/zone.js' ;
16+ Object . defineProperty ( XMLHttpRequest . prototype , 'onreadystatechange' , {
17+ get : onreadystatechangeGetter ,
18+ } ) ;
2419
2520// Finally, define the bootstrap
2621import { RootRenderer , Renderer , provide , NgZone , Provider , enableProdMode , PLATFORM_DIRECTIVES } from 'angular2/core' ;
@@ -51,7 +46,7 @@ import {MapView} from "../components/ios/map_view";
5146import { TabBar } from "../components/ios/tabbar" ;
5247import { TabBarItem } from "../components/ios/tabbar_item" ;
5348
54- export function bootstrapReactNative ( appName :string , cpt : any , customProviders ?: Array < any > = [ ] ) {
49+ export function bootstrapReactNative ( appName :string , cpt : any , customProviders ?: Array < any > ) {
5550 ReactNativeWrapperImpl . registerApp ( appName , function ( ) {
5651 enableProdMode ( ) ;
5752 bootstrap ( cpt , [
@@ -89,11 +84,11 @@ export function bootstrapReactNative(appName:string, cpt: any, customProviders?:
8984 provide ( ElementSchemaRegistry , { useExisting : ReactNativeElementSchemaRegistry } ) ,
9085 provide ( ReactNativeRootRenderer , { useClass : ReactNativeRootRenderer_ } ) ,
9186 provide ( RootRenderer , { useExisting : ReactNativeRootRenderer } )
92- ] . concat ( customProviders ) ) . then ( function ( appRef ) {
87+ ] . concat ( customProviders || [ ] ) ) . then ( function ( appRef ) {
9388 var zone = appRef . injector . get ( NgZone ) ;
9489 var rootRenderer = appRef . injector . get ( RootRenderer ) ;
95- zone . onTurnDone . subscribe ( ( ) => { rootRenderer . executeCommands ( ) ; } ) ;
96- appRef . injector . get ( ReactNativeWrapperImpl ) . patchReactUpdates ( zone . _innerZone ) ;
90+ zone . onStable . subscribe ( ( ) => { rootRenderer . executeCommands ( ) ; } ) ;
91+ appRef . injector . get ( ReactNativeWrapperImpl ) . patchReactUpdates ( zone ) ;
9792 } ) ;
9893 } ) ;
9994}
0 commit comments