Skip to content
This repository was archived by the owner on Apr 4, 2023. It is now read-only.

Commit 4a8089b

Browse files
Cleanup
1 parent 9c45840 commit 4a8089b

File tree

18 files changed

+97
-127
lines changed

18 files changed

+97
-127
lines changed

README.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,11 @@
1717

1818
<img src="docs/images/firebase-logo.png" width="116px" height="32px" alt="Firebase"/><br/>
1919

20-
> Plugin version **10.0.0** works with NativeScript 6.1+. Using an older version? Stick to plugin version < 10.
20+
> For NativeScript 7 compatibility, run `tns plugin add @nativescript/firebase`.
2121
22-
> For NativeScript 7 compatibiliy, install `@nativescript/firebase` version 11+.
22+
> For NativeScript 6.1+ compatibility, install polugin version 10: `tns plugin add nativescript-plugin-firebase@10`.
23+
24+
> For NativeScript 6.0 and lower, stick to plugin version < 10.
2325
2426
## Features
2527
* [AdMob](docs/ADMOB.md)
@@ -54,16 +56,16 @@ If you rather watch a (slightly outdated) video explaining the steps then check
5456
add iOS and Android support to the Firebase console and how to integrate anonymous authentication:
5557
[![YouTube demo](docs/images/yt-thumb-setup.png)](https://youtu.be/IextEpoIzwE "YouTube demo")
5658

57-
From the command prompt go to your app's root folder and execute:
59+
From the command prompt go to your app's root folder and execute this for NativeScript 7+:
5860

5961
```bash
60-
tns plugin add nativescript-plugin-firebase
62+
tns plugin add @nativescript/firebase
6163
```
6264

63-
or for NativeScript 7+:
65+
or for NativeScript 6:
6466

6567
```bash
66-
tns plugin add @nativescript/firebase
68+
tns plugin add nativescript-plugin-firebase
6769
```
6870

6971
This will launch an install script which will guide you through installing additional components.

demo/app/main-view-model.ts

Lines changed: 49 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,23 @@
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";
24
import { 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";
39
import { 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";
612
import { MessagingViewModel } from "./messaging-view-model";
713

814
const firebaseWebApi = require("@nativescript/firebase/app");
915

10-
declare const Crashlytics: any;
11-
1216
export 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 {
931934
932935
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",

demo/app/vendor-platform.android.ts

Lines changed: 0 additions & 9 deletions
This file was deleted.

demo/app/vendor-platform.ios.ts

Lines changed: 0 additions & 3 deletions
This file was deleted.

demo/app/vendor-platform.ts

Whitespace-only changes.

demo/app/vendor.ts

Lines changed: 0 additions & 10 deletions
This file was deleted.

demo/package.json

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
{
22
"dependencies": {
3-
"firebase-functions": "^2.0.5",
4-
"@nativescript/firebase": "file:../src",
5-
"nativescript-theme-core": "^1.0.4",
3+
"@nativescript/core": "~7.0.13",
4+
"@nativescript/firebase": "file:../publish/package/nativescript-firebase-11.1.1.tgz",
65
"@nativescript/unit-test-runner": "~1.0.2",
7-
"@nativescript/core": "7.0.0",
8-
"@nativescript/webpack": "~3.0.0"
6+
"firebase-functions": "^2.0.5",
7+
"nativescript-theme-core": "^1.0.4"
98
},
109
"devDependencies": {
10+
"@nativescript/android": "7.0.1",
1111
"@nativescript/ios": "7.0.4",
12-
"@nativescript/types": "~7.0.0",
12+
"@nativescript/types": "~7.0.4",
13+
"@nativescript/webpack": "~3.0.8",
1314
"@types/jasmine": "~2.8.0",
1415
"babel-traverse": "6.12.0",
1516
"babel-types": "6.11.1",
@@ -19,11 +20,9 @@
1920
"karma": "4.1.0",
2021
"karma-jasmine": "2.0.1",
2122
"karma-nativescript-launcher": "^0.4.0",
22-
"karma-webpack": "3.0.5",
2323
"lazy": "1.0.11",
24-
"nativescript-css-loader": "~0.26.0",
2524
"tslint": "~5.4.3",
26-
"typescript": "~4.0.0"
25+
"typescript": "~4.0.5"
2726
},
2827
"scripts": {
2928
"build.plugin": "cd ../src && npm run build",

docs/CRASHLYTICS.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,10 @@ Then produce a crash, and it can easily take a day before that screen changes (l
2626
Send a native iOS or Android exception to Crashlytics.
2727

2828
```typescript
29-
// either import like this:
29+
// for NativeScript 7, import like this:
30+
import { crashlytics } from "@nativescript/firebase/crashlytics";
31+
32+
// for older versions of NativeScript, either import like this:
3033
import { crashlytics } from "nativescript-plugin-firebase"; // and do: crashlytics.sendCrashLog
3134
// or this:
3235
import { crashlytics as firebaseCrashlytics } from "nativescript-plugin-firebase"; // and do: firebaseCrashlytics.sendCrashLog

src/app/functions/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import { functions as fNamepspace } from "../../firebase";
1+
import { firebaseFunctions as fNamespace } from "../../firebase";
22

33
export namespace functions {
44
// tslint:disable-next-line:class-name
55
export class Functions {
6-
httpsCallable<I, O>(functionName: string, region?: fNamepspace.SupportedRegions) {
7-
return fNamepspace.httpsCallable<I, O>(functionName, region);
6+
httpsCallable<I, O>(functionName: string, region?: fNamespace.SupportedRegions) {
7+
return fNamespace.httpsCallable<I, O>(functionName, region);
88
}
99
}
1010
}

0 commit comments

Comments
 (0)