-
Notifications
You must be signed in to change notification settings - Fork 165
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7164b2b
commit 2d1741b
Showing
7 changed files
with
76 additions
and
9 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,66 @@ | ||
/** | ||
* Created by yuanguozheng on 16/1/22. | ||
*/ | ||
'use strict'; | ||
import React, { | ||
Component, | ||
View, | ||
Text, | ||
Image, | ||
StyleSheet, | ||
ScrollView, | ||
RefreshControl | ||
} from 'react-native'; | ||
import MenuButton from './MenuButton'; | ||
import ViewPager from 'react-native-viewpager'; | ||
|
||
const BANNER_IMGS = [ | ||
require('../images/banner/1.jpg'), | ||
require('../images/banner/2.jpg'), | ||
require('../images/banner/3.jpg'), | ||
require('../images/banner/4.jpg') | ||
]; | ||
|
||
export default class HomePage extends Component { | ||
|
||
constructor(props) { | ||
super(props); | ||
// 用于构建DataSource对象 | ||
var dataSource = new ViewPager.DataSource({ | ||
pageHasChanged: (p1, p2) => p1 !== p2, | ||
}); | ||
// 实际的DataSources存放在state中 | ||
this.state = { | ||
dataSource: dataSource.cloneWithPages(BANNER_IMGS) | ||
} | ||
} | ||
|
||
_renderPage(data, pageID) { | ||
return ( | ||
<Image | ||
source={data} | ||
style={styles.page}/> | ||
); | ||
} | ||
|
||
render() { | ||
return ( | ||
<View> | ||
<ViewPager | ||
style={{height:130}} | ||
dataSource={this.state.dataSource} | ||
renderPage={this._renderPage} | ||
isLoop={true} | ||
autoPlay={true}/> | ||
</View> | ||
) | ||
} | ||
} | ||
|
||
const styles = StyleSheet.create({ | ||
page: { | ||
flex: 1, | ||
height: 130, | ||
resizeMode: 'stretch' | ||
}, | ||
}); |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
2d1741b
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
你好,轮播图代码会报错啊呀,会报can not find variable: animated
2d1741b
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rogueRabbit ViewPager库和RN的版本对吗?
2d1741b
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
循环轮播时最后一个图片条转到第一个图片时 有白屏一晃而过 晃眼 怎么解决?
2d1741b
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ahzar 取消自动播放
2d1741b
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
我的出来,图片不是完整的一张,有一小半是下张图片的,怎么回事啊?
2d1741b
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jinleli 高度、宽度,或者Image的缩放类型不对
2d1741b
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
我写的和您的代码一样,高度130,宽度没写,然后缩放类型stretch,我用的模拟器不是iphone跟这个有没有关系呢?
2d1741b
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jinleli 有可能,Android上屏幕不太一样可能会有变形,你计算一下然后改改就行
2d1741b
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
非常感谢,通过您的教程学到了很多
2d1741b
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jinleli 不客气,我也是新手,希望能共同学习
2d1741b
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
为什么我的滚动原点位置不对呢
2d1741b
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@RuntaiChen 应该是布局有点问题
2d1741b
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
会报错 null is not an object(evaluating 'this.state.dataSource')
2d1741b
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
我的出现了设置ViewPage的高度为130,但是出现的效果像是有两个ViewPage
的高度
2d1741b
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@lixiaobin0303 检查一下前后写的数据源是否正确
2d1741b
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@wdhonor 看一下里面的Item的高度
2d1741b
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@yuanguozheng 这个ViewPage里面没有Item啊 只是有被填充的图片资源 这个我也设置了高度是130
2d1741b
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@wdhonor 看看外层容器的高度,还有ViewPager是否是Flex:1
2d1741b
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@yuanguozheng 问题已经解决了 使用flex来进行解决的 就像Android中的weight进行设置权重比例一样
2d1741b
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@wdhonor 解决了就好
2d1741b
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@yuanguozheng 问一下几个问题
(1)ViewPager 被其他控件包住的时候就无法显示了
(2)如果要保留自动滑动,怎么解决从最后一张跳到第一张闪了一下的问题呢、
(3)设置了高度和flex ,ViewPager的导航点自己在页面的低端了,没法移到上面,,,
最后附上代码
import React, { Component } from 'react';
import {
StyleSheet,
Image,
} from 'react-native';
import ViewPager from 'react-native-viewpager';
const BANNER_IMGS = [
require('../image/banner/1.jpg'),
require('../image/banner/2.jpg'),
require('../image/banner/3.jpg'),
require('../image/banner/4.jpg')
];
export default class HomePage extends Component{
};
const styles = StyleSheet.create({
page: {
flex: 1,
height: 130,
resizeMode: 'stretch'
},
});
"dependencies": {
"react": "16.0.0-alpha.12",
"react-native": "0.45.1",
"react-native-tab-navigator": "^0.3.3",
"react-native-viewpager": "^0.2.13"
},
2d1741b
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
最好给View一个大小 @Lcn29
2d1741b
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@yuanguozhen
g 给ViewPager 外层的View 设置一个和ViewPager一样的高度,可以解决1,3问题
如果需要保留自动轮播的效果,怎么解决最后一张跳到第一张闪一下的问题呢,还有怎么设置他轮播的时间,
2d1741b
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Lcn29 闪的问题应该是这个第三方控件的bug,你可以看看这个ViewPager控件的最新版本是否解决了,如果没有解决,看下源码自己改下好了,其实也不难
2d1741b
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
我写上 报这个错
undefined is not an object(evaluating 'React.PropTypes.fun ')
2d1741b
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@liulee1514 你的RN版本是不是0.5?