8000 添加LViewController, 支持加载本地脚本 · pythonzz/LuaViewSDK@dbf7d40 · GitHub
[go: up one dir, main page]

Skip to content

Commit dbf7d40

Browse files
committed
添加LViewController, 支持加载本地脚本
1 parent 6fbff97 commit dbf7d40

File tree

8 files changed

+228
-97
lines changed
  • LuaViewSDK.xcodeproj
  • 8 files changed

    +228
    -97
    lines changed

    IOS/Demo/Demo/JHSLuaViewController.h

    Lines changed: 2 additions & 3 deletions
    Original file line numberDiff line numberDiff line change
    @@ -7,9 +7,8 @@
    77
    //
    88

    99
    #import <UIKit/UIKit.h>
    10+
    #import "LViewController.h"
    1011

    11-
    @interface JHSLuaViewController : UIViewController
    12-
    13-
    - (id)initWithSource:(NSString*) source;
    12+
    @interface JHSLuaViewController : LViewController
    1413

    1514
    @end

    IOS/Demo/Demo/JHSLuaViewController.m

    Lines changed: 14 additions & 93 deletions
    Original file line numberDiff line numberDiff line change
    @@ -15,125 +15,46 @@
    1515
    #import "JHSLVButton.h"
    1616
    #import "JHSLVImage.h"
    1717

    18+
    #import "AppDelegate.h"
    19+
    1820

    1921
    @interface JHSLuaViewController ()
    20-
    @property(nonatomic,strong) LView* lv;
    21-
    @property(nonatomic,strong) NSString* source;
    22-
    @property(nonatomic,strong) NSDate* sourceModifiyDate;
    23-
    @end
    2422

    25-
    #define iOS7 ([[[UIDevice currentDevice] systemVersion] compare:@"7.0"] != NSOrderedAscending)
    23+
    @end
    2624

    2725
    @implementation JHSLuaViewController
    2826

    29-
    - (void) dealloc{
    30-
    [self.lv releaseLuaView];
    31-
    }
    32-
    33-
    - (id)initWithSource:(NSString*) source{
    34-
    self = [super init];
    35-
    if (self) {
    36-
    self.source = source;
    37-
    }
    38-
    return self;
    39-
    }
    40-
    4127
    - (void)viewDidLoad {
    4228
    [super viewDidLoad];
    4329
    self.view.backgroundColor = [UIColor whiteColor];
    44-
    [self.navigationController setNavigationBarHidden:NO animated:YES];
    45-
    if( iOS7 ) {
    46-
    self.automaticallyAdjustsScrollViewInsets = NO;
    47-
    }
    4830

    49-
    // 创建LuaView
    50-
    [self createLuaView];
    31+
    [LVButton setDefaultStyle:[JHSLVButton class]];
    32+
    [LVImage setDefaultStyle:[JHSLVImage class]];
    33+
    [LVCollectionView setDefaultStyle:[JHSLVCollectionView class]];
    34+
    [LVTableView setDefaultStyle:[JHSLVTableView class]];
    5135

    5236
    //摇一摇本地代码
    5337
    [UIApplication sharedApplication].applicationSupportsShakeToEdit = YES;
    54-
    [self becomeFirstResponder];
    5538
    }
    5639

    57-
    -(void) createLuaView{
    40+
    - (void)willCreateLuaView {
    41+
    [super willCreateLuaView];
    42+
    5843
    while (self.view.subviews.count) {
    5944
    UIView* child = self.view.subviews.lastObject;
    6045
    [child removeFromSuperview];
    6146
    }
    62-
    [self.lv releaseLuaView];
    63-
    self.lv = nil;
    64-
    65-
    CGRect rect = self.view.bounds;
    66-
    rect.origin = CGPointZero;
    67-
    68-
    self.lv = [[LView alloc] initWithFrame:rect];
    69-
    self.lv.viewController = self;
    70-
    [self.view addSubview:self.lv];
    71-
    72-
    // 修改默认样式行为
    73-
    [LVButton setDefaultStyle:[JHSLVButton class]];
    74-
    [LVImage setDefaultStyle:[JHSLVImage class]];
    75-
    [LVCollectionView setDefaultStyle:[JHSLVCollectionView class]];
    76-
    [LVTableView setDefaultStyle:[JHSLVTableView class]];
    47+
    }
    48+
    49+
    - (void)didCreateLuaView:(LView *)view {
    50+
    [super didCreateLuaView:view];
    7751

    7852
    // 注册 用户面板类型
    7953
    self.lv[@"CustomError"] = [JHSLVCustomError class];
    8054
    self.lv[@"CustomLoading"] = [JHSLVCustomLoading class];
    8155

    8256
    // 注册 外部对象.
    8357
    self.lv[@"viewController"] = self;
    84-
    85-
    [self.lv runFile:self.source];// 量贩团页面
    86-
    }
    87-
    88-
    - (void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event {
    89-
    [self.lv motionBegan:motion withEvent:event];
    90-
    }
    91-
    92-
    // 摇一摇取消摇动
    93-
    - (void)motionCancelled:(UIEventSubtype)motion withEvent:(UIEvent *)event {
    94-
    [self.lv motionCancelled:motion withEvent:event];
    95-
    }
    96-
    97-
    // 摇一摇摇动结束
    98-
    - (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event {
    99-
    [self.lv motionEnded:motion withEvent:event];
    100-
    }
    101-
    102-
    -(void) viewWillAppear:(BOOL)animated{
    103-
    [super viewWillAppear:animated];
    104-
    [self.navigationController setNavigationBarHidden:NO animated:YES];
    105-
    106-
    [self.lv viewWillAppear];
    107-
    [self resetLuaViewFrame];
    108-
    }
    109-
    110-
    - (void) resetLuaViewFrame{
    111-
    CGRect rect = self.view.bounds;
    112-
    rect.origin = CGPointZero;
    113-
    if( iOS7 ) {
    114-
    rect.origin.y = 64;
    115-
    }
    116-
    self.lv.frame = rect;
    117-
    }
    118-
    119-
    -(void) viewDidAppear:(BOOL)animated{
    120-
    [super viewDidAppear:animated];
    121-
    [self resetLuaViewFrame];
    122-
    [self.lv viewDidAppear];
    123-
    }
    124-
    125-
    -(void) viewWillDisappear:(BOOL)animated{
    126-
    [super viewWillDisappear:animated];
    127-
    [self.lv viewWillDisAppear];
    128-
    }
    129-
    130-
    -(void) viewDidDisappear:(BOOL)animated{
    131-
    [super viewDidDisappear:animated];
    132-
    [self.lv viewDidDisAppear];
    133-
    }
    134-
    135-
    - (void)didReceiveMemoryWarning {
    136-
    [super didReceiveMemoryWarning];
    13758
    }
    13859

    13960
    - (UIStatusBarStyle)preferredStatusBarStyle {

    IOS/Demo/Demo/ViewController.m

    Lines changed: 3 additions & 1 deletion
    Original file line numberDiff line numberDiff line change
    @@ -55,6 +55,8 @@ - (void)viewDidLoad {
    5555
    // Test package
    5656
    [LVPkgManager unpackageFile:@"fire.zip" packageName:@"fire" checkTime:YES];
    5757
    [LVPkgManager clearCachesPath];
    58+
    59+
    [LViewController disableReloadKeyCommand:YES];
    5860
    }
    5961

    6062

    @@ -79,7 +81,7 @@ - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPa
    7981

    8082
    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    8183
    NSString* name = self.names[indexPath.row];
    82-
    JHSLuaViewController* c = [[JHSLuaViewController alloc] initWithSource:name];
    84+
    JHSLuaViewController* c = [[JHSLuaViewController alloc] initWithPackage:nil mainScript:name];
    8385
    [self.navigationController pushViewController:c animated:YES];
    8486
    }
    8587

    IOS/LuaViewSDK.xcodeproj/project.pbxproj

    Lines changed: 8 additions & 0 deletions
    Original file line numberDiff line numberDiff line change
    @@ -9,6 +9,8 @@
    99
    /* Begin PBXBuildFile section */
    1010
    3C02D1D91C31106E00213386 /* LVAnimator.h in Headers */ = {isa = PBXBuildFile; fileRef = 3C02D1D71C31106E00213386 /* LVAnimator.h */; settings = {ATTRIBUTES = (Public, ); }; };
    1111
    3C02D1DA1C31106E00213386 /* LVAnimator.m in Sources */ = {isa = PBXBuildFile; fileRef = 3C02D1D81C31106E00213386 /* LVAnimator.m */; };
    12+
    3C98A53A1C7C0C100001508E /* LViewController.h in Headers */ = {isa = PBXBuildFile; fileRef = 3C98A5381C7C0C100001508E /* LViewController.h */; };
    13+
    3C98A53B1C7C0C100001508E /* LViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 3C98A5391C7C0C100001508E /* LViewController.m */; };
    1214
    84C1D6AB1C16B09D0058E974 /* LuaViewTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 84C1D6AA1C16B09D0058E974 /* LuaViewTests.m */; };
    1315
    84C1D7CB1C16C3CD0058E974 /* LuaViewSDK-Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = 84C1D7CA1C16C3CD0058E974 /* LuaViewSDK-Info.plist */; };
    1416
    84C1D7D41C16C3F90058E974 /* LVPkgManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 84D446F11AF75BD8000A3911 /* LVPkgManager.m */; };
    @@ -213,6 +215,8 @@
    213215
    /* Begin PBXFileReference section */
    214216
    3C02D1D71C31106E00213386 /* LVAnimator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LVAnimator.h; sourceTree = "<group>"; };
    215217
    3C02D1D81C31106E00213386 /* LVAnimator.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LVAnimator.m; sourceTree = "<group>"; };
    218+
    3C98A5381C7C0C100001508E /* LViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LViewController.h; sourceTree = "<group>"; };
    219+
    3C98A5391C7C0C100001508E /* LViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LViewController.m; sourceTree = "<group>"; };
    216220
    8405078B1ADF8F7300906BAC /* podinstall.text */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = net.daringfireball.markdown; path = podinstall.text; sourceTree = "<group>"; };
    217221
    84056E701B5CA5990078F9D6 /* LVCustomPanel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LVCustomPanel.h; sourceTree = "<group>"; };
    218222
    84056E711B5CA5990078F9D6 /* LVCustomPanel.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LVCustomPanel.m; sourceTree = "<group>"; };
    @@ -519,6 +523,8 @@
    519523
    840AD5AD1A63ED7C003E837D /* lv514 */,
    520524
    840AD5311A5EAB4A0075CB58 /* LView.h */,
    521525
    840AD5321A5EAB4A0075CB58 /* LView.m */,
    526+
    3C98A5381C7C0C100001508E /* LViewController.h */,
    527+
    3C98A5391C7C0C100001508E /* LViewController.m */,
    522528
    84E85C181C33B84B007DE3DF /* LVBundle.h */,
    523529
    84E85C191C33B84B007DE3DF /* LVBundle.m */,
    524530
    84E446961AEE0655009C9A8A /* LVBlock.h */,
    @@ -925,6 +931,7 @@
    925931
    84C1D8531C16C44B0058E974 /* LVData.h in Headers */,
    926932
    84C1D8541C16C44B0058E974 /* LVDate.h in Headers */,
    927933
    84C1D8551C16C44B0058E974 /* LVTimer.h in Headers */,
    934+
    3C98A53A1C7C0C100001508E /* LViewController.h in Headers */,
    928935
    84C1D8561C16C44B0058E974 /* LVStruct.h in Headers */,
    929936
    84C1D8571C16C44B0058E974 /* LVGestureRecognizer.h in Headers */,
    930937
    84C1D8581C16C44B0058E974 /* LVLongPressGestureRecognizer.h in Headers */,
    @@ -1149,6 +1156,7 @@
    11491156
    84C1D8281C16C4070058E974 /* lVoslib.c in Sources */,
    11501157
    84C1D8291C16C4070058E974 /* lVparser.c in Sources */,
    11511158
    84C1D82A1C16C4070058E974 /* lVprint.c in Sources */,
    1159+
    3C98A53B1C7C0C100001508E /* LViewController.m in Sources */,
    11521160
    84C1D82B1C16C4070058E974 /* lVstate.c in Sources */,
    11531161
    84C1D82C1C16C4070058E974 /* lVstring.c in Sources */,
    11541162
    84C1D82D1C16C4070058E974 /* lVstrlib.c in Sources */,

    IOS/LuaViewSDK/Classes/LVBundle.h

    Lines changed: 2 additions & 0 deletions
    Original file line numberDiff line numberDiff line change
    @@ -19,6 +19,8 @@
    1919

    2020
    @property (nonatomic, readonly) NSString *currentPath;
    2121

    22+
    - (void)changeCurrentPath:(NSString *)path;
    23+
    2224
    /**
    2325
    * 可以是绝对路径也可以是相对bundle根目录的相对路径
    2426
    */

    IOS/LuaViewSDK/Classes/LVBundle.m

    Lines changed: 4 additions & 0 deletions
    Original file line numberDiff line numberDiff line change
    @@ -40,6 +40,10 @@ - (NSString *)currentPath {
    4040
    return [_fileManager currentDirectoryPath];
    4141
    }
    4242

    43+
    - (void)changeCurrentPath:(NSString *)path {
    44+
    [_fileManager changeCurrentDirectoryPath:path];
    45+
    }
    46+
    4347
    - (NSArray *)resourcePaths {
    4448
    return [_resourcePaths copy];
    4549
    }
    Lines changed: 28 additions & 0 deletions
    Original file line numberDiff line numberDiff line change
    @@ -0,0 +1,28 @@
    1+
    //
    2+
    // LViewController.h
    3+
    // LuaViewSDK
    4+
    //
    5+
    // Created by lamo on 16/2/23.
    6+
    // Copyright © 2016年 dongxicheng. All rights reserved.
    7+
    //
    8+
    9+
    #import <UIKit/UIKit.h>
    10+
    11+
    @class LView;
    12+
    13+
    @interface LViewController : UIViewController
    14+
    15+
    @property(nonatomic, readonly) LView *lv;
    16+
    @property(nonatomic, readonly) NSString *mainScriptName;
    17+
    @property(nonatomic, readonly) NSString *packagePath;
    18+
    19+
    + (void)disableReloadKeyCommand:(BOOL)disable;
    20+
    21+
    - (instancetype)initWithPackage:(NSString *)path mainScript:(NSString *)scriptName;
    22+
    23+
    - (void)willCreateLuaView;
    24+
    - (void)didCreateLuaView:(LView *)view;
    25+
    - (void)willDestroyLuaView:(LView *)view;
    26+
    - (void)didDestroyLuaView;
    27+
    28+
    @end

    0 commit comments

    Comments
     (0)
    0