-
Notifications
You must be signed in to change notification settings - Fork 132
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
7 changed files
with
176 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import {AppRegistry} from 'react-native'; | ||
import App from './src/index'; | ||
import {name as appName} from './app.json'; | ||
|
||
AppRegistry.registerComponent(appName, () => App); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import React, { Component } from "react"; | ||
import { StyleSheet, Text, View, Platform } from "react-native" | ||
|
||
/** | ||
* @areslabs/wx-animated 是参考小程序API实现的一套可以运行在React Native,小程序上的动画 | ||
* 详情参考:https://areslabs.github.io/alita/%E5%8A%A8%E7%94%BB.html | ||
*/ | ||
import {AnimatedImage, createAnimation} from '@areslabs/wx-animated' | ||
|
||
import rnLogoPng from './rn_logo.png' | ||
|
||
export default class HelloWorld extends Component { | ||
|
||
state = { | ||
logoAni: null, | ||
} | ||
|
||
componentDidMount() { | ||
this.logoAni() | ||
} | ||
|
||
render() { | ||
return ( | ||
<View style={styles.container}> | ||
|
||
<AnimatedImage | ||
animation={this.state.logoAni} | ||
source={rnLogoPng} | ||
style={styles.logo} | ||
/> | ||
|
||
<Text> | ||
Hello {Platform.OS}! | ||
</Text> | ||
</View> | ||
|
||
); | ||
} | ||
|
||
logoAni(num = 1) { | ||
const ani = createAnimation({ | ||
duration: 5000, | ||
}) | ||
ani.rotateZ(360 * num) | ||
ani.step() | ||
this.setState({ | ||
logoAni: ani.export(() => { | ||
this.logoAni(num + 1) | ||
}) | ||
}) | ||
} | ||
} | ||
|
||
const styles = StyleSheet.create({ | ||
container: { | ||
flex: 1, | ||
justifyContent: "center", | ||
alignItems: "center" | ||
}, | ||
logo: { | ||
width: 100, | ||
height: 100 | ||
} | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/** | ||
* 定义Router的文件,被称为入口文件,由于小程序的页面必须预先定义在 app.json 文件,json文件是静态的,所以入口文件的处理发生在编译阶段 | ||
* 这就要求入口文件需要足够的静态可分析。 | ||
* | ||
* 具体对入口文件的限制,请参考:https://areslabs.github.io/alita/%E5%85%A5%E5%8F%A3%E6%96%87%E4%BB%B6.html | ||
*/ | ||
|
||
import React, {PureComponent} from 'react' | ||
|
||
/** | ||
* alita转化的项目必须使用:@areslabs/router 路由,详细文档:https://areslabs.github.io/alita/%E8%B7%AF%E7%94%B1.html | ||
*/ | ||
import {Router, Route, TabRouter} from '@areslabs/router' | ||
|
||
import HelloWorld from './HelloWorld' | ||
|
||
export default class App extends PureComponent { | ||
|
||
render() { | ||
|
||
return ( | ||
<Router | ||
wxNavigationOptions={{ | ||
// 小程序导航条配置 | ||
navigationBarTitleText: "HelloWorld", | ||
navigationBarBackgroundColor: "#ffffff", | ||
navigationBarTextStyle: "black", | ||
}} | ||
|
||
navigationOptions={{ | ||
// rn 导航条配置 | ||
title: 'HelloWorld' | ||
}} | ||
> | ||
{/* | ||
* 页面一定要在Router里面明确定义,即使应用只有一个页面 | ||
*/} | ||
<Route key={"A"} component={HelloWorld}/> | ||
</Router> | ||
) | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/** | ||
* Copyright (c) Areslabs. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
*/ | ||
|
||
import path from 'path' | ||
import fse from 'fs-extra' | ||
import {successInfo} from './util' | ||
|
||
export default function initProject(operands) { | ||
const initIndex = operands.indexOf('init') | ||
const projectName = operands[initIndex + 1] | ||
|
||
if (!projectName) { | ||
console.log('alita初始化 请指定项目名!'.error) | ||
return | ||
} | ||
|
||
const targetpath = path.resolve(projectName) | ||
|
||
const tempDir = path.resolve(__dirname, '..', '..', 'rn-template') | ||
fse.copySync(tempDir, targetpath) | ||
|
||
const appJSPath = path.resolve(targetpath, 'App.js') | ||
if (fse.existsSync(appJSPath)) { | ||
fse.unlinkSync(appJSPath) | ||
} | ||
|
||
const pjsonPath = path.resolve(targetpath, 'package.json') | ||
const packageObj = fse.readJsonSync(pjsonPath) | ||
packageObj.dependencies = { | ||
"@areslabs/router": "^1.0.0", | ||
"@areslabs/wx-animated": "^1.0.0", | ||
...packageObj.dependencies, | ||
} | ||
fse.outputJsonSync(pjsonPath, packageObj, {spaces: ' '}) | ||
console.log(' Run instructions for 小程序:'.blue) | ||
console.log(` • alita -i ${projectName} -o [目标小程序目录] (若需要监听文件修改添加参数:--watch)`.black) | ||
} |