2015-03-23 13:28:42 -07:00
|
|
|
/**
|
|
|
|
* Copyright (c) 2015-present, Facebook, Inc.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This source code is licensed under the BSD-style license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree. An additional grant
|
|
|
|
* of patent rights can be found in the PATENTS file in the same directory.
|
|
|
|
*/
|
2015-03-12 17:49:54 -07:00
|
|
|
|
|
|
|
#import "RCTSourceCode.h"
|
|
|
|
|
2015-08-28 05:45:26 -07:00
|
|
|
#import "RCTDefines.h"
|
2015-03-12 17:49:54 -07:00
|
|
|
#import "RCTAssert.h"
|
2015-04-20 14:04:53 -07:00
|
|
|
#import "RCTBridge.h"
|
2015-03-12 17:49:54 -07:00
|
|
|
#import "RCTUtils.h"
|
|
|
|
|
|
|
|
@implementation RCTSourceCode
|
|
|
|
|
2015-04-08 05:42:43 -07:00
|
|
|
RCT_EXPORT_MODULE()
|
|
|
|
|
2015-04-20 14:04:53 -07:00
|
|
|
@synthesize bridge = _bridge;
|
|
|
|
|
2015-08-28 05:45:26 -07:00
|
|
|
#if !RCT_DEV
|
|
|
|
- (void)setScriptText:(NSString *)scriptText {}
|
|
|
|
#endif
|
|
|
|
|
2015-04-08 08:52:48 -07:00
|
|
|
RCT_EXPORT_METHOD(getScriptText:(RCTResponseSenderBlock)successCallback
|
2015-07-14 03:51:22 -07:00
|
|
|
failureCallback:(RCTResponseErrorBlock)failureCallback)
|
2015-03-12 17:49:54 -07:00
|
|
|
{
|
2015-10-16 08:10:25 -07:00
|
|
|
if (RCT_DEV && self.scriptData && self.scriptURL) {
|
|
|
|
NSString *scriptText = [[NSString alloc] initWithData:self.scriptData encoding:NSUTF8StringEncoding];
|
|
|
|
|
|
|
|
successCallback(@[@{@"text": scriptText, @"url": self.scriptURL.absoluteString}]);
|
2015-03-12 17:49:54 -07:00
|
|
|
} else {
|
2015-07-14 03:51:22 -07:00
|
|
|
failureCallback(RCTErrorWithMessage(@"Source code is not available"));
|
2015-03-12 17:49:54 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-14 10:25:00 -08:00
|
|
|
- (NSDictionary<NSString *, id> *)constantsToExport
|
2015-09-02 13:51:53 -07:00
|
|
|
{
|
|
|
|
NSString *URL = self.bridge.bundleURL.absoluteString ?: @"";
|
|
|
|
return @{@"scriptURL": URL};
|
|
|
|
}
|
|
|
|
|
2015-03-12 17:49:54 -07:00
|
|
|
@end
|