Fix iOS RCTSwiftLog naming collision with rive-react-native

This commit is contained in:
Liam Potter
2022-09-26 00:10:21 +01:00
parent 2349fad25f
commit a7f0efd27f
4 changed files with 12 additions and 9 deletions

View File

@@ -0,0 +1,11 @@
#import <Foundation/Foundation.h>
@interface RCTVideoSwiftLog : NSObject
+ (void)error:(NSString * _Nonnull)message file:(NSString * _Nonnull)file line:(NSUInteger)line;
+ (void)warn:(NSString * _Nonnull)message file:(NSString * _Nonnull)file line:(NSUInteger)line;
+ (void)info:(NSString * _Nonnull)message file:(NSString * _Nonnull)file line:(NSUInteger)line;
+ (void)log:(NSString * _Nonnull)message file:(NSString * _Nonnull)file line:(NSUInteger)line;
+ (void)trace:(NSString * _Nonnull)message file:(NSString * _Nonnull)file line:(NSUInteger)line;
@end

View File

@@ -0,0 +1,32 @@
#import <React/RCTLog.h>
#import "RCTVideoSwiftLog.h"
@implementation RCTVideoSwiftLog
+ (void)info:(NSString *)message file:(NSString *)file line:(NSUInteger)line
{
_RCTLogNativeInternal(RCTLogLevelInfo, file.UTF8String, (int)line, @"%@", message);
}
+ (void)warn:(NSString *)message file:(NSString *)file line:(NSUInteger)line
{
_RCTLogNativeInternal(RCTLogLevelWarning, file.UTF8String, (int)line, @"%@", message);
}
+ (void)error:(NSString *)message file:(NSString *)file line:(NSUInteger)line
{
_RCTLogNativeInternal(RCTLogLevelError, file.UTF8String, (int)line, @"%@", message);
}
+ (void)log:(NSString *)message file:(NSString *)file line:(NSUInteger)line
{
_RCTLogNativeInternal(RCTLogLevelInfo, file.UTF8String, (int)line, @"%@", message);
}
+ (void)trace:(NSString *)message file:(NSString *)file line:(NSUInteger)line
{
_RCTLogNativeInternal(RCTLogLevelTrace, file.UTF8String, (int)line, @"%@", message);
}
@end

View File

@@ -0,0 +1,53 @@
//
// RCTLog.swift
// WebViewExample
//
// Created by Jimmy Dee on 4/5/17.
// Copyright © 2017 Branch Metrics. All rights reserved.
//
/*
* Under at least some conditions, output from NSLog has been unavailable in the RNBranch module.
* Hence that module uses the RCTLog macros from <React/RCTLog.h>. The React logger is nicer than
* NSLog anyway, since it provides log levels with runtime filtering, file and line context and
* an identifier for the thread that logged the message.
*
* This wrapper lets you use functions with the same name in Swift. For example:
*
* RCTLogInfo("application launched")
*
* generates
*
* 2017-04-06 12:31:09.611 [info][tid:main][AppDelegate.swift:18] application launched
*
* This is currently part of this sample app. There may be some issues integrating it into an
* Objective-C library, either react-native-branch or react-native itself, but it may find its
* way into one or the other eventually. Feel free to reuse it as desired.
*/
func RCTLogError(_ message: String, _ file: String=#file, _ line: UInt=#line) {
RCTVideoSwiftLog.error(message, file: file, line: line)
}
func RCTLogWarn(_ message: String, _ file: String=#file, _ line: UInt=#line) {
RCTVideoSwiftLog.warn(message, file: file, line: line)
}
func RCTLogInfo(_ message: String, _ file: String=#file, _ line: UInt=#line) {
RCTVideoSwiftLog.info(message, file: file, line: line)
}
func RCTLog(_ message: String, _ file: String=#file, _ line: UInt=#line) {
RCTVideoSwiftLog.log(message, file: file, line: line)
}
func RCTLogTrace(_ message: String, _ file: String=#file, _ line: UInt=#line) {
RCTVideoSwiftLog.trace(message, file: file, line: line)
}
func DebugLog(_ message: String) {
#if DEBUG
print(message)
#endif
}