//
//  TMQLPreviewViewController.m
//  RNReactNativeDocViewer
//
//  Created by Robin on 2018/6/11.
//  Copyright © 2018年 Facebook. All rights reserved.
//

#import "TMQLPreviewViewController.h"

@interface TMQLPreviewViewController ()

@end

@implementation TMQLPreviewViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    UIButton *back = [UIButton buttonWithType:UIButtonTypeCustom];
    CGFloat statusHeight = [self statusBarHeight];
    [back setFrame:CGRectMake(4,statusHeight, 60, 44)];
    [back setTitle:@"关闭" forState:UIControlStateNormal];
    [back addTarget:self action:@selector(dismissViewController) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:back];
    
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(64, statusHeight, self.view.bounds.size.width - 108, 44)];
    label.textColor = [UIColor whiteColor];
    label.textAlignment = NSTextAlignmentCenter;
    label.text = self.fileName;
    [self.view addSubview: label];
}

-(void)dismissViewController{
    [self dismissViewControllerAnimated:YES completion:nil];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/**
 判断设备是否iPhone X系列
 */
- (BOOL)isIPhoneXSeries {
    BOOL iPhoneXSeries = NO;
    if (UIDevice.currentDevice.userInterfaceIdiom != UIUserInterfaceIdiomPhone) {
        return iPhoneXSeries;
    }
    
    if (@available(iOS 11.0, *)) {
        UIWindow *mainWindow = [[[UIApplication sharedApplication] delegate] window];
        if (mainWindow.safeAreaInsets.bottom > 0.0) {
            iPhoneXSeries = YES;
        }
    }
    
    return iPhoneXSeries;
}
- (CGFloat)statusBarHeight {
    return [self isIPhoneXSeries] ? 44 : 20;
}

@end
