1- import { firebase , AddEventListenerResult , admob as firebaseAdMob , crashlytics as firebaseCrashlytics , GetRemoteConfigResult , IdTokenResult , LogComplexEventTypeParameter , performance as firebasePerformance , storage as firebaseStorage , User } from "@nativescript/firebase" ;
1+ import { alert , File , isAndroid , isIOS , knownFolders , Observable , prompt } from "@nativescript/core" ;
2+ import { firebase } from "@nativescript/firebase" ;
3+ import { admob as firebaseAdmob } from "@nativescript/firebase/admob" ;
24import { RewardedVideoAdReward } from "@nativescript/firebase/admob/admob" ;
5+ import { analytics as firebaseAnalytics } from "@nativescript/firebase/analytics" ;
6+ import { crashlytics as firebaseCrashlytics } from "@nativescript/firebase/crashlytics" ;
7+ import { firebaseFunctions } from "@nativescript/firebase/functions" ;
8+ import { performance as firebasePerformance } from "@nativescript/firebase/performance" ;
39import { FirebaseTrace } from "@nativescript/firebase/performance/performance" ;
4- import { Observable , isAndroid , isIOS , Dialogs , knownFolders , File } from "@nativescript/core " ;
5- import { UploadMetadata } from "../../src /storage/storage" ;
10+ import { storage as firebaseStorage } from "@nativescript/firebase/storage " ;
11+ import { UploadMetadata } from "@nativescript/firebase /storage/storage" ;
612import { MessagingViewModel } from "./messaging-view-model" ;
713
814const firebaseWebApi = require ( "@nativescript/firebase/app" ) ;
915
10- declare const Crashlytics : any ;
11-
1216export class HelloWorldModel extends Observable {
13-
1417 public messaging = new MessagingViewModel ( ) ;
1518 public userEmailOrPhone : string ;
16- private userListenerWrapper : AddEventListenerResult ;
17- private companiesListenerWrapper : AddEventListenerResult ;
19+ private userListenerWrapper : firebase . AddEventListenerResult ;
20+ private companiesListenerWrapper : firebase . AddEventListenerResult ;
1821 private onAuthStateChangedHandlerSet = false ;
1922 private firebaseTrace : FirebaseTrace ;
2023
@@ -25,7 +28,7 @@ export class HelloWorldModel extends Observable {
2528 private ensureWebOnAuthChangedHandler ( ) : void {
2629 if ( ! this . onAuthStateChangedHandlerSet ) {
2730 this . onAuthStateChangedHandlerSet = true ;
28- firebaseWebApi . auth ( ) . onAuthStateChanged ( ( user ?: User ) => {
31+ firebaseWebApi . auth ( ) . onAuthStateChanged ( ( user ?: firebase . User ) => {
2932 console . log ( ">> auth state changed: " + user ) ;
3033 if ( user ) {
3134 this . set ( "userEmailOrPhone" , user . email ? user . email : ( user . phoneNumber ? user . phoneNumber : "N/A" ) ) ;
@@ -133,7 +136,7 @@ export class HelloWorldModel extends Observable {
133136
134137 public doWebCreateUser ( ) : void {
135138 firebaseWebApi . auth ( ) . createUserWithEmailAndPassword ( '[email protected] ' , 'firebase' ) 136- . then ( ( user : User ) => {
139+ . then ( ( user : firebase . User ) => {
137140 console . log ( "User created: " + JSON . stringify ( user ) ) ;
138141 this . set ( "userEmailOrPhone" , user . email ) ;
139142 alert ( {
@@ -175,7 +178,7 @@ export class HelloWorldModel extends Observable {
175178
176179 public doWebCallableFunction ( ) : void {
177180 // see the implementation of this function @ https://github.com/EddyVerbruggen/nativescript-plugin-firebase/blob/ff95c77c7b09acf66654f53c52e8ae0c8d7b1c78/demo/firebasefunctions/functions/src/index.ts#L15-L19
178- const fn = firebase . functions . httpsCallable ( "helloName" ) ;
181+ const fn = firebaseFunctions . httpsCallable ( "helloName" ) ;
179182
180183 fn ( "Nativescript-Plugin-Firebase!" )
181184 . then ( ( dataCue : any ) => {
@@ -288,7 +291,7 @@ export class HelloWorldModel extends Observable {
288291
289292 public doWebStoreCompanyByFirstCreatingKey ( ) : void {
290293 const path = "companies" ,
291- companyRef = firebaseWebApi . database ( ) . ref ( ) . child ( path ) ,
294+ companyRef = firebaseWebApi . database ( ) . ref ( path ) ,
292295 newCompanyKey = companyRef . push ( ) . key ,
293296 storeAtPath = `/${ path } /${ newCompanyKey } ` ,
294297 value = {
@@ -464,7 +467,7 @@ export class HelloWorldModel extends Observable {
464467 }
465468
466469 public doEnableAnalytics ( ) : void {
467- firebase . analytics . setAnalyticsCollectionEnabled ( true ) ;
470+ firebaseAnalytics . setAnalyticsCollectionEnabled ( true ) ;
468471 alert ( {
469472 title : "Analytics collection" ,
470473 message : "ENABLED" ,
@@ -473,7 +476,7 @@ export class HelloWorldModel extends Observable {
473476 }
474477
475478 public doDisableAnalytics ( ) : void {
476- firebase . analytics . setAnalyticsCollectionEnabled ( false ) ;
479+ firebaseAnalytics . setAnalyticsCollectionEnabled ( false ) ;
477480 alert ( {
478481 title : "Analytics collection" ,
479482 message : "DISABLED" ,
@@ -482,7 +485,7 @@ export class HelloWorldModel extends Observable {
482485 }
483486
484487 public doLogAnalyticsEvents ( ) : void {
485- firebase . analytics . logEvent ( {
488+ firebaseAnalytics . logEvent ( {
486489 // see https://firebase.google.com/docs/reference/android/com/google/firebase/analytics/FirebaseAnalytics.Event.html
487490 key : "add_to_cart" ,
488491 parameters : [
@@ -514,34 +517,34 @@ export class HelloWorldModel extends Observable {
514517 * Same thing as logEvent but can add an array or specific types not just string (LogComplexEventTypeParameter.BOOLEAN, LogComplexEventTypeParameter.STRING,
515518 * LogComplexEventTypeParameter.DOUBLE, LogComplexEventTypeParameter.FLOAT, LogComplexEventTypeParameter.INT, LogComplexEventTypeParameter.ARRAY)
516519 */
517- firebase . analytics . logComplexEvent ( {
520+ firebaseAnalytics . logComplexEvent ( {
518521 key : "view_item_list" ,
519522 parameters : [ {
520523 key : "item1" ,
521524 type : "array" ,
522525 value : [
523526 {
524527 parameters : [
525- { key : "item_id" , value : "id of item" , type : LogComplexEventTypeParameter . STRING } ,
526- { key : "item_name" , value : "name of item" , type : LogComplexEventTypeParameter . STRING } ,
527- { key : "item_category" , value : "category" , type : LogComplexEventTypeParameter . STRING } ,
528- { key : "item_variant" , value : "variant" , type : LogComplexEventTypeParameter . STRING } ,
529- { key : "item_brand" , value : "name of item brand" , type : LogComplexEventTypeParameter . STRING } ,
530- { key : "price" , value : 1 , type : LogComplexEventTypeParameter . DOUBLE } ,
531- { key : "item_list" , value : "name of list" , type : LogComplexEventTypeParameter . STRING } ,
532- { key : "index" , value : 1 , type : LogComplexEventTypeParameter . INT }
528+ { key : "item_id" , value : "id of item" , type : firebase . LogComplexEventTypeParameter . STRING } ,
529+ { key : "item_name" , value : "name of item" , type : firebase . LogComplexEventTypeParameter . STRING } ,
530+ { key : "item_category" , value : "category" , type : firebase . LogComplexEventTypeParameter . STRING } ,
531+ { key : "item_variant" , value : "variant" , type : firebase . LogComplexEventTypeParameter . STRING } ,
532+ { key : "item_brand" , value : "name of item brand" , type : firebase . LogComplexEventTypeParameter . STRING } ,
533+ { key : "price" , value : 1 , type : firebase . LogComplexEventTypeParameter . DOUBLE } ,
534+ { key : "item_list" , value : "name of list" , type : firebase . LogComplexEventTypeParameter . STRING } ,
535+ { key : "index" , value : 1 , type : firebase . LogComplexEventTypeParameter . INT }
533536 ]
534537 } ,
535538 {
536539 parameters : [
537- { key : "item_id" , value : "id of item" , type : LogComplexEventTypeParameter . STRING } ,
538- { key : "item_name" , value : "name of item" , type : LogComplexEventTypeParameter . STRING } ,
539- { key : "item_category" , value : "category" , type : LogComplexEventTypeParameter . STRING } ,
540- { key : "item_variant" , value : "variant" , type : LogComplexEventTypeParameter . STRING } ,
541- { key : "item_brand" , value : "name of item brand" , type : LogComplexEventTypeParameter . STRING } ,
542- { key : "price" , value : 1 , type : LogComplexEventTypeParameter . DOUBLE } ,
543- { key : "item_list" , value : "name of list" , type : LogComplexEventTypeParameter . STRING } ,
544- { key : "index" , value : 2 , type : LogComplexEventTypeParameter . INT }
540+ { key : "item_id" , value : "id of item" , type : firebase . LogComplexEventTypeParameter . STRING } ,
541+ { key : "item_name" , value : "name of item" , type : firebase . LogComplexEventTypeParameter . STRING } ,
542+ { key : "item_category" , value : "category" , type : firebase . LogComplexEventTypeParameter . STRING } ,
543+ { key : "item_variant" , value : "variant" , type : firebase . LogComplexEventTypeParameter . STRING } ,
544+ { key : "item_brand" , value : "name of item brand" , type : firebase . LogComplexEventTypeParameter . STRING } ,
545+ { key : "price" , value : 1 , type : firebase . LogComplexEventTypeParameter . DOUBLE } ,
546+ { key : "item_list" , value : "name of list" , type : firebase . LogComplexEventTypeParameter . STRING } ,
547+ { key : "index" , value : 2 , type : firebase . LogComplexEventTypeParameter . INT }
545548 ]
546549 }
547550 ]
@@ -551,7 +554,7 @@ export class HelloWorldModel extends Observable {
551554 }
552555
553556 public doSetAnalyticsUserProperty ( ) : void {
554- firebase . analytics . setUserProperty ( {
557+ firebaseAnalytics . setUserProperty ( {
555558 key : "origin" , // note that this needs to be preregistered, see https://support.google.com/firebase/answer/6317519?hl=en&ref_topic=6317489#create-property
556559 value : "demoapp"
557560 } ) . then (
@@ -580,7 +583,7 @@ export class HelloWorldModel extends Observable {
580583 }
581584
582585 private setScreenName ( screenName ) : void {
583- firebase . analytics . setScreenName ( {
586+ firebaseAnalytics . setScreenName ( {
584587 screenName
585588 } ) . then (
586589 ( ) => {
@@ -600,8 +603,8 @@ export class HelloWorldModel extends Observable {
600603 }
601604
602605 public doShowAdMobBanner ( ) : void {
603- firebaseAdMob . showBanner ( {
604- size : firebaseAdMob . AD_SIZE . SMART_BANNER ,
606+ firebaseAdmob . showBanner ( {
607+ size : firebaseAdmob . AD_SIZE . SMART_BANNER ,
605608 margins : {
606609 bottom : isIOS ? 50 : 0
607610 } ,
@@ -637,7 +640,7 @@ export class HelloWorldModel extends Observable {
637640 }
638641
639642 public doShowAdMobInterstitial ( ) : void {
640- firebase . admob . showInterstitial ( {
643+ firebaseAdmob . showInterstitial ( {
641644 iosInterstitialId : "ca-app-pub-9517346003011652/6938836122" ,
642645 androidInterstitialId : "ca-app-pub-9517346003011652/9225834529" ,
643646 testing : true ,
@@ -661,7 +664,7 @@ export class HelloWorldModel extends Observable {
661664 }
662665
663666 public doPreloadAdMobInterstitial ( ) : void {
664- firebaseAdMob . preloadInterstitial ( {
667+ firebaseAdmob . preloadInterstitial ( {
665668 iosInterstitialId : "ca-app-pub-9517346003011652/6938836122" ,
666669 androidInterstitialId : "ca-app-pub-9517346003011652/9225834529" ,
667670 testing : true ,
@@ -687,7 +690,7 @@ export class HelloWorldModel extends Observable {
687690 }
688691
689692 public doShowPreloadedAdMobInterstitial ( ) : void {
690- firebaseAdMob . showInterstitial ( ) . then (
693+ firebaseAdmob . showInterstitial ( ) . then (
691694 ( ) => console . log ( "AdMob interstitial showing" ) ,
692695 errorMessage => {
693696 alert ( {
@@ -700,7 +703,7 @@ export class HelloWorldModel extends Observable {
700703 }
701704
702705 public doPreloadRewardedVideoAd ( ) : void {
703- firebaseAdMob . preloadRewardedVideoAd ( {
706+ firebaseAdmob . preloadRewardedVideoAd ( {
704707 iosAdPlacementId : "ca-app-pub-9517346003011652/8586553377" ,
705708 androidAdPlacementId : "ca-app-pub-9517346003011652/2819097664" ,
706709 testing : true ,
@@ -727,7 +730,7 @@ export class HelloWorldModel extends Observable {
727730
728731 public doShowPreloadedRewardedVideoAd ( ) : void {
729732 let reward : RewardedVideoAdReward ;
730- firebaseAdMob . showRewardedVideoAd ( {
733+ firebaseAdmob . showRewardedVideoAd ( {
731734 onRewarded : receivedReward => {
732735 reward = receivedReward ;
733736 console . log ( "Rewarded video ad: rewarded. Details: " + JSON . stringify ( reward ) ) ;
@@ -767,7 +770,7 @@ export class HelloWorldModel extends Observable {
767770 * so there's no function to do it programmatically.
768771 */
769772 public doHideAdMobBanner ( ) : void {
770- firebase . admob . hideBanner ( ) . then (
773+ firebaseAdmob . hideBanner ( ) . then (
771774 ( ) => {
772775 console . log ( "AdMob banner hidden" ) ;
773776 } ,
@@ -814,7 +817,7 @@ export class HelloWorldModel extends Observable {
814817 "default" : 11
815818 } ]
816819 } ) . then (
817- ( result : GetRemoteConfigResult ) => {
820+ ( result : firebase . GetRemoteConfigResult ) => {
818821 console . log ( "remote config fetched: " + JSON . stringify ( result . properties ) ) ;
819822 alert ( {
820823 title : `Fetched at ${ result . lastFetch } ${ result . throttled ? '(throttled)' : '' } ` ,
@@ -931,7 +934,7 @@ export class HelloWorldModel extends Observable {
931934932935 password : 'firebase'
933936 } ) . then (
934- ( user : User ) => {
937+ ( user : firebase . User ) => {
935938 console . log ( "User created: " + JSON . stringify ( user ) ) ;
936939 this . set ( "userEmailOrPhone" , user . email ) ;
937940 alert ( {
@@ -992,7 +995,7 @@ export class HelloWorldModel extends Observable {
992995 {
993996 forceRefresh : false
994997 } )
995- . then ( ( result : IdTokenResult ) => console . log ( "Auth token retrieved: " + JSON . stringify ( result ) ) )
998+ . then ( ( result : firebase . IdTokenResult ) => console . log ( "Auth token retrieved: " + JSON . stringify ( result ) ) )
996999 . catch ( errorMessage => console . log ( "Auth token retrieval error: " + errorMessage ) ) ;
9971000 } ,
9981001 errorMessage => {
@@ -1959,7 +1962,7 @@ export class HelloWorldModel extends Observable {
19591962
19601963 public doSetUserId ( ) : void {
19611964 // just for fun: showing usage of 'firebase.crashlytics' instead of 'firebaseCrashlytics'
1962- firebase . crashlytics . setUserId ( "user#42" ) ;
1965+ firebaseCrashlytics . setUserId ( "user#42" ) ;
19631966
19641967 alert ( {
19651968 title : "User id changed" ,
0 commit comments