Skip to content

Instantly share code, notes, and snippets.

View michaeldong's full-sized avatar

dong michaeldong

  • Beijing
View GitHub Profile
import React from 'react';
import {View, TouchableOpacity} from 'react-native';
export default class TestRender extends React.Component {
render() {
return (
<View style={{ backgroundColor: 'white', paddingTop: 64,}} testID="white">
<View style={{ backgroundColor: "yellow",width: 50, height: 50}} testID="white-yellow"/>
<View
style={{backgroundColor: 'green',width: 100, height: 100,justifyContent:"center",alignItems:"center"}} testID="white-green"
import UIKit
extension UIApplication {
class func topViewController(_ base: UIViewController? = UIApplication.shared.keyWindow?.rootViewController) -> UIViewController? {
if let navigationController = base as? UINavigationController, navigationController.viewControllers.count > 0 {
return topViewController(navigationController.visibleViewController)
}
@michaeldong
michaeldong / .m
Last active November 9, 2018 02:19
weex read local image
if([url.scheme isEqualToString:@"file"]) {
NSString *fileName = [NSString stringWithFormat:@"%@@3x", url.host];
NSString *file = [[NSBundle mainBundle] pathForResource:fileName ofType:@"png"];
if(file != nil) {
url = [NSURL fileURLWithPath:file];
}
else {
NSInteger prefixLength = @"file://".length + url.host.length + @"/".length;
@michaeldong
michaeldong / UIImage+PixedColor.swift
Created October 1, 2017 04:06
Pixel Color from UIImage by subscript swift 4
// Created by michaelxing on 2017/9/30.
// Copyright © 2017年 michaelxing. All rights reserved.
import UIKit
extension UIImage {
subscript(x: Int, y: Int) -> UIColor? {
get {
if x < 0 || x > Int(size.width) || y < 0 || y > Int(size.height) {
@michaeldong
michaeldong / PSPDFUIKitMainThreadGuard.m
Created December 23, 2015 07:58 — forked from steipete/PSPDFUIKitMainThreadGuard.m
This is a guard that tracks down UIKit access on threads other than main. This snippet is taken from the commercial iOS PDF framework http://pspdfkit.com, but relicensed under MIT. Works because a lot of calls internally call setNeedsDisplay or setNeedsLayout. Won't catch everything, but it's very lightweight and usually does the job.You might n…
// Taken from the commercial iOS PDF framework http://pspdfkit.com.
// Copyright (c) 2014 Peter Steinberger, PSPDFKit GmbH. All rights reserved.
// Licensed under MIT (http://opensource.org/licenses/MIT)
//
// You should only use this in debug builds. It doesn't use private API, but I wouldn't ship it.
#import <objc/runtime.h>
#import <objc/message.h>
// Compile-time selector checks.