广告屏react-native项目
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 
 
 

1300 行
36 KiB

  1. import React, { Component } from 'react';
  2. import {
  3. Platform,
  4. StyleSheet,
  5. Text,
  6. View,
  7. Image,
  8. ImageBackground,
  9. PixelRatio,
  10. NativeModules,
  11. } from 'react-native';
  12. //引用插件
  13. import Package from './package.json'
  14. import HttpUtils from './HttpUtils.js';
  15. import CodePush from "react-native-code-push";
  16. import DeviceInfo from "react-native-device-info";
  17. import * as Animatable from 'react-native-animatable';
  18. import Swiper from 'react-native-swiper';
  19. import Carousel from 'react-native-snap-carousel';
  20. // import {BoxShadow} from 'react-native-shadow';
  21. var testMac = 'FF:FF:FF:FF:FF:FF'
  22. var curAdIndex = 0;
  23. var errorMsg = {
  24. ERR_MAC_GET:'设备编号获取错误',
  25. ERR_START_AD:'广告播放系统错误',
  26. ERR_DATA_GET:'广告数据获取错误',
  27. ERR_HEARTBEAT:'设备心跳数据错误',
  28. ERR_NO_DATA:'暂无优惠信息'
  29. }
  30. var animationThemes = [
  31. // 滑入
  32. {
  33. first:"slideInDown",
  34. second:"slideInLeft",
  35. third:"slideInRight"
  36. },
  37. // 放大
  38. {
  39. first:"zoomInDown",
  40. second:"zoomInLeft",
  41. third:"zoomInRight"
  42. },
  43. // 翻转
  44. {
  45. first:"flipInX",
  46. second:"flipInY",
  47. third:"flipInX"
  48. },
  49. // 弹出
  50. {
  51. first:"bounceInDown",
  52. second:"bounceInLeft",
  53. third:"bounceInRight"
  54. }
  55. ]
  56. const shadowOpt = {
  57. width: 800/PixelRatio.get(),
  58. height: 240/PixelRatio.get(),
  59. color:"#000",
  60. border:2,
  61. radius:3,
  62. opacity:0.5,
  63. x:2,
  64. y:3,
  65. style:{marginVertical:5}
  66. }
  67. var curTimer = null;
  68. var hbRequestCount
  69. var getAdDataCount
  70. var pageChangeCount
  71. var adDataList = [];
  72. var adDataBgList = [];
  73. var heartConfig = {
  74. heartbeatInterval:300,
  75. dataRefreshInterval:3600,
  76. pageChangeInterval:10,
  77. }
  78. var requestFailedCount = 0;
  79. var versionInfo = '';
  80. let codePushOptions = {
  81. //设置检查更新的频率
  82. //ON_APP_RESUME APP恢复到前台的时候
  83. //ON_APP_START APP开启的时候
  84. //MANUAL 手动检查
  85. checkFrequency : CodePush.CheckFrequency.ON_APP_START
  86. };
  87. export default class MyPage extends Component {
  88. constructor(props) {
  89. super(props);
  90. this.state = {
  91. baseInfo: null,
  92. contentItem0:null,
  93. contentItem1:null,
  94. contentItem2:null,
  95. animationTheme:animationThemes[0],
  96. contentDisplayStatus:false,
  97. syncMessage: "初始化..." ,
  98. errorMessage: '加载中...',
  99. progress: {
  100. receivedBytes:0,
  101. totalBytes:0
  102. },
  103. updating:true,
  104. macAddress: '',
  105. versionInfo:'未知',
  106. adType: 0,
  107. curAdType02Index: 0, //广告图index
  108. coverImgUrl: '',
  109. previewImg: '',
  110. curImgState: false,
  111. };
  112. /* this.codePushUpdate = this.codePushUpdate.bind(this);
  113. this.startAd = this.startAd.bind(this);
  114. this.showErrMsg = this.showErrMsg.bind(this); */
  115. }
  116. componentDidMount() {
  117. this.codePushUpdate();
  118. DeviceInfo.getMACAddress().then((mac)=>{
  119. if (mac=='' || mac==null ) {
  120. if (NativeModules.BuildConfig.buildType == 'debug') {
  121. this.setState({macAddress : this.testMac})
  122. this.startAd()
  123. } else {
  124. this.showErrMsg(errorMsg.ERR_MAC_GET);
  125. }
  126. } else {
  127. this.setState({macAddress : mac})
  128. this.startAd()
  129. }
  130. }).catch(e => {
  131. this.showErrMsg(errorMsg.ERR_START_AD);
  132. })
  133. }
  134. componentDidUpdate() {
  135. /* console.log(this.refs.scrollView)
  136. if (this.refs.scrollView != undefined) {
  137. var ScrollView = this.refs.scrollView;
  138. ScrollView.scrollBy(0, true);
  139. } */
  140. }
  141. //更新函数
  142. async codePushUpdate() {
  143. CodePush.allowRestart();
  144. await CodePush.getUpdateMetadata(CodePush.UpdateState.RUNNING)
  145. .then((metadata: LocalPackage) => {
  146. this.setState({ versionInfo: metadata ? 'b'+NativeModules.BuildConfig.versionCode+"-" + metadata.label : 'b'+ NativeModules.BuildConfig.versionCode});
  147. versionInfo = this.state.versionInfo;
  148. }, (error: any) => {
  149. this.setState({ versionInfo: "Unknown"});
  150. versionInfo = this.state.versionInfo;
  151. });
  152. await CodePush.sync(
  153. { mandatoryInstallMode: CodePush.InstallMode.ON_NEXT_RESTART,
  154. installMode: CodePush.InstallMode.ON_NEXT_RESTART},
  155. this.codePushStatusDidChange.bind(this),
  156. this.codePushDownloadDidProgress.bind(this)
  157. ).then((status: SyncStatus) => {
  158. }, (error: any) => {
  159. console.log(error)
  160. // CodePush.restartApp();
  161. });
  162. }
  163. // 监听更新状态
  164. codePushStatusDidChange(syncStatus) {
  165. switch(syncStatus) {
  166. case CodePush.SyncStatus.CHECKING_FOR_UPDATE:
  167. this.setState({ syncMessage: "检查更新" });
  168. break;
  169. case CodePush.SyncStatus.DOWNLOADING_PACKAGE:
  170. this.setState({ syncMessage: "下载更新" });
  171. break;
  172. case CodePush.SyncStatus.AWAITING_USER_ACTION:
  173. this.setState({ syncMessage: "等待用户操作" });
  174. break;
  175. case CodePush.SyncStatus.INSTALLING_UPDATE:
  176. this.setState({ syncMessage: "安装更新" });
  177. break;
  178. case CodePush.SyncStatus.UP_TO_DATE:
  179. this.setState({ syncMessage: "已更新到最新程序", updating: false });
  180. break;
  181. case CodePush.SyncStatus.UPDATE_IGNORED:
  182. this.setState({ syncMessage: "更新被取消", updating: false });
  183. break;
  184. case CodePush.SyncStatus.UPDATE_INSTALLED:
  185. this.setState({ syncMessage: "更新已安装,重启应用后生效", updating: false });
  186. break;
  187. case CodePush.SyncStatus.UNKNOWN_ERROR:
  188. this.setState({ syncMessage: "未知错误", updating: false });
  189. break;
  190. }
  191. }
  192. codePushDownloadDidProgress(progress) {
  193. this.setState({ progress });
  194. }
  195. // 列表滚动
  196. updateContent() {
  197. if (adDataList.length <=0)
  198. return false;
  199. if (curAdIndex >= adDataList.length) {
  200. curAdIndex = 0;
  201. }
  202. this.setState({contentItem0:adDataList[curAdIndex]});
  203. if (curAdIndex + 1 < adDataList.length)
  204. this.setState({contentItem1:adDataList[curAdIndex+1]});
  205. else
  206. this.setState({contentItem1:null});
  207. if (curAdIndex + 2 < adDataList.length)
  208. this.setState({contentItem2:adDataList[curAdIndex+2]});
  209. else
  210. this.setState({contentItem2:null});
  211. curAdIndex+=3
  212. return true;
  213. }
  214. hbRequest() {
  215. return HttpUtils.post(NativeModules.BuildConfig.apiHost
  216. + 'api/wxDeviceScreenAd/heartbeat?deviceId='
  217. + encodeURIComponent(this.state.macAddress),
  218. {version:this.state.versionInfo})
  219. .then(result => {
  220. if (result.code == 200) {
  221. let config = JSON.parse(result.data.config);
  222. heartConfig.heartbeatInterval = config.heartbeatInterval
  223. heartConfig.dataRefreshInterval=config.dataRefreshInterval
  224. heartConfig.pageChangeInterval=config.pageChangeInterval
  225. // 动画划入
  226. if(config.animationTheme == 0){
  227. this.setState({
  228. animationTheme:animationThemes[0]
  229. })
  230. }else if(config.animationTheme == 1){
  231. // 放大
  232. this.setState({
  233. animationTheme:animationThemes[1]
  234. })
  235. }else if(config.animationTheme == 2){
  236. // 淡入
  237. this.setState({
  238. animationTheme:animationThemes[2]
  239. })
  240. }else if(config.animationTheme == 3){
  241. // 弹入
  242. this.setState({
  243. animationTheme:animationThemes[3]
  244. })
  245. }
  246. } else {
  247. //do nothing
  248. }
  249. })
  250. .catch(error => {
  251. requestFailedCount++
  252. this.setState({ versionInfo: versionInfo+`[${requestFailedCount}]`});
  253. })
  254. }
  255.  showErrMsg(errMsg) {
  256. this.setState({contentDisplayStatus: false})
  257. this.setState({errorMessage : errMsg});
  258. }
  259. //判断播放类型adType
  260. dealLoopType(dataList) {
  261. adDataList = dataList.filter((item) => {
  262. return item.type == 0;
  263. })
  264. adDataBgList = dataList.filter((item) => {
  265. return item.type == 2;
  266. })
  267. //aaa
  268. let num = 0;
  269. if (adDataList.length > 0 && adDataBgList.length > 0) {
  270. num = 2;
  271. this.setState({previewImg: adDataBgList[0].coverImg});
  272. } else if (adDataList.length > 0 && !adDataBgList.length) {
  273. num = 0;
  274. } else if (!adDataList.length && adDataBgList.length > 0) {
  275. num = 1;
  276. }
  277. this.setState({adType: num })
  278. }
  279. getAdDataList(first) {
  280. HttpUtils.get(NativeModules.BuildConfig.apiHost
  281. + 'api/wxDeviceScreenAd/list?deviceId='
  282. + encodeURIComponent(this.state.macAddress)
  283. + '&pageNum=1&pageSize=1000')
  284. .then(result => {
  285. if (result.code != 200) {
  286. this.showErrMsg(result.message+'\n'+this.state.macAddress);
  287. } else if (result.data.list) {
  288. //aaa
  289. //type==0的是券 1是? 2是广告大图
  290. let curData = result.data.list;
  291. this.dealLoopType(curData);
  292. if (this.updateContent()) {
  293. this.setState({contentDisplayStatus: true})
  294. } else {
  295. this.showErrMsg(errorMsg.ERR_NO_DATA);
  296. }
  297. } else {
  298.  this.showErrMsg(errorMsg.ERR_DATA_GET);
  299. }
  300. })
  301. .catch(error => {
  302. if (first) {
  303. this.showErrMsg(error.message);
  304. }
  305. else {
  306. requestFailedCount++
  307. this.setState({ versionInfo: versionInfo+`[${requestFailedCount}]`});
  308. }
  309. })
  310. }
  311. getBaseInfo() {
  312. HttpUtils.get(NativeModules.BuildConfig.apiHost
  313. + 'api/wxDeviceScreenAd/info?deviceId='
  314. + encodeURIComponent(this.state.macAddress))
  315. .then(result => {
  316. if (result.code != 200) {
  317. this.showErrMsg(result.message+'\n'+this.state.macAddress);
  318. } else if (result.data) {
  319. this.setState({baseInfo:result.data});
  320. } else {
  321. this.showErrMsg(errorMsg.ERR_DATA_GET);
  322. }
  323. })
  324. .catch(error => {
  325. this.showErrMsg(error.message);
  326. })
  327. }
  328. componentWillUnmount(){
  329. if (curTimer)
  330. clearTimeout(curTimer)
  331. }
  332. async routine() {
  333. hbRequestCount -=1;
  334. getAdDataCount -=1;
  335. if (this.state.adType == 2 && this.state.curImgState) {
  336. pageChangeCount -=1;
  337. }
  338. if (this.state.adType != 2) {
  339. pageChangeCount -=1;
  340. }
  341. try {
  342. if (getAdDataCount<=0) {
  343. this.getAdDataList(false)
  344. getAdDataCount = heartConfig.dataRefreshInterval
  345. } else if (hbRequestCount<=0) {
  346. this.hbRequest()
  347. hbRequestCount = heartConfig.heartbeatInterval
  348. }
  349. //如果是adType == 2时间间隔到了,要检验轮播是否走完在决定切换
  350. if (this.state.adType == 2) {
  351. if (pageChangeCount<=0) {
  352. let curNum = this.state.curAdType02Index + 1;
  353. if (curNum >= adDataBgList.length) {
  354. curNum = 0;
  355. }
  356. this.setState({
  357. curAdType02Index: curNum,
  358. previewImg:adDataBgList[curNum].coverImg
  359. })
  360. pageChangeCount = heartConfig.pageChangeInterval
  361. }
  362. } else if (this.state.adType == 0) {
  363. if (pageChangeCount <= 0) { //页面切换间隔
  364. if (this.state.contentDisplayStatus && this.state.baseInfo) {
  365. this.setState({ contentDisplayStatus: false})
  366. if (this.updateContent()) {
  367. this.setState({ contentDisplayStatus: true})
  368. }
  369. } else {
  370. await this.getBaseInfo()
  371. await this.getAdDataList(true)
  372. getAdDataCount = heartConfig.dataRefreshInterval
  373. hbRequestCount = heartConfig.heartbeatInterval
  374. }
  375. pageChangeCount = heartConfig.pageChangeInterval
  376. }
  377. }
  378. } catch(e){
  379. this.setState({ versionInfo: versionInfo+'[E]'});
  380. }
  381. curTimer = setTimeout(()=>{
  382. this.routine();
  383. },1000);
  384. }
  385. startAd() {
  386. hbRequestCount = 0;
  387. getAdDataCount = 0;
  388. pageChangeCount = 0;
  389. this.routine();
  390. }
  391. getContentViewItemUplayer(contentItem) {
  392. if (contentItem.type == 0) {
  393. if (contentItem.subType == 2)
  394. return (<Image source={require('./image/timed.png')} resizeMode='center' style={styles.contentItemUpLayer} /> )
  395. if (contentItem.subType == 6)
  396. return (<Image source={require('./image/discount.png')} resizeMode='center' style={styles.contentItemUpLayer} /> )
  397. if (contentItem.subType == 7)
  398. return (<Image source={require('./image/groupbuy.png')} resizeMode='center' style={styles.contentItemUpLayer} /> )
  399. return null;
  400. }
  401. }
  402. getContentViewItemActionStr(contentItem) {
  403. if (contentItem.type == 0) {
  404. if (contentItem.subType == 2)
  405. return '扫码秒杀';
  406. else if (contentItem.subType == 6)
  407. return '扫码砍价';
  408. else if (contentItem.subType == 7)
  409. return '扫码拼团';
  410. else
  411. return '扫码领取';
  412. }
  413. }
  414. getContentViewItemMerchantName(contentItem) {
  415. if (contentItem.type == 0) {
  416. if (contentItem.target.merchantVoList.length > 1)
  417. return '多商户通用';
  418. else
  419. return contentItem.target.merchantVoList[0].merchantName;
  420. }
  421. }
  422. getContentViewItem(contentItem, annomation) {
  423. if (!contentItem)
  424. return (
  425. <View style={styles.contentItem}>
  426. </View>
  427. )
  428. actionText = this.getContentViewItemActionStr(contentItem);
  429. merchantName = this.getContentViewItemMerchantName(contentItem);
  430. // console.warn(annomation)
  431. return (
  432. <Animatable.View animation={annomation} style={styles.contentItem}>
  433. <ImageBackground source={require('./image/item-background.png')} resizeMode='center' style={styles.contentItemDownLayer} >
  434. {/* 列表 */}
  435. <View style={styles.contentItemTop}>
  436. <Image source={{uri: contentItem.coverImg}} resizeMode='cover' style={styles.contentItemTopCoverImg} />
  437. <View style={styles.contentItemTopDetail}>
  438. {/* 券的title */}
  439. <Text style={styles.contentItemTopDetailTitle} numberOfLines={2} ellipsizeMode="tail">{contentItem.target.title}</Text>
  440. <View style={styles.contentItemTopDetailPrice}>
  441. {/* 售价 */}
  442. <View style={styles.contentItemTopDetailCurPrice}>
  443. <Text style={styles.contentItemTopDetailCurPriceStrUnit}>¥</Text>
  444. <Text style={styles.contentItemTopDetailCurPriceStr}>{contentItem.target.salePriceStr}</Text>
  445. </View>
  446. {/* 面额 */}
  447. <View style={styles.contentItemTopDetailSalePrice}>
  448. <Text style={styles.contentItemTopDetailSalePriceStr} >¥{contentItem.target.priceStr}</Text>
  449. </View>
  450. </View>
  451. </View>
  452. {/* <Image source={{uri:'data:image/png;base64,'+contentItem.qrcode}} resizeMode='contain' style={styles.contentItemTopQrcode} /> */}
  453. <Image source={{uri:contentItem.target.qrCode}} resizeMode='contain' style={styles.contentItemTopQrcode} />
  454. </View>
  455. {/* 优惠券底部商户名称 */}
  456. <View style={styles.contentItemBottom}>
  457. <Text style={styles.contentItemBottomMerchantName}>{merchantName}</Text>
  458. <Text style={styles.contentItemBottomPlacehold}>{contentItem.target.merchantVoList[0].buildingName}{contentItem.target.merchantVoList[0].floorName}</Text>
  459. <Text style={styles.contentItemBottomAction}>{actionText}</Text>
  460. </View>
  461. </ImageBackground>
  462. {this.getContentViewItemUplayer(contentItem)}
  463. </Animatable.View>
  464. )
  465. }
  466. getContentView() {
  467. if (this.state.contentDisplayStatus) {
  468. return (<View style={styles.content}>
  469. {this.getContentViewItem(this.state.contentItem0,this.state.animationTheme.first)}
  470. {this.getContentViewItem(this.state.contentItem1,this.state.animationTheme.second)}
  471. {this.getContentViewItem(this.state.contentItem2,this.state.animationTheme.third)}
  472. </View>)
  473. }else{
  474. return (
  475. <View style={styles.content}>
  476. <Text style={styles.updatePage}>{this.state.errorMessage}</Text>
  477. </View>)
  478. }
  479. }
  480. setAdSwiperItemDom(item) {
  481. let contentItem = item.item;
  482. return (
  483. <View style={styles.onlyAdSwiperItem}>
  484. <Image source={{uri: contentItem.coverImg}} resizeMode='stretch' style={styles.onlyAdTypeItemImg} />
  485. </View>
  486. )
  487. }
  488. setSwiperItemDom(item) {
  489. let contentItem = item.item;
  490. let index = item.index;
  491. let curLogo = null;
  492. if (contentItem.type == 0) {
  493. if (contentItem.subType == 2)
  494. curLogo = require('./image/timed.png');
  495. if (contentItem.subType == 6)
  496. curLogo = require('./image/discount.png');
  497. if (contentItem.subType == 7)
  498. curLogo = require('./image/groupbuy.png');
  499. }
  500. return (
  501. <View style={styles.carouselItemWrap}>
  502. {/* <BoxShadow setting={shadowOpt}> */}
  503. <View setting={shadowOpt}>
  504. <View style={styles.contentItemTopForAd} key={index}>
  505. <Image source={curLogo} resizeMode='center' style={styles.contentItemUpLayerLogo} />
  506. {/* <ImageBackground style={styles.adTypeSwiper02} resizeMode="stretch" source={require('./image/item-background.png')}></ImageBackground> */}
  507. <Image source={{uri: contentItem.coverImg}} resizeMode='cover' style={styles.adTypeItemImg} />
  508. <View style={styles.contentItemTopDetail}>
  509. {/* 券的title */}
  510. <Text style={styles.contentItemTopDetailTitle02} numberOfLines={2} ellipsizeMode="tail">{contentItem.target.title}</Text>
  511. <View style={styles.contentItemTopDetailPrice}>
  512. {/* 售价 */}
  513. <View style={styles.contentItemTopDetailCurPrice}>
  514. <Text style={styles.contentItemTopDetailCurPriceStrUnit02}>¥</Text>
  515. <Text style={styles.contentItemTopDetailCurPriceStr02}>{contentItem.target.salePriceStr}</Text>
  516. </View>
  517. {/* 面额 */}
  518. <View style={styles.contentItemTopDetailSalePrice02}>
  519. <Text style={styles.contentItemTopDetailSalePriceStr02} >¥{contentItem.target.priceStr}</Text>
  520. </View>
  521. </View>
  522. </View>
  523. {/* <Image source={{uri:'data:image/png;base64,'+contentItem.qrcode}} resizeMode='contain' style={styles.contentItemTopQrcode} /> */}
  524. <View style={styles.contentItemTopQrcodeBox}>
  525. <Image source={{uri:contentItem.target.qrCode}} resizeMode='contain' style={styles.contentItemTopQrcode02} />
  526. </View>
  527. </View>
  528. </View>
  529. {/* </BoxShadow> */}
  530. </View>
  531. )
  532. }
  533. getUpdateView() {
  534. if (this.state.progress.totalBytes > 0)
  535. return (
  536. <Text style={styles.updatePage}>{this.state.syncMessage}{'\n'}
  537. {this.state.progress.receivedBytes} of {this.state.progress.totalBytes} bytes received{'\n'}
  538. </Text>
  539. );
  540. return (
  541. <Text style={styles.updatePage}>{this.state.syncMessage}
  542. </Text>
  543. );
  544. }
  545. rendDefaultImg() {
  546. if (this.state.coverImgUrl) {
  547. return (
  548. <ImageBackground style={styles.adTypeBg} resizeMode="stretch" source={{uri: this.state.coverImgUrl}}></ImageBackground>
  549. )
  550. } else {
  551. return (
  552. <ImageBackground style={styles.adTypeBg} resizeMode="stretch" source={require('./image/background.png')}></ImageBackground>
  553. )
  554. }
  555. }
  556. getAdView(){
  557. if (this.state.baseInfo) {
  558. if (this.state.adType == 0) {
  559. return (
  560. <ImageBackground style={styles.background} resizeMode='center' source={require('./image/background.png')}>
  561. {/* 头部title二维码开始 */}
  562. <View style={styles.title}>
  563. <View style={styles.titleImagePlace}>
  564. <Image source={require('./image/title.png')} resizeMode='center' style={styles.titleImage} />
  565. </View>
  566. <ImageBackground source={require('./image/title-qrcode.png') } resizeMode='center' style={styles.titleQrcodeBonder} >
  567. <View style={styles.titleQrcodePlacehold}></View>
  568. <Image source={{uri: this.state.baseInfo.imgQrcodeWeapp}} resizeMode='center' style={styles.titleQrcode} />
  569. <View style={styles.titleQrcodePlacehold}></View>
  570. </ImageBackground>
  571. </View>
  572. {/* 券列表展示列表开始 */}
  573. {this.getContentView()}
  574. {/* 底部商场信息展示开始 */}
  575. <View style={styles.bottom}>
  576. <View style={styles.bottomLogoBackground}>
  577. <Image source={{ uri: this.state.baseInfo.imgUrlH}} resizeMode='contain' style={styles.bottomLogo} />
  578. </View>
  579. <View style={styles.bottomQrcode1Background}>
  580. <Image source={{ uri: this.state.baseInfo.imgQrcodeWeapp}} resizeMode='center' style={styles.bottomQrcode1} />
  581. <Text style={styles.bottomQrcode1Str}>小程序</Text>
  582. </View>
  583. <View style={styles.bottomQrcode2Background}>
  584. <Image source={{ uri: this.state.baseInfo.imgQrcodeWemp}} resizeMode='center' style={styles.bottomQrcode2} />
  585. <Text style={styles.bottomQrcode1Str}>公众号</Text>
  586. </View>
  587. <Text style={styles.bottomPlacehold}>{this.state.versionInfo}</Text>
  588. </View>
  589. </ImageBackground>
  590. );
  591. } else if (this.state.adType == 2) {
  592. let curWidthNum = 1080/(PixelRatio.get());
  593. return (
  594. // <ImageBackground style={styles.adTypeBg} source={require('./image/ad1.jpg')}> slideInDown zoomInDown
  595. <View style={styles.adWrapBox}>
  596. <Image style={styles.adWrapHideImg}
  597. onLoadStart={() => {
  598. this.setState({
  599. curImgState: false
  600. })
  601. }}
  602. onLoad={() => {
  603. this.setState({
  604. coverImgUrl: this.state.previewImg,
  605. curImgState: true
  606. })
  607. }}
  608. resizeMode="stretch" source={{uri: this.state.previewImg}}>
  609. </Image>
  610. <Animatable.View animation="fadeIn" style={styles.adWrap} key={this.state.coverImgUrl}>
  611. {this.rendDefaultImg()}
  612. </Animatable.View>
  613. <View style={styles.adTypeSwiper02}>
  614. <Carousel
  615. style={styles.adTypeSwiper02Content}
  616. ref={'carousel02'}
  617. data={adDataList}
  618. renderItem={this.setSwiperItemDom}
  619. sliderWidth={curWidthNum}
  620. itemWidth={curWidthNum}
  621. layout={'stack'}
  622. activeSlideOffset={0}
  623. autoplay={true}
  624. loop={true}
  625. autoplayInterval={5000}
  626. />
  627. </View>
  628. </View>
  629. );
  630. } else if (this.state.adType == 1) {
  631. let curWidthNum = 1080/(PixelRatio.get())
  632. return(
  633. <Carousel
  634. ref={'carousel01'}
  635. data={adDataBgList}
  636. renderItem={this.setAdSwiperItemDom}
  637. sliderWidth={curWidthNum}
  638. itemWidth={curWidthNum}
  639. activeSlideOffset={0}
  640. autoplay={true}
  641. loop={true}
  642. autoplayInterval={5000}
  643. />
  644. )
  645. }
  646. }
  647. else {
  648. return (
  649. <ImageBackground style={styles.background} resizeMode='center' source={require('./image/background.png')}>
  650. {/* 头部title二维码开始 */}
  651. <View style={styles.title}>
  652. </View>
  653. {/* 券列表展示列表开始 */}
  654. {this.getContentView()}
  655. {/* 底部商场信息展示开始 */}
  656. <View style={styles.bottom}>
  657. <View style={styles.bottomLogoBackground}>
  658. </View>
  659. <View style={styles.bottomQrcode1Background}>
  660. </View>
  661. <View style={styles.bottomQrcode2Background}>
  662. </View>
  663. <Text style={styles.bottomPlacehold}>{this.state.versionInfo}</Text>
  664. </View>
  665. </ImageBackground>
  666. );
  667. }
  668. }
  669. render() {
  670. if (this.state.updating) {
  671. return this.getUpdateView();
  672. }
  673. return this.getAdView();
  674. }
  675. }
  676. MyPage = CodePush(codePushOptions)(MyPage);
  677. const styles = StyleSheet.create({
  678. updatePage:{
  679. flex: 2,
  680. width:'100%',
  681. height:'100%',
  682. backgroundColor:'transparent',
  683. textAlign :'center',
  684. textAlignVertical:'center',
  685. fontSize: 63/PixelRatio.get(),
  686. color: 'darkblue'
  687. },
  688. //layer background
  689. background:{
  690. flex: 1,
  691. width:'100%',
  692. height:'100%'
  693. },
  694. //layer top
  695. title:{
  696. flex: 6,
  697. flexDirection: 'row',
  698. alignItems: 'center',
  699. paddingLeft:42/PixelRatio.get(),
  700. paddingRight:42/PixelRatio.get(),
  701. backgroundColor:'transparent'
  702. },
  703. content:{
  704. flex: 18,
  705. flexDirection: 'column',
  706. alignItems: 'center',
  707. backgroundColor:'transparent'
  708. },
  709. bottom:{
  710. flex: 2,
  711. flexDirection: 'row',
  712. alignItems: 'center',
  713. paddingLeft:42/PixelRatio.get(),
  714. paddingRight:42/PixelRatio.get(),
  715. backgroundColor:'transparent'
  716. },
  717. //layer title
  718. titleImagePlace: {
  719. flex: 2,
  720. paddingTop: '20%',
  721. paddingLeft: '15%',
  722. alignItems: 'center',
  723. backgroundColor:'transparent'
  724. },
  725. titleImage: {
  726. width:'100%',
  727. height:'100%',
  728. flex: 1,
  729. backgroundColor:'transparent'
  730. },
  731. titleQrcodeBonder: {
  732. width:'100%',
  733. height:'100%',
  734. alignItems: 'center',
  735. flexDirection: 'column',
  736. flex: 1,
  737. backgroundColor:'transparent'
  738. },
  739. titleQrcodePlacehold: {
  740. flex: 5,
  741. backgroundColor:'transparent'
  742. },
  743. titleQrcode: {
  744. flex: 6,
  745. width:'100%',
  746. height:'100%',
  747. backgroundColor:'transparent'
  748. },
  749. //layer bottom
  750. bottomLogoBackground: {
  751. flex: 3,
  752. borderRadius:16/PixelRatio.get(),
  753. marginTop: 26/PixelRatio.get(),
  754. marginBottom: 26/PixelRatio.get(),
  755. backgroundColor:'transparent',//'rgba(255,255,255,0.5)',
  756. },
  757. bottomLogo: {
  758. width:'100%',
  759. height:'100%',
  760. backgroundColor:'transparent'
  761. },
  762. bottomQrcode1Background : {
  763. flex: 1,
  764. width:'100%',
  765. height:'100%',
  766. marginLeft: 21/PixelRatio.get(),
  767. paddingTop: 27/PixelRatio.get(),
  768. paddingBottom: 11/PixelRatio.get(),
  769. flexDirection: 'column',
  770. backgroundColor:'transparent'
  771. },
  772. bottomQrcode2Background : {
  773. flex: 1,
  774. width:'100%',
  775. height:'100%',
  776. marginLeft: 21/PixelRatio.get(),
  777. paddingTop: 26/PixelRatio.get(),
  778. paddingBottom: 11/PixelRatio.get(),
  779. flexDirection: 'column',
  780. backgroundColor:'transparent'
  781. },
  782. bottomQrcode1: {
  783. flex: 2,
  784. width:'100%',
  785. height:'100%',
  786. backgroundColor:'transparent'
  787. },
  788. bottomQrcode2: {
  789. flex: 2,
  790. width:'100%',
  791. height:'100%',
  792. backgroundColor:'transparent'
  793. },
  794. bottomQrcode1Str: {
  795. flex: 1,
  796. textAlign :'center',
  797. textAlignVertical:'center',
  798. fontSize: 16/PixelRatio.get(),
  799. color : 'white',
  800. backgroundColor:'transparent'
  801. },
  802. bottomQrcode2Str: {
  803. flex: 1,
  804. textAlign :'center',
  805. textAlignVertical:'center',
  806. fontSize: 16/PixelRatio.get(),
  807. color : 'white',
  808. backgroundColor:'transparent'
  809. },
  810. bottomPlacehold: {
  811. flex: 8,
  812. width:'100%',
  813. height:'100%',
  814. backgroundColor:'transparent',
  815. textAlign :'right',
  816. textAlignVertical:'bottom',
  817. fontSize: 27/PixelRatio.get(),
  818. color : 'gray'
  819. },
  820. //layer content item
  821. contentItem:{
  822. flex: 1,
  823. width:'100%',
  824. height:'100%',
  825. flexDirection: 'column',
  826. backgroundColor:'transparent'
  827. },
  828. contentItemDownLayer:{
  829. position:'absolute',
  830. width:'100%',
  831. height:'100%',
  832. flexDirection: 'column',
  833. alignItems: 'center',
  834. backgroundColor:'transparent'
  835. },
  836. contentItemUpLayer:{
  837. width:210/PixelRatio.get(),
  838. height:153/PixelRatio.get(),
  839. position:'absolute',
  840. backgroundColor:'transparent'
  841. },
  842. contentItemUpLayerLogo: {
  843. width:160/PixelRatio.get(),
  844. height:83/PixelRatio.get(),
  845. position: 'absolute',
  846. left: -20/PixelRatio.get(),
  847. top: 20/PixelRatio.get(),
  848. zIndex:100,
  849. backgroundColor: 'transparent',
  850. },
  851. contentItemTop:{
  852. flex: 3,
  853. width:'100%',
  854. height:'100%',
  855. paddingLeft: 66/PixelRatio.get(),
  856. paddingRight: 53/PixelRatio.get(),
  857. paddingTop: 40/PixelRatio.get(),
  858. flexDirection: 'row',
  859. alignItems: 'center',
  860. backgroundColor:'transparent'
  861. },
  862. contentItemBottom:{
  863. flex: 1,
  864. width:'100%',
  865. height:'100%',
  866. paddingLeft: 66/PixelRatio.get(),
  867. paddingRight: 53/PixelRatio.get(),
  868. paddingBottom: 40/PixelRatio.get(),
  869. flexDirection: 'row',
  870. alignItems: 'center',
  871. backgroundColor:'transparent'
  872. },
  873. //layer content item top
  874. contentItemTopCoverImg:{
  875. flex: 5,
  876. width:'100%',
  877. height:'100%',
  878. borderRadius:27/PixelRatio.get(),
  879. backgroundColor:'transparent'
  880. },
  881. contentItemTopDetail:{
  882. flex: 6,
  883. width:'100%',
  884. height:'100%',
  885. paddingLeft: 20/PixelRatio.get(),
  886. paddingRight: 20/PixelRatio.get(),
  887. alignItems: 'center',
  888. backgroundColor:'transparent'
  889. },
  890. contentItemTopQrcode:{
  891. flex: 5,
  892. width:'100%',
  893. height:'100%',
  894. marginLeft:18/PixelRatio.get(),
  895. // backgroundColor:'transparent'
  896. },
  897. contentItemTopQrcodeBox:{
  898. flex: 5,
  899. width:'100%',
  900. height:'100%',
  901. flexDirection: 'column',
  902. alignItems: 'center',
  903. justifyContent: 'center',
  904. marginLeft: -28/PixelRatio.get(),
  905. // backgroundColor:'transparent'
  906. },
  907. contentItemTopQrcode02:{
  908. width:'90%',
  909. height:'90%',
  910. },
  911. //layer content item bottom
  912. contentItemBottomMerchantName:{
  913. flex: 5,
  914. width:'100%',
  915. height:'100%',
  916. alignItems: 'center',
  917. color:"black",
  918. backgroundColor:'transparent',
  919. textAlign :'center',
  920. textAlignVertical:'center',
  921. fontSize: 27/PixelRatio.get(),
  922. fontWeight : 'bold',
  923. },
  924. contentItemBottomPlacehold:{
  925. flex: 6,
  926. fontSize: 27/PixelRatio.get(),
  927. paddingLeft: 27/PixelRatio.get(),
  928. paddingRight: 79/PixelRatio.get(),
  929. width:'100%',
  930. height:'100%',
  931. color:"black",
  932. textAlignVertical:'center',
  933. backgroundColor:'transparent',
  934. },
  935. contentItemBottomAction:{
  936. flex: 5,
  937. width:'100%',
  938. height:'100%',
  939. backgroundColor:'transparent',
  940. textAlign :'center',
  941. textAlignVertical:'center',
  942. fontSize: 36/PixelRatio.get(),
  943. color: 'black',
  944. },
  945. contentItemBottomAction02:{
  946. width:'100%',
  947. height: 60/PixelRatio.get(),
  948. backgroundColor:'transparent',
  949. textAlign :'center',
  950. textAlignVertical:'center',
  951. fontSize: 36/PixelRatio.get(),
  952. color: 'black',
  953. },
  954. // 券的title
  955. contentItemTopDetailTitle:{
  956. flex: 2,
  957. // height:'100%',
  958. width:'100%',
  959. marginTop:"2%",
  960. backgroundColor:'transparent',
  961. textAlign :'left',
  962. color:"black",
  963. textAlignVertical:'center',
  964. fontSize: 53/PixelRatio.get(),
  965. },
  966. // 券的title
  967. contentItemTopDetailTitle02:{
  968. flex: 2,
  969. // height:'100%',
  970. width:'100%',
  971. marginTop:"2%",
  972. paddingRight: 14/PixelRatio.get(),
  973. backgroundColor:'transparent',
  974. textAlign :'left',
  975. color:"black",
  976. textAlignVertical:'center',
  977. fontSize: 42/PixelRatio.get(),
  978. },
  979. /*
  980. contentItemTopDetailRemark:{
  981. flex: 1,
  982. width:'100%',
  983. height:'100%',
  984. backgroundColor:'transparent',
  985. textAlign :'left',
  986. textAlignVertical:'center',
  987. fontSize: 27/PixelRatio.get(),
  988. color : 'gray'
  989. },
  990. */
  991. contentItemTopDetailPrice:{
  992. flex: 2,
  993. width:'100%',
  994. height:'100%',
  995. backgroundColor:'transparent',
  996. flexDirection: 'row',
  997. },
  998. // 售价的样式
  999. contentItemTopDetailCurPrice:{
  1000. position:"absolute",
  1001. bottom:10,
  1002. left:0,
  1003. width:'100%',
  1004. height:'100%',
  1005. flexDirection: 'row',
  1006. backgroundColor:'transparent',
  1007. },
  1008. contentItemTopDetailCurPriceStr:{
  1009. backgroundColor:'transparent',
  1010. fontSize:96/PixelRatio.get(),
  1011. fontFamily:"PingFangSC-Bold",
  1012. fontWeight: "bold",
  1013. textAlign :'left',
  1014. textAlignVertical:'bottom',
  1015. color : 'red'
  1016. },
  1017. contentItemTopDetailCurPriceStr02:{
  1018. backgroundColor:'transparent',
  1019. fontSize:72/PixelRatio.get(),
  1020. fontFamily:"PingFangSC-Bold",
  1021. fontWeight: "bold",
  1022. textAlign :'left',
  1023. color : 'red'
  1024. },
  1025. contentItemTopDetailCurPriceStrUnit:{
  1026. backgroundColor:'transparent',
  1027. textAlign :'left',
  1028. textAlignVertical:'bottom',
  1029. paddingBottom: 16/PixelRatio.get(),
  1030. fontSize: 48/PixelRatio.get(),
  1031. color : 'red'
  1032. },
  1033. contentItemTopDetailCurPriceStrUnit02:{
  1034. backgroundColor:'transparent',
  1035. textAlign :'left',
  1036. textAlignVertical:'center',
  1037. paddingBottom: 16/PixelRatio.get(),
  1038. fontSize: 48/PixelRatio.get(),
  1039. color : 'red'
  1040. },
  1041. // 面额的样式
  1042. contentItemTopDetailSalePrice:{
  1043. position:"absolute",
  1044. bottom:2,
  1045. left:0,
  1046. // flex: 1,
  1047. paddingTop:138/PixelRatio.get(),
  1048. width:'100%',
  1049. // height:'100%',
  1050. backgroundColor:'transparent',
  1051. },
  1052. contentItemTopDetailSalePrice02:{
  1053. position:"absolute",
  1054. bottom:14/PixelRatio.get(),
  1055. left:0,
  1056. // flex: 1,
  1057. paddingTop:138/PixelRatio.get(),
  1058. width:'100%',
  1059. // height:'100%',
  1060. backgroundColor:'transparent',
  1061. },
  1062. contentItemTopDetailSalePriceStr:{
  1063. width:'100%',
  1064. height:'100%',
  1065. backgroundColor:'transparent',
  1066. textAlign :'left',
  1067. textAlignVertical:'bottom',
  1068. fontSize: 27/PixelRatio.get(),
  1069. textDecorationLine: 'line-through',
  1070. color : 'gray'
  1071. },
  1072. contentItemTopDetailSalePriceStr02:{
  1073. width:'100%',
  1074. height:'100%',
  1075. backgroundColor:'transparent',
  1076. textAlignVertical:'center',
  1077. textAlign :'left',
  1078. fontSize: 27/PixelRatio.get(),
  1079. textDecorationLine: 'line-through',
  1080. color : 'gray'
  1081. },
  1082. adTypeBg:{
  1083. flex: 1,
  1084. width: '100%',
  1085. height: '100%',
  1086. },
  1087. adWrapBox: {
  1088. width: '100%',
  1089. height: '100%',
  1090. position: 'relative',
  1091. },
  1092. adWrap: {
  1093. width: '100%',
  1094. height: '100%',
  1095. position: 'absolute',
  1096. left: 0,
  1097. top: 0,
  1098. zIndex: 10,
  1099. },
  1100. adWrapHideImg: {
  1101. width: '100%',
  1102. height: '100%',
  1103. position: 'absolute',
  1104. left: 0,
  1105. top: 0,
  1106. zIndex: -1,
  1107. opacity:0,
  1108. },
  1109. adTypeSwiper02:{
  1110. flex: 1,
  1111. alignItems: 'center',
  1112. position: 'absolute',
  1113. left: 0,
  1114. bottom: 60/PixelRatio.get(),
  1115. width: '100%',
  1116. height: 270/PixelRatio.get(),
  1117. paddingTop: 10/PixelRatio.get(),
  1118. paddingBottom: 10/PixelRatio.get(),
  1119. backgroundColor: 'rgba(0,0,0,.1)',
  1120. },
  1121. adTypeItemImgWrap:{
  1122. flex: 1,
  1123. width: '100%',
  1124. height: 369/PixelRatio.get(),
  1125. flexDirection: 'row',
  1126. alignItems: 'center',
  1127. },
  1128. adTypeItemImg:{
  1129. width: 200/PixelRatio.get(),
  1130. height: 200/PixelRatio.get(),
  1131. marginLeft: 8/PixelRatio.get(),
  1132. marginTop: 20/PixelRatio.get(),
  1133. borderRadius:27/PixelRatio.get(),
  1134. backgroundColor:'transparent'
  1135. },
  1136. bottomBox:{
  1137. position: 'absolute',
  1138. bottom: 20/PixelRatio.get(),
  1139. left: 0,
  1140. width: '100%',
  1141. height: 130/PixelRatio.get(),
  1142. flexDirection: 'row',
  1143. alignItems: 'center',
  1144. backgroundColor:'transparent',
  1145. },
  1146. contentItemTopForAd:{
  1147. position: 'relative',
  1148. flex: 1,
  1149. width: 800/PixelRatio.get(),
  1150. // width: '100%',
  1151. height:'100%',
  1152. paddingLeft: 12/PixelRatio.get(),
  1153. paddingRight: 26/PixelRatio.get(),
  1154. flexDirection: 'row',
  1155. alignItems: 'flex-start',
  1156. borderRadius: 6,
  1157. backgroundColor:'rgba(255,255,255,.8)',
  1158. },
  1159. onlyAdSwiperItem:{
  1160. width: '100%',
  1161. height: '100%',
  1162. },
  1163. onlyAdTypeItemImg:{
  1164. width: '100%',
  1165. height: '100%',
  1166. },
  1167. carouselItemWrap: {
  1168. flex: 1,
  1169. width: '100%',
  1170. backgroundColor: 'transparent',
  1171. alignItems: 'center',
  1172. }
  1173. });