Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Patch TabNavigation and AppBar so they render within the viewport in iOS #114

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 21 additions & 15 deletions src/AppBar/AppBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,18 @@ export default class AppBar extends Component {
return {}
}

getContainerMarginTop() {
const { hasDynamicIslandOrNotch, isResponsiveComponent } = this.props;
let marginTop = -30;
if (hasDynamicIslandOrNotch) {
marginTop += -10
}
if (isResponsiveComponent) {
marginTop += -10
}
return marginTop;
}

getShadowStyle() {
let { shadow } = this.props
if (shadow) {
Expand Down Expand Up @@ -257,12 +269,10 @@ export default class AppBar extends Component {
}

renderBlur(containerStyles) {
let { translucentColor, hasDynamicIslandOrNotch } = this.props

const blurViewStyle = {};
if (hasDynamicIslandOrNotch) {
blurViewStyle.marginTop = -40
}
let { translucentColor } = this.props

const marginTop = this.getContainerMarginTop();
const blurViewStyle = { marginTop };

return (
<Blur
Expand All @@ -278,12 +288,11 @@ export default class AppBar extends Component {
}

renderImageBackgroundToolbar() {
let { backgroundImage, hasDynamicIslandOrNotch } = this.props
let { backgroundImage } = this.props

const marginTop = this.getContainerMarginTop();
let imageBackgroundStyles = styles.imageBackground;
if (hasDynamicIslandOrNotch) {
imageBackgroundStyles = { ...imageBackgroundStyles, marginTop: -40 }
}
imageBackgroundStyles = { ...imageBackgroundStyles, marginTop }

const imageStyles = [
imageBackgroundStyles,
Expand Down Expand Up @@ -311,7 +320,7 @@ export default class AppBar extends Component {
}

renderToolbar() {
let { barType, translucentColor, backgroundColor, editor, hasDynamicIslandOrNotch } = this.props
let { barType, translucentColor, backgroundColor, editor } = this.props
let containerStyles = {
backgroundColor,
height: 76,
Expand All @@ -322,10 +331,7 @@ export default class AppBar extends Component {
}

if (!editor) {
let marginTop = -30;
if (hasDynamicIslandOrNotch) {
marginTop = -40;
}
const marginTop = this.getContainerMarginTop();
containerStyles = {
...containerStyles,
height: 106,
Expand Down
22 changes: 16 additions & 6 deletions src/TabNavigator/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { Component } from 'react'
import { StyleSheet } from 'react-native'
import { StyleSheet, Platform } from 'react-native'
import {
BottomNavigation,
ThemeContext,
Expand Down Expand Up @@ -38,7 +38,7 @@ export default class TabNavigator extends Component {
}

render() {
let { backgroundColor, editor, activeTab, _fonts, getFlags } = this.props
let { backgroundColor, editor, activeTab, _fonts, getFlags, isResponsiveComponent } = this.props
const { hasUpdatedLoadingStates } = (getFlags && getFlags()) || {}

let enabledTabs = tabNames.filter((tabName) => {
Expand All @@ -53,18 +53,21 @@ export default class TabNavigator extends Component {
})

let wrapperStyles = editor ? styles.editorWrapper : styles.wrapper
if (!editor) {
// Patch for TabNavigation rendering outside of viewport in iOS for responsive web apps
wrapperStyles = isResponsiveComponent && Platform.OS === "ios" ? styles.responsiveComponentWrapper : styles.wrapper;
}

let defaultFontStyle = _fonts
? { fontFamily: _fonts.body, fontSize: 11 }
: { fontSize: 11 }


return (
<ThemeContext.Provider value={this.getTheme()}>
<BottomNavigation
active={activeTab}
style={{
container: [wrapperStyles, { backgroundColor }],
}}
style={{ container: [wrapperStyles, { backgroundColor }] }}
>
{enabledTabs.map((tabName) => (
<BottomNavigation.Action
Expand All @@ -88,11 +91,18 @@ export default class TabNavigator extends Component {
}

const styles = StyleSheet.create({
wrapper: {
defaultWrapper: {
marginBottom: -100,
paddingBottom: 100,
height: 156,
},
responsiveComponentWrapper: {
jose-adalo marked this conversation as resolved.
Show resolved Hide resolved
position: "absolute",
bottom: 0,
left: 0,
right: 0,
height: 156,
},
editorWrapper: {
height: 56,
},
Expand Down
44 changes: 27 additions & 17 deletions src/TextButton/TextButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@ export default class WrappedTextButton extends Component {
getContainerStyles() {
let { type, primaryColor, borderRadius } = this.props


if (type === 'contained') {

return { backgroundColor: primaryColor, borderRadius }
}

Expand All @@ -42,7 +40,7 @@ export default class WrappedTextButton extends Component {
}

getTextStyles() {
let { primaryColor, contrastColor, type, icon, styles, _fonts } = this.props
let { primaryColor, contrastColor, type, icon, styles, upperCase, _fonts } = this.props

const textStyles = { fontWeight: '600' }

Expand All @@ -61,10 +59,31 @@ export default class WrappedTextButton extends Component {

if (icon) {
textStyles.marginLeft = 8
textStyles.marginRight = 5
}

if (upperCase) {
textStyles.letterSpacing = 1
}

return textStyles
}

getIconStyles() {
const { icon } = this.props;
// Base icon styles are same as text styles
const iconStyles = this.getTextStyles()
// marginRight needs to be removed from base text styles for icons
delete iconStyles.marginRight;

if (!iconStyles.width && !iconStyles.minWidth) {
// Set default icon size as min width
iconStyles.minWidth = 24;
}

return iconStyles
}

getAdditionalProps() {
let { type, shadow = true } = this.props

Expand Down Expand Up @@ -96,19 +115,11 @@ export default class WrappedTextButton extends Component {
}

renderSub() {
let { icon, action, text, upperCase, container } = this.props
let { icon, action, text, upperCase } = this.props

let containerStyles = this.getContainerStyles()
let iconStyles = this.getTextStyles()
let textStyles = { ...this.getTextStyles() }

if (icon) {
textStyles.marginRight = 5
}

if (upperCase) {
textStyles.letterSpacing = 1
}
let textStyles = this.getTextStyles()
let iconStyles = this.getIconStyles()

return (
<View>
Expand All @@ -120,12 +131,11 @@ export default class WrappedTextButton extends Component {
onPress={action && this.submitAction}
text={this.state.loading ? '' : text}
style={{
container: [containerStyles, container],
container: containerStyles,
icon: iconStyles,
text: [textStyles, styles.text],
}}
disabled={this.state.loading}

disabled={action ? this.state.loading : true}
/>
</View>
{this.state.loading && (
Expand Down