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

Commit

Permalink
chore: latest updates
Browse files Browse the repository at this point in the history
  • Loading branch information
NathanWalker committed Sep 1, 2020
1 parent d165863 commit 4296803
Show file tree
Hide file tree
Showing 23 changed files with 1,579 additions and 1,053 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ build/
*.tgz
*.log.*
src/**/*.d.ts
src/**/*.map
src/platforms/ios_lib/TNSMLKitCamera/TNSMLKitCamera.xcodeproj/project.xcworkspace
src/platforms/ios_lib/TNSMLKitCamera/TNSMLKitCamera.xcodeproj/xcuserdata
src/platforms/ios/Podfile
Expand Down
2 changes: 1 addition & 1 deletion publish/scripts/installer.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ var directories = {

console.log('NativeScript Firebase Plugin Installation');

var appRoot = "../../";
var appRoot = "../../../";
var pluginConfigFile = "firebase.nativescript.json";
var pluginConfigPath = path.join(appRoot, pluginConfigFile);
var config = {};
Expand Down
2 changes: 2 additions & 0 deletions src/.npmignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
*.map
*.ts
!*.d.ts
ns-transform-native-classes.*
tsconfig.json
references.d.ts
platforms/android/libraryproject/
Expand All @@ -11,3 +12,4 @@ platforms/android/typings/
platforms/web
platforms/ios/Podfile
platforms/android/include.gradle
*.tgz
3 changes: 3 additions & 0 deletions src/admob/admob.ios.ts
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,7 @@ function _getBannerType(size): any {
}
}

@NativeClass()
class GADInterstitialDelegateImpl extends NSObject implements GADInterstitialDelegate {
public static ObjCProtocols = [];
private options: InterstitialOptions;
Expand Down Expand Up @@ -381,6 +382,7 @@ class GADInterstitialDelegateImpl extends NSObject implements GADInterstitialDel
}
}

@NativeClass()
class GADBannerViewDelegateImpl extends NSObject implements GADBannerViewDelegate {
public static ObjCProtocols = [];
private onAdCloseCallback: () => void;
Expand Down Expand Up @@ -419,6 +421,7 @@ class GADBannerViewDelegateImpl extends NSObject implements GADBannerViewDelegat
}
}

@NativeClass()
class GADRewardBasedVideoAdDelegateImpl extends NSObject implements GADRewardBasedVideoAdDelegate {
public static ObjCProtocols = [];
_loaded: () => void;
Expand Down
23 changes: 11 additions & 12 deletions src/app/auth/index.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
import * as firebase from "../../firebase";
import { FirebaseEmailLinkActionCodeSettings, LoginType, User, Unsubscribe } from "../../firebase";
import { firebase } from "../../firebase";

export namespace auth {
export class Auth {
private authStateChangedHandler;
private authStateOnErrorHandler;
public currentUser: User;
public currentUser: firebase.User;
public languageCode: string | null;

private loginHelper(options: firebase.LoginOptions) {
return new Promise((resolve, reject) => {
firebase.login(options)
.then((user: User) => {
.then((user: firebase.User) => {
this.currentUser = user;
this.authStateChangedHandler && this.authStateChangedHandler(user);
resolve({
Expand Down Expand Up @@ -45,7 +44,7 @@ export namespace auth {

// Completed will never be called, but it is here to closely follow the web api interface.
// When called, the callback handler will be passed in the currentUser or undefined if not signed in
public onAuthStateChanged(handler: (user: User) => void, error?: (err) => any, completed?: Unsubscribe): Unsubscribe {
public onAuthStateChanged(handler: (user: firebase.User) => void, error?: (err) => any, completed?: firebase.Unsubscribe): firebase.Unsubscribe {
this.authStateChangedHandler = handler;
if (error) this.authStateOnErrorHandler = error;
console.log(">> added onAuthStateChanged handler");
Expand Down Expand Up @@ -92,7 +91,7 @@ export namespace auth {

public signInWithEmailAndPassword(email: string, password: string): Promise<any> {
const emailOption: firebase.LoginOptions = {
type: LoginType.PASSWORD,
type: firebase.LoginType.PASSWORD,
passwordOptions: {
email: email,
password: password
Expand All @@ -103,7 +102,7 @@ export namespace auth {

public signInWithCustomToken(token: string): Promise<any> {
const customTokenOption: firebase.LoginOptions = {
type: LoginType.CUSTOM,
type: firebase.LoginType.CUSTOM,
customOptions: {
token: token
}
Expand All @@ -113,14 +112,14 @@ export namespace auth {

public signInAnonymously(): Promise<any> {
const anonymousOption: firebase.LoginOptions = {
type: LoginType.ANONYMOUS
type: firebase.LoginType.ANONYMOUS
};
return this.loginHelper(anonymousOption);
}

public sendSignInLinkToEmail(email: string, actionCodeSettings: FirebaseEmailLinkActionCodeSettings): Promise<any> {
public sendSignInLinkToEmail(email: string, actionCodeSettings: firebase.FirebaseEmailLinkActionCodeSettings): Promise<any> {
const sendSignInLinklOption: firebase.LoginOptions = {
type: LoginType.EMAIL_LINK,
type: firebase.LoginType.EMAIL_LINK,
emailLinkOptions: {
email: email,
url: actionCodeSettings.url,
Expand All @@ -140,12 +139,12 @@ export namespace auth {
return this.loginHelper(signInWithEmailOption);
}

public createUserWithEmailAndPassword(email: string, password: string): Promise<User> {
public createUserWithEmailAndPassword(email: string, password: string): Promise<firebase.User> {
return new Promise((resolve, reject) => {
firebase.createUser({
email: email,
password: password
}).then((user: User) => {
}).then((user: firebase.User) => {
this.currentUser = user;
resolve(user);
}).catch(err => reject(err));
Expand Down
7 changes: 3 additions & 4 deletions src/app/database/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import * as firebase from "../../firebase";
import { AddEventListenerResult, FBData } from "../../firebase";
import { firebase } from "../../firebase";
import { nextPushId } from "./util/NextPushId";

export module database {
Expand Down Expand Up @@ -42,7 +41,7 @@ export module database {
};

firebase.addValueEventListener(onValueEvent, this.path).then(
(result: AddEventListenerResult) => {
(result: firebase.AddEventListenerResult) => {
if (!Query.registeredListeners.has(this.path)) {
Query.registeredListeners.set(this.path, []);
}
Expand Down Expand Up @@ -85,7 +84,7 @@ export module database {
});
}

private getOnValueEventHandler(): (data: FBData) => void {
private getOnValueEventHandler(): (data: firebase.FBData) => void {
return result => {
const callbacks = Query.registeredCallbacks.get(this.path);
callbacks && callbacks.map(callback => {
Expand Down
2 changes: 1 addition & 1 deletion src/app/firestore/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as firebase from "../../firebase";
import { firebase } from "../../firebase";
// import * as firebaseSdk from 'firebase/app';

export namespace firestore {
Expand Down
2 changes: 1 addition & 1 deletion src/app/functions/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as firebase from "../../firebase";
import { firebase } from "../../firebase";

export namespace functions {
// tslint:disable-next-line:class-name
Expand Down
2 changes: 1 addition & 1 deletion src/app/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Use 'const firebase = require("nativescript-plugin-firebase/app")'
*/

import * as firebase from "../firebase";
import { firebase } from "../firebase";
import { auth as firebaseAuthModule } from "./auth";
import { database as firebaseDatabaseModule } from "./database";
import { firestore as firebaseFirestoreModule } from "./firestore";
Expand Down
17 changes: 9 additions & 8 deletions src/firebase-common.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { prompt, ApplicationSettings } from "@nativescript/core";
import { firestore } from "./firebase";
import { firebase as fbNamespace } from "./firebase";
import * as admob from "./admob/admob";
import * as analytics from "./analytics/analytics";
import * as crashlytics from "./crashlytics/crashlytics";
Expand All @@ -9,15 +9,15 @@ import * as mlkit from "./mlkit";

// note that this implementation is overridden for iOS
export class FieldValue {
constructor(public type: firestore.FieldValueType,
constructor(public type: fbNamespace.firestore.FieldValueType,
public value: any) {
}

static serverTimestamp = () => "SERVER_TIMESTAMP";
static delete = () => "DELETE_FIELD";
static arrayUnion = (...elements: any[]) => new FieldValue("ARRAY_UNION", elements);
static arrayRemove = (...elements: any[]) => new FieldValue("ARRAY_REMOVE", elements);
static increment = (n: number) => new firebase.firestore.FieldValue("INCREMENT", n);
static increment = (n: number) => new fbNamespace.firestore.FieldValue("INCREMENT", n);
}

export class GeoPoint {
Expand Down Expand Up @@ -214,18 +214,19 @@ export const firebase: any = {
return result;
}
};
export const firestore = firebase.firestore;

export abstract class DocumentSnapshot implements firestore.DocumentSnapshot {
public data: () => firestore.DocumentData;
export abstract class DocumentSnapshot {
public data: () => firebase.firestore.DocumentData;

constructor(public id: string,
public exists: boolean,
documentData: firestore.DocumentData,
public ref: firestore.DocumentReference) {
documentData: firebase.firestore.DocumentData,
public ref: firebase.firestore.DocumentReference) {
this.data = () => exists ? documentData : undefined;
}
}

export function isDocumentReference(object: any): object is firestore.DocumentReference {
export function isDocumentReference(object: any): object is firebase.firestore.DocumentReference {
return object && object.discriminator === "docRef";
}
Loading

0 comments on commit 4296803

Please sign in to comment.