html转换react native,react native 虚拟html页面

vpages

import { Animated, Button, StyleSheet, Text, View, Dimensions } from 'react-native';

const {width, height} = Dimensions.get('window');

const androidHeight = height-24

var styles = {

ul: {

marginLeft: 0

},

html: {

item: {

width: width,

marginTop: 24,

},

ul: {

height: androidHeight,

backgroundColor: '#ffffff'

}

},

head: {

item: {

position: 'absolute',

top: 0,

left: 0,

height: 50,

width: width,

backgroundColor: '#c9c9c9',

},

itemText: {

color: '#000000'

}

},

body: {

item: {

flex: 1,

marginTop: 50

}

},

foot: {

item: {

position: 'absolute',

bottom: 0,

left: 0,

height: 70,

width: width,

backgroundColor: '#c9c9c9'

},

itemText: {

color: '#000000'

}

},

test: {

item: {

height: 80,

backgroundColor: '#ae5273'

},

itemText: {

color: '#ffffff'

}

}

}

class Vpages extends React.Component {

constructor(props){

super(props)

this.state = {

vpages: this.props.data || []

}

}

render(){

const stys = Aotoo.merge({}, styles, this.props.style)

return Aotoo.tree(

{ data: this.state.vpages },

stys

)

}

}

function findIndex(vpages, select, pre){

let index

if (!pre) {

vpages.forEach( (ele, ii) => {

if (ele.parent == select) { index = ii }

});

}

if (!index) index = Aotoo.findIndex(vpages, o=>o.idf==select)

return index

}

const Actions = {

APPEND: function(ostate, opts){

var state = this.curState

var vpages = state.vpages

const select = opts.select

const content = opts.content

const className = opts.className

const id = opts.id

const index = findIndex(vpages, select)

const wanner = {title: content, idf: id, parent: select, className}

vpages.splice( (index+1), 0, wanner)

return state

},

PREPEND: function(ostate, opts){

var state = this.curState

var vpages = state.vpages

const select = opts.select

const content = opts.content

const className = opts.className

const id = opts.id

const index = findIndex(vpages, select, true)

const wanner = {title: content, idf: id, parent: select, className}

vpages.splice( (index+1), 0, wanner)

return state

},

REMOVE: function(ostate, opts){

var state = this.curState

var vpages = state.vpages

const select = opts.select

const index = findIndex(vpages, select, true)

vpages.splice( index, 1 )

return state

},

UPDATE: function(ostate, opts){

var state = this.curState

var vpages = state.vpages

const content = opts.content

const className = opts.className

const index = findIndex(vpages, select, true)

let resource = vpages[index]

resource.title = content

resource.className = className

return state

}

}

function myTemplate(newTmp){

const _tmp = {

empty: [

{title: '', idf: 'html', className: 'html'},

],

html: [

{title: '', idf: 'html', className: 'html'},

{title: '', idf: 'head', parent: 'html', className: 'head'},

{title: '', idf: 'body', parent: 'html', className: 'body'},

{title: '', idf: 'foot', parent: 'html', className: 'foot'},

]

}

if (newTmp) {

return Aotoo.merge({}, _tmp, newTmp)

} else {

return _tmp

}

}

module.exports = function(opts){

let template = myTemplate()

if (typeof opts == 'string' || !opts) {

const tmp = opts || 'empty'

if (template[tmp]) {

opts = {

props: {

data: template[tmp]

}

}

} else {

opts = {}

}

}

if (!opts.props) {

opts.props = {

data: template.empty

}

}

if (opts.props && !opts.props.data) {

opts.props.data = template.empty

}

if (opts.props && typeof opts.props.data == 'string') {

if (!template[opts.props.data]) {

opts.props.data = 'empty'

}

opts.props.data = template[opts.props.data]

}

const Vp = Aotoo(Vpages, Actions)

function visualPages(select){

return Vp.$(select)

}

visualPages.template = function(newTemplate){

template = myTemplate(newTemplate)

}

visualPages.render = function(id, fun){

Vp.setConfig(opts)

Vp.rendered = visualPages.rendered

return Vp.render(id, fun)

}

Vp.extend({

$: function(select){

const that = this

const index = findIndex(opts.props.data, select, true)

if (!index) return

return {

append: function(options){

let {content, id, className} = options

if (!id) id = Aotoo.uniqueId('visualPage_')

if (that.hasMounted()) {

that.dispatch ('APPEND', { select, content, id, className })

} else {

const index = findIndex(opts.props.data, select)

const wanner = {title: content, idf: id, parent: select, className}

opts.props.data.splice( (index+1), 0, wanner)

}

return visualPages(id)

},

prepend: function(options){

let {content, id, className} = options

if (!id) id = Aotoo.uniqueId('visualPage_')

if (that.hasMounted()) {

that.dispatch ('PREPEND', { select, content, id, className })

} else {

const index = findIndex(opts.props.data, select, true)

const wanner = {title: content, idf: id, parent: select, className}

opts.props.data.splice( (index+1), 0, wanner)

}

return visualPages(id)

},

remove: function(){

if (that.hasMounted()) {

that.dispatch ('REMOVE', { select })

} else {

const index = findIndex(opts.props.data, select, true)

opts.props.data.splice( index, 1 )

}

},

update: function(options){

let {content, className} = options

if (that.hasMounted()) {

that.dispatch ('UPDATE', { content, className })

} else {

const index = findIndex(opts.props.data, select, true)

if (index) {

opts.props.data[index]['title'] = content

opts.props.data[index]['className'] = className

}

}

return visualPages(select)

},

get: function(){

const index = findIndex(opts.props.data, select, true)

if (index) {

return opts.props.data[index]

}

},

animat: function(){}

}

}

})

return visualPages

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值