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

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
EddyVerbruggen committed Nov 2, 2020
1 parent 9c45840 commit 4a8089b
Show file tree
Hide file tree
Showing 18 changed files with 97 additions and 127 deletions.
14 changes: 8 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@

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

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

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

```bash
tns plugin add nativescript-plugin-firebase
tns plugin add @nativescript/firebase
```

or for NativeScript 7+:
or for NativeScript 6:

```bash
tns plugin add @nativescript/firebase
tns plugin add nativescript-plugin-firebase
```

This will launch an install script which will guide you through installing additional components.
Expand Down
95 changes: 49 additions & 46 deletions demo/app/main-view-model.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
import { firebase, AddEventListenerResult, admob as firebaseAdMob, crashlytics as firebaseCrashlytics, GetRemoteConfigResult, IdTokenResult, LogComplexEventTypeParameter, performance as firebasePerformance, storage as firebaseStorage, User } from "@nativescript/firebase";
import { alert, File, isAndroid, isIOS, knownFolders, Observable, prompt } from "@nativescript/core";
import { firebase } from "@nativescript/firebase";
import { admob as firebaseAdmob } from "@nativescript/firebase/admob";
import { RewardedVideoAdReward } from "@nativescript/firebase/admob/admob";
import { analytics as firebaseAnalytics } from "@nativescript/firebase/analytics";
import { crashlytics as firebaseCrashlytics } from "@nativescript/firebase/crashlytics";
import { firebaseFunctions } from "@nativescript/firebase/functions";
import { performance as firebasePerformance } from "@nativescript/firebase/performance";
import { FirebaseTrace } from "@nativescript/firebase/performance/performance";
import { Observable, isAndroid, isIOS, Dialogs, knownFolders, File } from "@nativescript/core";
import { UploadMetadata } from "../../src/storage/storage";
import { storage as firebaseStorage } from "@nativescript/firebase/storage";
import { UploadMetadata } from "@nativescript/firebase/storage/storage";
import { MessagingViewModel } from "./messaging-view-model";

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

declare const Crashlytics: any;

export class HelloWorldModel extends Observable {

public messaging = new MessagingViewModel();
public userEmailOrPhone: string;
private userListenerWrapper: AddEventListenerResult;
private companiesListenerWrapper: AddEventListenerResult;
private userListenerWrapper: firebase.AddEventListenerResult;
private companiesListenerWrapper: firebase.AddEventListenerResult;
private onAuthStateChangedHandlerSet = false;
private firebaseTrace: FirebaseTrace;

Expand All @@ -25,7 +28,7 @@ export class HelloWorldModel extends Observable {
private ensureWebOnAuthChangedHandler(): void {
if (!this.onAuthStateChangedHandlerSet) {
this.onAuthStateChangedHandlerSet = true;
firebaseWebApi.auth().onAuthStateChanged((user?: User) => {
firebaseWebApi.auth().onAuthStateChanged((user?: firebase.User) => {
console.log(">> auth state changed: " + user);
if (user) {
this.set("userEmailOrPhone", user.email ? user.email : (user.phoneNumber ? user.phoneNumber : "N/A"));
Expand Down Expand Up @@ -133,7 +136,7 @@ export class HelloWorldModel extends Observable {

public doWebCreateUser(): void {
firebaseWebApi.auth().createUserWithEmailAndPassword('[email protected]', 'firebase')
.then((user: User) => {
.then((user: firebase.User) => {
console.log("User created: " + JSON.stringify(user));
this.set("userEmailOrPhone", user.email);
alert({
Expand Down Expand Up @@ -175,7 +178,7 @@ export class HelloWorldModel extends Observable {

public doWebCallableFunction(): void {
// see the implementation of this function @ https://github.com/EddyVerbruggen/nativescript-plugin-firebase/blob/ff95c77c7b09acf66654f53c52e8ae0c8d7b1c78/demo/firebasefunctions/functions/src/index.ts#L15-L19
const fn = firebase.functions.httpsCallable("helloName");
const fn = firebaseFunctions.httpsCallable("helloName");

fn("Nativescript-Plugin-Firebase!")
.then((dataCue: any) => {
Expand Down Expand Up @@ -288,7 +291,7 @@ export class HelloWorldModel extends Observable {

public doWebStoreCompanyByFirstCreatingKey(): void {
const path = "companies",
companyRef = firebaseWebApi.database().ref().child(path),
companyRef = firebaseWebApi.database().ref(path),
newCompanyKey = companyRef.push().key,
storeAtPath = `/${path}/${newCompanyKey}`,
value = {
Expand Down Expand Up @@ -464,7 +467,7 @@ export class HelloWorldModel extends Observable {
}

public doEnableAnalytics(): void {
firebase.analytics.setAnalyticsCollectionEnabled(true);
firebaseAnalytics.setAnalyticsCollectionEnabled(true);
alert({
title: "Analytics collection",
message: "ENABLED",
Expand All @@ -473,7 +476,7 @@ export class HelloWorldModel extends Observable {
}

public doDisableAnalytics(): void {
firebase.analytics.setAnalyticsCollectionEnabled(false);
firebaseAnalytics.setAnalyticsCollectionEnabled(false);
alert({
title: "Analytics collection",
message: "DISABLED",
Expand All @@ -482,7 +485,7 @@ export class HelloWorldModel extends Observable {
}

public doLogAnalyticsEvents(): void {
firebase.analytics.logEvent({
firebaseAnalytics.logEvent({
// see https://firebase.google.com/docs/reference/android/com/google/firebase/analytics/FirebaseAnalytics.Event.html
key: "add_to_cart",
parameters: [
Expand Down Expand Up @@ -514,34 +517,34 @@ export class HelloWorldModel extends Observable {
* Same thing as logEvent but can add an array or specific types not just string (LogComplexEventTypeParameter.BOOLEAN, LogComplexEventTypeParameter.STRING,
* LogComplexEventTypeParameter.DOUBLE, LogComplexEventTypeParameter.FLOAT, LogComplexEventTypeParameter.INT, LogComplexEventTypeParameter.ARRAY)
*/
firebase.analytics.logComplexEvent({
firebaseAnalytics.logComplexEvent({
key: "view_item_list",
parameters: [{
key: "item1",
type: "array",
value: [
{
parameters: [
{key: "item_id", value: "id of item", type: LogComplexEventTypeParameter.STRING},
{key: "item_name", value: "name of item", type: LogComplexEventTypeParameter.STRING},
{key: "item_category", value: "category", type: LogComplexEventTypeParameter.STRING},
{key: "item_variant", value: "variant", type: LogComplexEventTypeParameter.STRING},
{key: "item_brand", value: "name of item brand", type: LogComplexEventTypeParameter.STRING},
{key: "price", value: 1, type: LogComplexEventTypeParameter.DOUBLE},
{key: "item_list", value: "name of list", type: LogComplexEventTypeParameter.STRING},
{key: "index", value: 1, type: LogComplexEventTypeParameter.INT}
{key: "item_id", value: "id of item", type: firebase.LogComplexEventTypeParameter.STRING},
{key: "item_name", value: "name of item", type: firebase.LogComplexEventTypeParameter.STRING},
{key: "item_category", value: "category", type: firebase.LogComplexEventTypeParameter.STRING},
{key: "item_variant", value: "variant", type: firebase.LogComplexEventTypeParameter.STRING},
{key: "item_brand", value: "name of item brand", type: firebase.LogComplexEventTypeParameter.STRING},
{key: "price", value: 1, type: firebase.LogComplexEventTypeParameter.DOUBLE},
{key: "item_list", value: "name of list", type: firebase.LogComplexEventTypeParameter.STRING},
{key: "index", value: 1, type: firebase.LogComplexEventTypeParameter.INT}
]
},
{
parameters: [
{key: "item_id", value: "id of item", type: LogComplexEventTypeParameter.STRING},
{key: "item_name", value: "name of item", type: LogComplexEventTypeParameter.STRING},
{key: "item_category", value: "category", type: LogComplexEventTypeParameter.STRING},
{key: "item_variant", value: "variant", type: LogComplexEventTypeParameter.STRING},
{key: "item_brand", value: "name of item brand", type: LogComplexEventTypeParameter.STRING},
{key: "price", value: 1, type: LogComplexEventTypeParameter.DOUBLE},
{key: "item_list", value: "name of list", type: LogComplexEventTypeParameter.STRING},
{key: "index", value: 2, type: LogComplexEventTypeParameter.INT}
{key: "item_id", value: "id of item", type: firebase.LogComplexEventTypeParameter.STRING},
{key: "item_name", value: "name of item", type: firebase.LogComplexEventTypeParameter.STRING},
{key: "item_category", value: "category", type: firebase.LogComplexEventTypeParameter.STRING},
{key: "item_variant", value: "variant", type: firebase.LogComplexEventTypeParameter.STRING},
{key: "item_brand", value: "name of item brand", type: firebase.LogComplexEventTypeParameter.STRING},
{key: "price", value: 1, type: firebase.LogComplexEventTypeParameter.DOUBLE},
{key: "item_list", value: "name of list", type: firebase.LogComplexEventTypeParameter.STRING},
{key: "index", value: 2, type: firebase.LogComplexEventTypeParameter.INT}
]
}
]
Expand All @@ -551,7 +554,7 @@ export class HelloWorldModel extends Observable {
}

public doSetAnalyticsUserProperty(): void {
firebase.analytics.setUserProperty({
firebaseAnalytics.setUserProperty({
key: "origin", // note that this needs to be preregistered, see https://support.google.com/firebase/answer/6317519?hl=en&ref_topic=6317489#create-property
value: "demoapp"
}).then(
Expand Down Expand Up @@ -580,7 +583,7 @@ export class HelloWorldModel extends Observable {
}

private setScreenName(screenName): void {
firebase.analytics.setScreenName({
firebaseAnalytics.setScreenName({
screenName
}).then(
() => {
Expand All @@ -600,8 +603,8 @@ export class HelloWorldModel extends Observable {
}

public doShowAdMobBanner(): void {
firebaseAdMob.showBanner({
size: firebaseAdMob.AD_SIZE.SMART_BANNER,
firebaseAdmob.showBanner({
size: firebaseAdmob.AD_SIZE.SMART_BANNER,
margins: {
bottom: isIOS ? 50 : 0
},
Expand Down Expand Up @@ -637,7 +640,7 @@ export class HelloWorldModel extends Observable {
}

public doShowAdMobInterstitial(): void {
firebase.admob.showInterstitial({
firebaseAdmob.showInterstitial({
iosInterstitialId: "ca-app-pub-9517346003011652/6938836122",
androidInterstitialId: "ca-app-pub-9517346003011652/9225834529",
testing: true,
Expand All @@ -661,7 +664,7 @@ export class HelloWorldModel extends Observable {
}

public doPreloadAdMobInterstitial(): void {
firebaseAdMob.preloadInterstitial({
firebaseAdmob.preloadInterstitial({
iosInterstitialId: "ca-app-pub-9517346003011652/6938836122",
androidInterstitialId: "ca-app-pub-9517346003011652/9225834529",
testing: true,
Expand All @@ -687,7 +690,7 @@ export class HelloWorldModel extends Observable {
}

public doShowPreloadedAdMobInterstitial(): void {
firebaseAdMob.showInterstitial().then(
firebaseAdmob.showInterstitial().then(
() => console.log("AdMob interstitial showing"),
errorMessage => {
alert({
Expand All @@ -700,7 +703,7 @@ export class HelloWorldModel extends Observable {
}

public doPreloadRewardedVideoAd(): void {
firebaseAdMob.preloadRewardedVideoAd({
firebaseAdmob.preloadRewardedVideoAd({
iosAdPlacementId: "ca-app-pub-9517346003011652/8586553377",
androidAdPlacementId: "ca-app-pub-9517346003011652/2819097664",
testing: true,
Expand All @@ -727,7 +730,7 @@ export class HelloWorldModel extends Observable {

public doShowPreloadedRewardedVideoAd(): void {
let reward: RewardedVideoAdReward;
firebaseAdMob.showRewardedVideoAd({
firebaseAdmob.showRewardedVideoAd({
onRewarded: receivedReward => {
reward = receivedReward;
console.log("Rewarded video ad: rewarded. Details: " + JSON.stringify(reward));
Expand Down Expand Up @@ -767,7 +770,7 @@ export class HelloWorldModel extends Observable {
* so there's no function to do it programmatically.
*/
public doHideAdMobBanner(): void {
firebase.admob.hideBanner().then(
firebaseAdmob.hideBanner().then(
() => {
console.log("AdMob banner hidden");
},
Expand Down Expand Up @@ -814,7 +817,7 @@ export class HelloWorldModel extends Observable {
"default": 11
}]
}).then(
(result: GetRemoteConfigResult) => {
(result: firebase.GetRemoteConfigResult) => {
console.log("remote config fetched: " + JSON.stringify(result.properties));
alert({
title: `Fetched at ${result.lastFetch} ${result.throttled ? '(throttled)' : ''}`,
Expand Down Expand Up @@ -931,7 +934,7 @@ export class HelloWorldModel extends Observable {
email: '[email protected]',
password: 'firebase'
}).then(
(user: User) => {
(user: firebase.User) => {
console.log("User created: " + JSON.stringify(user));
this.set("userEmailOrPhone", user.email);
alert({
Expand Down Expand Up @@ -992,7 +995,7 @@ export class HelloWorldModel extends Observable {
{
forceRefresh: false
})
.then((result: IdTokenResult) => console.log("Auth token retrieved: " + JSON.stringify(result)))
.then((result: firebase.IdTokenResult) => console.log("Auth token retrieved: " + JSON.stringify(result)))
.catch(errorMessage => console.log("Auth token retrieval error: " + errorMessage));
},
errorMessage => {
Expand Down Expand Up @@ -1959,7 +1962,7 @@ export class HelloWorldModel extends Observable {

public doSetUserId(): void {
// just for fun: showing usage of 'firebase.crashlytics' instead of 'firebaseCrashlytics'
firebase.crashlytics.setUserId("user#42");
firebaseCrashlytics.setUserId("user#42");

alert({
title: "User id changed",
Expand Down
9 changes: 0 additions & 9 deletions demo/app/vendor-platform.android.ts

This file was deleted.

3 changes: 0 additions & 3 deletions demo/app/vendor-platform.ios.ts

This file was deleted.

Empty file removed demo/app/vendor-platform.ts
Empty file.
10 changes: 0 additions & 10 deletions demo/app/vendor.ts

This file was deleted.

17 changes: 8 additions & 9 deletions demo/package.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
{
"dependencies": {
"firebase-functions": "^2.0.5",
"@nativescript/firebase": "file:../src",
"nativescript-theme-core": "^1.0.4",
"@nativescript/core": "~7.0.13",
"@nativescript/firebase": "file:../publish/package/nativescript-firebase-11.1.1.tgz",
"@nativescript/unit-test-runner": "~1.0.2",
"@nativescript/core": "7.0.0",
"@nativescript/webpack": "~3.0.0"
"firebase-functions": "^2.0.5",
"nativescript-theme-core": "^1.0.4"
},
"devDependencies": {
"@nativescript/android": "7.0.1",
"@nativescript/ios": "7.0.4",
"@nativescript/types": "~7.0.0",
"@nativescript/types": "~7.0.4",
"@nativescript/webpack": "~3.0.8",
"@types/jasmine": "~2.8.0",
"babel-traverse": "6.12.0",
"babel-types": "6.11.1",
Expand All @@ -19,11 +20,9 @@
"karma": "4.1.0",
"karma-jasmine": "2.0.1",
"karma-nativescript-launcher": "^0.4.0",
"karma-webpack": "3.0.5",
"lazy": "1.0.11",
"nativescript-css-loader": "~0.26.0",
"tslint": "~5.4.3",
"typescript": "~4.0.0"
"typescript": "~4.0.5"
},
"scripts": {
"build.plugin": "cd ../src && npm run build",
Expand Down
5 changes: 4 additions & 1 deletion docs/CRASHLYTICS.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ Then produce a crash, and it can easily take a day before that screen changes (l
Send a native iOS or Android exception to Crashlytics.

```typescript
// either import like this:
// for NativeScript 7, import like this:
import { crashlytics } from "@nativescript/firebase/crashlytics";

// for older versions of NativeScript, either import like this:
import { crashlytics } from "nativescript-plugin-firebase"; // and do: crashlytics.sendCrashLog
// or this:
import { crashlytics as firebaseCrashlytics } from "nativescript-plugin-firebase"; // and do: firebaseCrashlytics.sendCrashLog
Expand Down
6 changes: 3 additions & 3 deletions src/app/functions/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { functions as fNamepspace } from "../../firebase";
import { firebaseFunctions as fNamespace } from "../../firebase";

export namespace functions {
// tslint:disable-next-line:class-name
export class Functions {
httpsCallable<I, O>(functionName: string, region?: fNamepspace.SupportedRegions) {
return fNamepspace.httpsCallable<I, O>(functionName, region);
httpsCallable<I, O>(functionName: string, region?: fNamespace.SupportedRegions) {
return fNamespace.httpsCallable<I, O>(functionName, region);
}
}
}
Loading

0 comments on commit 4a8089b

Please sign in to comment.