From e1c42a10a25ac5d6c6af3f4612dc4126c090e216 Mon Sep 17 00:00:00 2001 From: Liangyu Date: Thu, 24 Aug 2017 17:40:27 +0800 Subject: [PATCH] fix "big icon button" bug on Android, #44 --- components/TabView/TabView.js | 87 +++++++++++++++++++++------------ example/views/DrawerExample.js | 20 +++++--- example/views/TabViewExample.js | 4 +- package.json | 2 +- 4 files changed, 71 insertions(+), 42 deletions(-) diff --git a/components/TabView/TabView.js b/components/TabView/TabView.js index 0284ac3..a55479e 100644 --- a/components/TabView/TabView.js +++ b/components/TabView/TabView.js @@ -4,7 +4,7 @@ import React, {Component} from 'react'; import PropTypes from 'prop-types'; -import {View} from 'react-native'; +import {StyleSheet, View} from 'react-native'; import Theme from 'teaset/themes/Theme'; import TabSheet from './TabSheet'; @@ -52,15 +52,32 @@ export default class TabView extends Component { }].concat(style); barStyle = [{ backgroundColor: Theme.tvBarColor, + position: 'absolute', + left: 0, + bottom: 0, + right: 0, height: Theme.tvBarHeight, paddingTop: Theme.tvBarPaddingTop, paddingBottom: Theme.tvBarPaddingBottom, borderTopWidth: Theme.tvBarSeparatorWidth, borderColor: Theme.tvBarSeparatorColor, + }].concat(barStyle); + barStyle = StyleSheet.flatten(barStyle); + let {height, paddingTop, paddingBottom} = barStyle; + let buttonContainerStyle = { + position: 'absolute', + left: 0, + bottom: 0, + right: 0, + paddingTop, + paddingBottom, flexDirection: 'row', - alignItems: 'stretch', + alignItems: 'flex-end', justifyContent: 'space-around', - }].concat(barStyle); + }; + let buttonStyle = { + minHeight: height - paddingTop - paddingBottom, + }; if (!(children instanceof Array)) { if (children) children = [children]; @@ -68,39 +85,44 @@ export default class TabView extends Component { } children = children.filter(item => item); //remove empty item - this.props = {style, barStyle, children, ...others}; + this.props = {style, barStyle, buttonContainerStyle, buttonStyle, children, ...others}; } renderBar() { - let {barStyle, onChange, children} = this.props; + //Overflow is not supported on Android, then use a higher container view to support "big icon button" + let {barStyle, buttonContainerStyle, buttonStyle, onChange, children} = this.props; let sheetCount = 0; return ( - - {children.map((item, index) => { - let {type, title, icon, activeIcon, iconContainerStyle, badge, onPress} = item.props; - let sheetIndex = sheetCount; - if (type === 'sheet') sheetCount += 1; - return ( - { - if (type === 'sheet') { - this.setState({activeIndex: sheetIndex}, () => { - this.refs.carousel && this.refs.carousel.scrollToPage(sheetIndex); - onChange && onChange(sheetIndex); - }); - } - onPress && onPress(e); - }} - /> - ); - })} + + + + {children.map((item, index) => { + let {type, title, icon, activeIcon, iconContainerStyle, badge, onPress} = item.props; + let sheetIndex = sheetCount; + if (type === 'sheet') sheetCount += 1; + return ( + { + if (type === 'sheet') { + this.setState({activeIndex: sheetIndex}, () => { + this.refs.carousel && this.refs.carousel.scrollToPage(sheetIndex); + onChange && onChange(sheetIndex); + }); + } + onPress && onPress(e); + }} + /> + ); + })} + ); } @@ -135,10 +157,11 @@ export default class TabView extends Component { render() { this.buildProps(); - let {type, children, ...others} = this.props; + let {barStyle, type, children, ...others} = this.props; return ( {type === 'carousel' ? this.renderCarousel() : this.renderProjector()} + {this.renderBar()} ); diff --git a/example/views/DrawerExample.js b/example/views/DrawerExample.js index 5b5176a..2621edc 100644 --- a/example/views/DrawerExample.js +++ b/example/views/DrawerExample.js @@ -28,7 +28,7 @@ export default class DrawerExample extends NavigationPage { if (side == 'left' || side == 'right') { this.drawer = Drawer.open(this.renderDrawerMenu(), side, rootTransform); } else { - this.drawer = Drawer.open(this.renderDrawerBox(side), side, rootTransform); + this.drawer = Drawer.open(this.renderDrawerBox(side), side, rootTransform, {containerStyle: {backgroundColor: 'rgba(0, 0, 0, 0)'}}); } } @@ -60,13 +60,22 @@ export default class DrawerExample extends NavigationPage { } renderDrawerBox(side) { + //Overflow is not supported on Android, then use a higher container view to implement this functionality return ( - + + + + + - - ); } diff --git a/example/views/TabViewExample.js b/example/views/TabViewExample.js index 8fe522b..18c9526 100644 --- a/example/views/TabViewExample.js +++ b/example/views/TabViewExample.js @@ -3,7 +3,7 @@ 'use strict'; import React, {Component} from 'react'; -import {StyleSheet, View, ScrollView, Image, Switch} from 'react-native'; +import {StyleSheet, View, ScrollView, Image, Switch, Platform} from 'react-native'; import {Theme, TeaNavigator, NavigationPage, BasePage, ListRow, TabView, Label, PullPicker} from 'teaset'; @@ -54,7 +54,7 @@ export default class TabViewExample extends BasePage { renderPage() { let {type, custom} = this.state; - let customBarStyle = { + let customBarStyle = Platform.OS == 'android' ? null : { borderTopWidth: 0, shadowColor: '#ccc', shadowOffset: {height: -1}, diff --git a/package.json b/package.json index 85cb35b..b637dd4 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "teaset", - "version": "0.3.1", + "version": "0.3.2", "description": "A UI library for react native.", "main": "index.js", "scripts": {