Coder Social home page Coder Social logo

hackers-painters / samurai-native Goto Github PK

View Code? Open in Web Editor NEW
2.3K 181.0 381.0 19.84 MB

Bring web standards to native platform

Home Page: http://hackers-painters.github.io/samurai-native/

License: MIT License

Objective-C 43.26% C++ 0.49% CSS 1.54% HTML 54.37% Groff 0.01% JavaScript 0.33%

samurai-native's Introduction

samurai-native-logo

Bring web standards to native platform

samurai-native enables you to build native apps using web technologies (HTML/CSS) based on its own Web-Core. Support iOS now, Android later.

Road map | 中文介绍 | QQ群 79054681

Demo apps

Quick preview

gif

Native Components

You can use the native components such as UICollectionView and UICollectionViewCell on iOS. This gives your app a consistent look and feel with the rest of the platform ecosystem, and keeps the quality bar high. These components are easily incorporated into your app using <UICollectionView/> and <UICollectionViewCell/> directly.

<html>

	<body>

		<UICollectionView class="list" is-vertical>
			<UICollectionViewCell is-static is-row>
				...
			</UICollectionViewCell>
		</UICollectionView>

	</body>

</html>

HTML Components

You can use the standard HTML tags such as div and img on iOS. This gives you ability to define your user interface using a hybrid way.

<html>

	<body>

		<UICollectionViewCell is-static is-row>
			<div class="profile-wrapper">
				<div class="profile-attribution">
					<div class="profile-segment no-wrap">
						<div class="segment-wrapper">
							<span class="segment-count">10,875</span>
							<span class="segment-suffix">Followers</span>
						</div>
					</div>
					<div class="profile-segment no-wrap">
						<div class="segment-wrapper">
							<span class="segment-count">199</span>
							<span class="segment-suffix">Followers</span>
						</div>
					</div>
				</div>
			</div>
		</UICollectionViewCell>

	</body>

</html>

CSS Fluid layout

We brought the css layout model from the web to samurai-native, css layout makes it simple to build the most common UI layouts, such as stacked and nested boxes with margin and padding. samurai-native also supports common web styles, such as font-weight and border-radius, and you can extend your style in SamuraiHtmlRenderStyle class.

<html>

	<head>

		<link rel="stylesheet" type="text/css" href="../css/normalize.css"/>
		<link rel="stylesheet" type="text/css" href="../css/main.css"/>

	</head>

</html>
<html>

	<body>

		<p style="color: red;">
			Hello, world!
		</p>

	</body>

</html>
<html>

	<body>

		<div class="tab-bar">
			<div class="tab">Popular</div>
			<div class="tab">Debuts</div>
			<div class="tab">Everyone</div>
		</div>

		<style>

			.tab-bar {
				display: block;
				width: 100%;
				height: 34px;
				background-color: #e5508c;
				/* box-shadow: 0px 0.5px 0.5px black; */
				z-index: 2;
			}

			.tab {
				float: left;
				display: block;
				width: 33.33%;
				height: 34px;
				font-size: 14px;
				line-height: 34px;
				color: #fff 0.75;
				text-align: center;
				font-weight: normal;
			}

			...

		</style>

	</body>

</html>

Easy to Integration

@implementation MyViewController

- (void)viewDidLoad
{
	[self loadTemplate:@"/www/html/dribbble-index.html"];
//	[self loadTemplate:@"http://localhost:8000/html/dribbble-index.html"];
}

- (void)dealloc
{
	[self unloadTemplate];
}

- (void)onTemplateLoading {}
- (void)onTemplateLoaded {}
- (void)onTemplateFailed {}
- (void)onTemplateCancelled {}

@end

Signal Handling

samurai-native provide a high level event system called Signal, you can interact (gesture) with HTML page through signal system.

<div onclick="signal('hello')">
	Click here
</div>
<div onswipe-left="signal('next')" onswipe-right="signal('prev')">
	Swipe left or right
</div>
@implementation MyViewController

handleSignal( hello )
{
	[self something];
}

handleSignal( prev )
{
	[self something];
}

handleSignal( next )
{
	[self something];
}

@end

Data Binding

samurai-native provide a efficient way to binding native objects to HTML page in single way through DOM's name property.

<html>
	<body>

		...

		<div name="author">
			<img name="avatar"/>
			<div>
				<div name="title"/>
				<div>by <span name="name"/></div>
			</div>
		</div>

		...

	</body>
</html>
@implementation MyViewController

...

- (void)reloadData
{
	self[@"author"] = @{
		@"avatar" : "xxx.jpg",
		@"title"  : @"Hello",
		@"name"   : @"World"
	};
}

@end

Extensibility

samurai-native is designed to be easily extended with custom native components, that means you can reuse anything you've already built, and can import and use your favorite native components.

@implementation UILabel(Html)

- (void)html_applyDom:(SamuraiHtmlDomNode *)dom
{
	[super html_applyDom:dom];

	self.text = [dom computeInnerText];
}

- (void)html_applyStyle:(SamuraiHtmlRenderStyle *)style
{
	[super html_applyStyle:style];

	self.font = [style computeFont:self.font];
	self.textColor = [style computeColor:self.textColor];
	self.textAlignment = [style computeTextAlignment:self.textAlignment];
	self.baselineAdjustment = [style computeBaselineAdjustment:self.baselineAdjustment];
	self.lineBreakMode = [style computeLineBreakMode:self.lineBreakMode];
	self.numberOfLines = 0;

	...
}

@end

Live reload

Add lines below into your main() function, samurai-native will applies HTML/CSS changes to iPhoneSimulator without rebuild and run the app.

[[SamuraiWatcher sharedInstance] watch:@(__FILE__)];

Running the Examples

  • clone https://github.com/hackers-painters/samurai.git
  • open samurai-examples/dribbble/demo.xcodeproj
  • build and run

Licensing

samurai-native is licensed under the MIT License.

Contributors

Special thanks

Related Projects

  • gumbo: An HTML5 parsing library in pure C99
  • katana: An CSS3 parsing library in pure C99
  • fishhook: A library that enables dynamically rebinding symbols in Mach-O binaries running on iOS.
  • AFNetworking: A delightful iOS and OS X networking framework

samurai-native's People

Contributors

akitaka avatar cyndibaby905 avatar gavinkwoe avatar geekzoostudio avatar inonomori avatar jichao avatar qfish avatar uxyheaven avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

samurai-native's Issues

uibutton不能够设置文字颜色

文字颜色一直为白色,使用css并不能够更改,从catalog uibutton的运行结果可以看出.
ios simulator screen shot 2015 5 9 3 57 07
原因是UIButton+Html.m当中处理button颜色的时候,使用了titleLabel.textColor,但是ios的document明确指出

Do not use the label object to set the text color or the shadow color. Instead, use the setTitleColor:forState: and setTitleShadowColor:forState: methods of this class to make those changes.

因此要改成[self setTitleColor:[style computeColor:self.titleLabel.textColor] forState:UIControlStateNormal];就正确了。

ios simulator screen shot 2015 5 9 4 01 27

无法使用,求指教。

  1. git clone后打开工程在Xcode6.4报错。
    #include Samurai_CSSStyleSheet.h
    显示没找到此文件,在导航栏手动添加此文件后,终于通过。
  2. 显示Samurai_CSSRuleData.m不存在。
    no such file or directory: '/Users/ff/samurai-native/samurai-webcore/modules/css-parser/Samurai_CSSRuleData.m'
    搜索代码后发现确实有调用此文件名,但文件确实不存在。

uibutton有没有可能直接使用系统类型?

从view-component来看,似乎类型并不可以指定,而只能够使用custom。

    UIButton * button = [self buttonWithType:UIButtonTypeCustom];

    button.renderer = renderer;

    [[button buttonAgent] enableEvents];

    return button;

但是如果用户想使用systemtype,则没有办法。
如果确实是没有办法的话,是不是考虑指定一个参数,使得用户可以创建systemtype的uibutton.

ATTR方法在iPhone5S以上(64位设备)真机Release环境下会发生闪退,iPhone5和模拟器不会闪退,Debug环境也不会。

示例:
$(dom).ATTR(@"display", @"none");

错误行数:
Samurai_HtmlRenderQuery.m第350行:
SamuraiHtmlRenderQueryBlockN block = (SamuraiHtmlRenderQueryBlockN)^ SamuraiHtmlRenderQuery * ( NSString * key, NSString * value )

错误原因:
可变参数导致的闪退问题。只有在iPhone5S以上(64位设备)真机Release环境下会发生闪退。
只要ATTR传了第二个参数,就会闪退。传一个参数不会。

无意中发现了,请测试并官方修复,谢谢啦。

css里的 display: none 在某种情况下使用有问题

.hidden2
{
display: none;
background-color: #aaa;
}

直接在html用正常.如果用下面的方法在oc里添加进去,

$(@"#scan").ADD_CLASS( @"hidden2" );
[self.scan addCssStyleClass:@"hidden2"];

display: none无效
background-color: #aaa; 有效

ATTR问题及其他

1.ATTR问题

html部分代码是这样的

 <UICollectionView name="sections" id="list" class="list" columns="1" is-vertical>
    <UICollectionViewCell name="section" class="cell" is-row>
        <div class="title">
            <div class="title-name" name="name">Name</div>
            <div class="title-time" name="time">time</div>
        </div>
    </UICollectionViewCell>     
</UICollectionView>
<style>
        .list {
            display: block;
            width: 100%;
            height: 100%;
            z-index: 1;
            background-color: #eaeaea;
            margin-top: 2px;
        }
        .cell {
            height: 80px;
            color: #333;
            background-color: #eee;
            border-bottom: 1px;
            border-bottom-color: #ccc;
            border-bottom-style: solid;
        }
        .title {
            width: 100%;
            height: 100%;
            float: right;
        }
        .title-name {
            padding-top: 15px;
            padding-left: 30px;
            color: #333;
            font-size: 16px;
        }
        .title-time {
            padding-left: 30px;
            color: #aaa;
            font-size: 13px;
        }
</style>

对list使用ATTR后

$(@"#list").ATTR(@"display",@"none");
$(@"#list").ATTR(@"display",@"block");

再让list显示后,list里面文字部分的字号和字体颜色都会发生变化,字体会变为一样大,颜色黑色。

2.字体问题

字体设置font-family无效。

3.实机运行问题

实机上运行需要注释掉。

//DEBUG_RENDERER_DOM( self );

4.UICollectionViewCell问题

iOS7系统下 UICollectionViewCell 不显示。

关于Android大约何时可以发布

很想问一个开发者都比较关注的问题,不知道对Android版的发布大约要多久以后呢?否则我相信不少朋友依旧处于观望状态。谢谢。

无法集成阿里百川SDK

集成阿里百川的SDK,在初始化阿里百川SDK的时候总是导致crash,去掉Samurai就可以正常初始化。

movie的demo存在问题

movie的demo在iphone 5上边会出现内容错乱的情况。
img_0037
而在iphone6下边内容不会错乱。
ios simulator screen shot 2015 5 7 11 40 38

如何做POST请求还有如何POST一张(或多张)图片啊

在Bee里面有POST的例子,这里找不到POST的例子。我往代码去看,貌似要自己去写一个Client然后继承STIHTTPSessionManager,去加POST的方法。是这样子吗?还是有更好的办法。
我看到AFN底层是有预留的
multipartFormRequestWithMethod:URLString:parameters:constructingBodyWithBlock:

Could modify tabbar content via html?

I try to modify the tabbar content in dribbble demo, but it's not work.

        <div name="tabbar" class="tab-bar">
            <div id="tab1" name="popular" class="tab" onclick="signal('switch-tab1')">Popular</div>
            <div id="tab2" name="debuts" class="tab" onclick="signal('switch-tab2')">Debuts</div>
            <div id="tab3" name="everyone" class="tab" onclick="signal('switch-tab3')">Everyonesss</div>
        </div>

Then i found the tabbar is defined in obj-c, so could we move tabbar code to html that build the demo with full web stack?

- (void)reloadData
{
    self[@"tabbar"] = @{

        @"popular" : ({

            NSString * text = nil;

            if ( _currentModel == self.model1 )
            {
                text = @"/Popular/";
            }
            else
            {
                text = @"Popular";
            }

            text;
        }),

        @"debuts" : ({

            NSString * text = nil;

            if ( _currentModel == self.model2 )
            {
                text = @"/Debuts/";
            }
            else
            {
                text = @"Debuts";
            }

            text;

        }),

        @"everyone" : ({

            NSString * text = nil;

            if ( _currentModel == self.model3 )
            {
                text = @"/Everyone/";
            }
            else
            {
                text = @"Everyone";
            }

            text;
        }),

    };

    self[@"list"] = @{

        @"shots" : ({

            NSMutableArray * shots = [NSMutableArray array];

            for ( SHOT * shot in _currentModel.shots )
            {
                [shots addObject:@{
                    @"shot-url" : shot.images.teaser ?: @"",
                    @"author-avatar" : shot.user.avatar_url ?: @"",
                }];
            }

            shots;
        })
    };
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.