This commit is contained in:
wushenghua
2017-04-10 17:56:27 +08:00
parent ab87ffadbe
commit 9159b73d76
914 changed files with 146352 additions and 0 deletions
+64
View File
@@ -0,0 +1,64 @@
//
// ASHRNViewController.h
// ASHReactNative
//
// Created by xmfish on 17/4/10.
// Copyright © 2017年 ash. All rights reserved.
//
#import <UIKit/UIKit.h>
@class ASHRNView;
@interface ASHRNViewController : UIViewController
/**
通过包url初始化
@param bundleURL 包地址
@return IMYRNViewController
*/
- (instancetype)initWithBundleURL:(NSString *)bundleURL;
/**
通过包url读取包地址,并且展示 modelName 的内容。
@param bundleURL 包地址
@param modelName 页面名称
@return IMYRNViewController
*/
- (instancetype)initWithBundleURL:(NSString *)bundleURL modelName:(NSString *)modelName;
/**
加载本地bundle包
@param bundleName 本地的bundle名称
@return IMYRNViewController
*/
- (instancetype)initWithBundleName:(NSString *)bundleName;
/**
加载本地bundle包
@param bundleName bundleName 本地的bundle名称
@param modelName 页面名称
@return IMYRNViewController
*/
- (instancetype)initWithBundleName:(NSString *)bundleName modelName:(NSString *)modelName;
/**
网络路径
*/
@property (nonatomic, copy, readonly) NSString *bundleURL;
/**
读取的页面,默认是 index。
*/
@property(nonatomic,copy)NSString *moduleName;
@property(nonatomic,copy)NSString *navTitle;
//本地包名
@property(nonatomic,copy)NSString *bundleName;
@property(nonatomic,strong)NSDictionary *initialProperties;/**< RN要用的参数:请求参数,埋点,自定义... */
@property(nonatomic,assign)BOOL isNeedReloadPage;
@property(nonatomic,strong,readonly)ASHRNView *rnView;
@end
+127
View File
@@ -0,0 +1,127 @@
//
// ASHRNViewController.m
// ASHReactNative
//
// Created by xmfish on 17/4/10.
// Copyright © 2017年 ash. All rights reserved.
//
#import "ASHRNViewController.h"
#import "ASHRNView.h"
#import "NSString+Util.h"
#import <MBProgressHUD.h>
@interface ASHRNViewController ()<ASHRNViewDelegate>
@property(nonatomic,strong)ASHRNView *rnView;
@property(nonatomic,strong)UIActivityIndicatorView *indicatorView;
@end
@implementation ASHRNViewController
@synthesize bundleURL = _bundleURL;
@synthesize moduleName = _moduleName;
- (instancetype)initWithBundleURL:(NSString *)bundleURL
{
NSDictionary* dic = [bundleURL ash_queryDictionary];
NSString* model = dic[@"model"];
if (!model.length) {
model = @"index";
}
return [self initWithBundleURL:bundleURL modelName:model];
}
- (instancetype)initWithBundleURL:(NSString *)bundleURL modelName:(NSString *)modelName
{
self = [super init];
if (self) {
_bundleURL = bundleURL;
if (!modelName.length) {
NSDictionary* dic = [bundleURL ash_queryDictionary];
modelName = dic[@"model"];
if (!modelName.length) {
modelName = @"index";
}
}
_moduleName = modelName;
}
return self;
}
- (instancetype)initWithBundleName:(NSString *)bundleName
{
return [self initWithBundleName:bundleName modelName:@"index"];
}
- (instancetype)initWithBundleName:(NSString *)bundleName modelName:(NSString *)modelName
{
self = [super init];
if (self) {
_bundleName = bundleName;
_moduleName = modelName;
}
return self;
}
- (void)loadView
{
[super loadView];
[self setupRNView];
[self setupCaptionView];
}
- (void)setupRNView
{
self.rnView = [[ASHRNView alloc] initWithFrame:self.view.bounds];
self.rnView.viewDelegate = self;
self.rnView.initialProperties = self.initialProperties;
self.rnView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
[self.view addSubview:self.rnView];
}
- (void)setupCaptionView
{
self.indicatorView = [UIActivityIndicatorView new];
self.indicatorView.activityIndicatorViewStyle = UIActivityIndicatorViewStyleGray;
}
- (void)viewDidLoad
{
[super viewDidLoad];
self.edgesForExtendedLayout = UIRectEdgeNone;
self.view.backgroundColor = [UIColor whiteColor];
if (self.navTitle) {
self.navigationItem.title = self.navTitle;
}
[self loadBundle];
}
- (void)loadBundle
{
if (self.bundleURL) {
[self.rnView loadBundle:self.bundleURL withModelName:self.moduleName];
} else {
[self.rnView loadBundleName:self.bundleName modelName:self.moduleName];
}
}
#pragma mark IMYRNViewDelegate
- (void)rnViewDidCreated:(ASHRNView *)weexView
{
[MBProgressHUD showHUDAddedTo:self.view animated:YES];
}
- (void)rnView:(ASHRNView *)rnView didFailed:(NSError *)error
{
[MBProgressHUD hideHUDForView:self.view animated:YES];
}
- (void)rnViewDidRenderFinish:(ASHRNView *)rnView
{
[MBProgressHUD hideHUDForView:self.view animated:YES];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
@end