Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(lint, ios): fix xcode warnings wherever possible #6061

Merged
merged 12 commits into from
Feb 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/scripts/functions/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import * as functions from 'firebase-functions';
//
export const helloWorld = functions.https.onRequest((request, response) => {
functions.logger.info('Hello logs!', { structuredData: true });
response.send('Hello from Firebase!');
response.send('{ "data": "Hello from Firebase!" }');
});

export { testFunctionCustomRegion } from './testFunctionCustomRegion';
Expand Down
4 changes: 2 additions & 2 deletions packages/app/ios/RNFBApp/RNFBPreferences.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@

- (void)setBooleanValue:(NSString *)key boolValue:(BOOL)boolValue;

- (void)setIntegerValue:(NSString *)key integerValue:(NSInteger *)integerValue;
- (void)setIntegerValue:(NSString *)key integerValue:(NSInteger)integerValue;

- (void)setStringValue:(NSString *)key stringValue:(NSString *)stringValue;

- (NSString *)getStringValue:(NSString *)key defaultValue:(NSString *)defaultValue;

- (NSInteger *)getIntegerValue:(NSString *)key defaultValue:(NSInteger *)defaultValue;
- (NSInteger)getIntegerValue:(NSString *)key defaultValue:(NSInteger)defaultValue;

- (NSDictionary *)getAll;

Expand Down
6 changes: 3 additions & 3 deletions packages/app/ios/RNFBApp/RNFBPreferences.m
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,14 @@ - (void)setBooleanValue:(NSString *)key boolValue:(BOOL)boolValue {
[_userDefaults synchronize];
}

- (void)setIntegerValue:(NSString *)key integerValue:(NSInteger *)integerValue {
- (void)setIntegerValue:(NSString *)key integerValue:(NSInteger)integerValue {
[_userDefaults setInteger:(NSInteger)integerValue forKey:key];
[_userDefaults synchronize];
}

- (NSInteger *)getIntegerValue:(NSString *)key defaultValue:(NSInteger *)defaultValue {
- (NSInteger)getIntegerValue:(NSString *)key defaultValue:(NSInteger)defaultValue {
if ([_userDefaults objectForKey:key] == nil) return defaultValue;
return (NSInteger *)[_userDefaults integerForKey:key];
return [_userDefaults integerForKey:key];
}

- (NSString *)getStringValue:(NSString *)key defaultValue:(NSString *)defaultValue {
Expand Down
5 changes: 5 additions & 0 deletions packages/auth/ios/RNFBAuth/RNFBAuthModule.m
Original file line number Diff line number Diff line change
Expand Up @@ -626,6 +626,11 @@ - (void)invalidate {
case FIRActionCodeOperationEmailLink:
actionType = @"EMAIL_SIGNIN";
break;
case FIRActionCodeOperationVerifyAndChangeEmail:
case FIRActionCodeOperationRevertSecondFactorAddition:
default:
actionType = @"ERROR";
break;
}

NSMutableDictionary *data = [NSMutableDictionary dictionary];
Expand Down
4 changes: 2 additions & 2 deletions packages/database/ios/RNFBDatabase/RNFBDatabaseCommon.m
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ + (void)setDatabaseConfig:(FIRDatabase *)firDatabase dbURL:(NSString *)dbURL {

// Persistence cache size
if ([preferences contains:DATABASE_PERSISTENCE_CACHE_SIZE]) {
NSInteger *cacheSizeBytes = [preferences getIntegerValue:DATABASE_PERSISTENCE_CACHE_SIZE
defaultValue:(NSInteger *)10000000];
NSInteger cacheSizeBytes = [preferences getIntegerValue:DATABASE_PERSISTENCE_CACHE_SIZE
defaultValue:10000000];
[firDatabase setPersistenceCacheSizeBytes:(NSUInteger)cacheSizeBytes];
}

Expand Down
5 changes: 3 additions & 2 deletions packages/database/ios/RNFBDatabase/RNFBDatabaseModule.m
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,9 @@ - (dispatch_queue_t)methodQueue {
RCT_EXPORT_METHOD(setPersistenceCacheSizeBytes
: (FIRApp *)firebaseApp
: (NSString *)dbURL
: (NSInteger *)bytes) {
[[RNFBPreferences shared] setIntegerValue:DATABASE_PERSISTENCE_CACHE_SIZE integerValue:bytes];
: (NSNumber *_Nonnull)bytes) {
[[RNFBPreferences shared] setIntegerValue:DATABASE_PERSISTENCE_CACHE_SIZE
integerValue:[bytes intValue]];
}

@end
2 changes: 1 addition & 1 deletion packages/database/ios/RNFBDatabase/RNFBDatabaseQuery.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

- (BOOL)hasListeners;

- (void)addEventListener:(NSString *)eventRegistrationKey:(FIRDatabaseHandle)listener;
- (void)addEventListener:(NSString *)eventRegistrationKey handle:(FIRDatabaseHandle)handle;

- (void)removeEventListener:(NSString *)eventRegistrationKey;

Expand Down
4 changes: 2 additions & 2 deletions packages/database/ios/RNFBDatabase/RNFBDatabaseQuery.m
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@ - (id)getIdValue:(NSString *)value type:(NSString *)type {
}
}

- (void)addEventListener:(NSString *)eventRegistrationKey:(FIRDatabaseHandle)listener {
_listeners[eventRegistrationKey] = @(listener);
- (void)addEventListener:(NSString *)eventRegistrationKey handle:(FIRDatabaseHandle)handle {
_listeners[eventRegistrationKey] = @(handle);
}

- (void)removeEventListener:(NSString *)eventRegistrationKey {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ - (void)addEventListener:(RNFBDatabaseQuery *)databaseQuery
FIRDatabaseHandle handle = [databaseQuery.query observeEventType:firDataEventType
andPreviousSiblingKeyWithBlock:andPreviousSiblingKeyWithBlock
withCancelBlock:errorBlock];
[databaseQuery addEventListener:eventRegistrationKey:handle];
[databaseQuery addEventListener:eventRegistrationKey handle:handle];
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ - (id)init {
[RNFBDatabaseCommon getReferenceForDatabase:firDatabase path:path];

id runTransactionBlock = ^FIRTransactionResult *(FIRMutableData *currentData) {
dispatch_barrier_async(_transactionQueue, ^{
dispatch_barrier_async(self->_transactionQueue, ^{
[transactions setValue:transactionState forKey:[transactionId stringValue]];

[[RNFBRCTEventEmitter shared]
Expand All @@ -94,7 +94,7 @@ - (id)init {
BOOL abort = [transactionState valueForKey:@"abort"] || timedout;
id value = [transactionState valueForKey:@"value"];

dispatch_barrier_async(_transactionQueue, ^{
dispatch_barrier_async(self->_transactionQueue, ^{
[transactions removeObjectForKey:[transactionId stringValue]];
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,15 +88,17 @@ - (BOOL)application:(UIApplication *)application

- (BOOL)application:(UIApplication *)application
continueUserActivity:(NSUserActivity *)userActivity
restorationHandler:(void (^)(NSArray *restorableObjects))restorationHandler {
restorationHandler:
(void (^_Nonnull __strong)(NSArray<id<UIUserActivityRestoring>>
*_Nullable __strong restorableObjects))restorationHandler {
__block BOOL retried = NO;

id completion = ^(FIRDynamicLink *_Nullable dynamicLink, NSError *_Nullable error) {
if (!error && dynamicLink && dynamicLink.url) {
if (_initialLinkUrl == nil) {
_initialLinkUrl = dynamicLink.url.absoluteString;
_initialLinkMinimumAppVersion = dynamicLink.minimumAppVersion;
_initialLinkUtmParametersDictionary = dynamicLink.utmParametersDictionary;
if (self->_initialLinkUrl == nil) {
self->_initialLinkUrl = dynamicLink.url.absoluteString;
self->_initialLinkMinimumAppVersion = dynamicLink.minimumAppVersion;
self->_initialLinkUtmParametersDictionary = dynamicLink.utmParametersDictionary;
}
[[RNFBRCTEventEmitter shared]
sendEventWithName:LINK_RECEIVED_EVENT
Expand All @@ -109,7 +111,7 @@ - (BOOL)application:(UIApplication *)application
? @{}
: dynamicLink.utmParametersDictionary,
}];
}
};

// Per Apple Tech Support, a network failure could occur when returning from background on
// iOS 12. https://github.com/AFNetworking/AFNetworking/issues/4279#issuecomment-447108981 So
Expand Down
6 changes: 3 additions & 3 deletions packages/firestore/ios/RNFBFirestore/RNFBFirestoreCommon.m
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,14 @@ + (void)setFirestoreSettings:(FIRFirestore *)firestore appName:(NSString *)appNa
firestoreSettings.dispatchQueue = [self getFirestoreQueue];

NSString *cacheKey = [NSString stringWithFormat:@"%@_%@", FIRESTORE_CACHE_SIZE, appName];
NSInteger *size = [preferences getIntegerValue:cacheKey defaultValue:0];
NSInteger size = [preferences getIntegerValue:cacheKey defaultValue:0];

if (size == (NSInteger *)-1) {
if (size == -1) {
firestoreSettings.cacheSizeBytes = kFIRFirestoreCacheSizeUnlimited;
} else if (size == 0) {
firestoreSettings.cacheSizeBytes = firestore.settings.cacheSizeBytes;
} else {
firestoreSettings.cacheSizeBytes = (int64_t)size;
firestoreSettings.cacheSizeBytes = size;
}

NSString *hostKey = [NSString stringWithFormat:@"%@_%@", FIRESTORE_HOST, appName];
Expand Down
10 changes: 5 additions & 5 deletions packages/functions/__tests__/functions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ describe('Cloud Functions', function () {

describe('useFunctionsEmulator()', function () {
it('useFunctionsEmulator -> uses 10.0.2.2', function () {
functions().useFunctionsEmulator('http://localhost');
functions().useEmulator('localhost', 5001);

// @ts-ignore
expect(functions()._useFunctionsEmulatorOrigin).toBe('http://10.0.2.2');
expect(functions()._useFunctionsEmulatorHost).toBe('10.0.2.2');

functions().useFunctionsEmulator('http://127.0.0.1');
functions().useEmulator('127.0.0.1', 5001);

// @ts-ignore
expect(functions()._useFunctionsEmulatorOrigin).toBe('http://10.0.2.2');
expect(functions()._useFunctionsEmulatorHost).toBe('10.0.2.2');
});

it('prefers emulator to custom domain', function () {
Expand All @@ -30,7 +30,7 @@ describe('Cloud Functions', function () {
functions.useFunctionsEmulator('http://10.0.2.2');

// @ts-ignore
expect(functions._useFunctionsEmulatorOrigin).toBe('http://10.0.2.2');
expect(functions._useFunctionsEmulatorHost).toBe('10.0.2.2');
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public class UniversalFirebaseFunctionsModule extends UniversalFirebaseModule {
}

Task<Object> httpsCallable(
String appName, String region, String origin, String name, Object data, ReadableMap options) {
String appName, String region, String host, Integer port, String name, Object data, ReadableMap options) {
return Tasks.call(
getExecutor(),
() -> {
Expand All @@ -52,8 +52,8 @@ Task<Object> httpsCallable(
httpReference.setTimeout((long) options.getInt("timeout"), TimeUnit.SECONDS);
}

if (origin != null) {
functionsInstance.useFunctionsEmulator(origin);
if (host != null) {
functionsInstance.useEmulator(host, port);
}

return Tasks.await(httpReference.call(data)).getData();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,15 @@ public class ReactNativeFirebaseFunctionsModule extends ReactNativeFirebaseModul
public void httpsCallable(
String appName,
String region,
String origin,
String host,
Integer port,
String name,
ReadableMap wrapper,
ReadableMap options,
Promise promise) {
Task<Object> callMethodTask =
module.httpsCallable(
appName, region, origin, name, wrapper.toHashMap().get(DATA_KEY), options);
appName, region, host, port, name, wrapper.toHashMap().get(DATA_KEY), options);

// resolve
callMethodTask.addOnSuccessListener(
Expand Down
30 changes: 23 additions & 7 deletions packages/functions/e2e/functions.e2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,18 +69,34 @@ describe('functions()', function () {
const response = await functionRunner();
response.data.should.equal('null');
});
});

it('useFunctionsEmulator', async function () {
const region = 'europe-west2';
const fnName = 'invertaseReactNativeFirebaseFunctionsEmulator';
describe('emulator', function () {
it('configures functions emulator via deprecated method with no port', async function () {
const region = 'us-central1';
const fnName = 'helloWorld';
const functions = firebase.app().functions(region);
functions.useFunctionsEmulator('http://localhost');
const response = await functions.httpsCallable(fnName)();
response.data.should.equal('Hello from Firebase!');
});

functions.useFunctionsEmulator('http://api.rnfirebase.io');

it('configures functions emulator via deprecated method with port', async function () {
const region = 'us-central1';
const fnName = 'helloWorld';
const functions = firebase.app().functions(region);
functions.useFunctionsEmulator('http://localhost:5001');
const response = await functions.httpsCallable(fnName)();
response.data.should.equal('Hello from Firebase!');
});

response.data.region.should.equal(region);
response.data.fnName.should.equal(fnName);
it('configures functions emulator', async function () {
const region = 'us-central1';
const fnName = 'helloWorld';
const functions = firebase.app().functions(region);
functions.useEmulator('localhost', 5001);
const response = await functions.httpsCallable(fnName)();
response.data.should.equal('Hello from Firebase!');
});
});

Expand Down
9 changes: 5 additions & 4 deletions packages/functions/ios/RNFBFunctions/RNFBFunctionsModule.m
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ @implementation RNFBFunctionsModule

RCT_EXPORT_METHOD(httpsCallable
: (FIRApp *)firebaseApp customUrlOrRegion
: (NSString *)customUrlOrRegion origin
: (NSString *)origin name
: (NSString *)customUrlOrRegion host
: (NSString *)host port
: (NSNumber *_Nonnull)port name
: (NSString *)name wrapper
: (NSDictionary *)wrapper options
: (NSDictionary *)options resolver
Expand All @@ -45,8 +46,8 @@ @implementation RNFBFunctionsModule
? [FIRFunctions functionsForApp:firebaseApp customDomain:customUrlOrRegion]
: [FIRFunctions functionsForApp:firebaseApp region:customUrlOrRegion];

if (origin != nil) {
[functions useFunctionsEmulatorOrigin:origin];
if (host != nil) {
[functions useEmulatorWithHost:host port:[port intValue]];
}

FIRHTTPSCallable *callable = [functions HTTPSCallableWithName:name];
Expand Down
24 changes: 24 additions & 0 deletions packages/functions/lib/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -356,9 +356,33 @@ export namespace FirebaseFunctionsTypes {
* If you want to use the emulator on a real android device, you will need to specify the actual host
* computer IP address.
*
* @deprecated prefer useEmulator instead
* @param origin url of the local emulator started via firebase tools "http://localhost:5001"
*/
useFunctionsEmulator(origin: string): void;

/**
* Changes this instance to point to a Cloud Functions emulator running locally.
*
* See https://firebase.google.com/docs/functions/local-emulator
*
* #### Example
*
* ```js
* if (__DEV__) {
* firebase.functions().useEmulator('localhost', 5001);
* }
* ```
*
* Note: on android, hosts 'localhost' and '127.0.0.1' are automatically remapped to '10.0.2.2' (the
* "host" computer IP address for android emulators) to make the standard development experience easy.
* If you want to use the emulator on a real android device, you will need to specify the actual host
* computer IP address.
*
* @param host hostname of the local emulator started via firebase tools, ex. "localhost"
* @param port port of the local emulator started via firebase tools, ex. 5001
*/
useEmulator(host: string, port: number): void;
}
}

Expand Down
Loading