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

Safe area view for IPhone x #166

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
34 changes: 23 additions & 11 deletions mobile/AppInternal.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,34 @@ import { SafeAreaView, View } from 'react-native'
import Page from './components/Page'

export class AppInternal extends Component {
constructor (props) {
super(props)
this.state = {
backgroundColor: 'white'
}
this.RouteWithProps = ({component: Component, ...rest}) => <Route {...rest} render={props => <Component {...props} changeSafeAreaViewBackground={this.changeSafeAreaViewBackground.bind(this)} />} />
}

changeSafeAreaViewBackground (color) {
this.setState({backgroundColor: color || 'white'})
}

render () {
return (<NativeRouter>
<SafeAreaView style={{backgroundColor: 'transparent'}}>
<SafeAreaView style={{backgroundColor: this.state.backgroundColor}}>
<View style={styles.mainPage}>
<View style={styles.topContainer} />
{this.props.fontLoaded ? <Page>
<Route exact path='/' component={Home} />
<Route exact path='/intro' component={Intro} />
<Route exact path='/congratulations' component={Congratulations} />
<Route exact path='/questions' component={Questions} />
<Route exact path='/login' component={Login} />
<Route exact path='/lectures' component={Lectures} />
<Route exact path='/calendar' component={Calendar} />
<Route exact path='/profile' component={Profile} />
<Route exact path='/contact' component={Contact} />
<Route exact path='/nointernet' component={NoInternet} />
<this.RouteWithProps exact path='/' component={Home} />
<this.RouteWithProps exact path='/intro' component={Intro} />
<this.RouteWithProps exact path='/congratulations' component={Congratulations} />
<this.RouteWithProps exact path='/questions' component={Questions} />
<this.RouteWithProps exact path='/login' component={Login} />
<this.RouteWithProps exact path='/lectures' component={Lectures} />
<this.RouteWithProps exact path='/calendar' component={Calendar} />
<this.RouteWithProps exact path='/profile' component={Profile} />
<this.RouteWithProps exact path='/contact' component={Contact} />
<this.RouteWithProps exact path='/nointernet' component={NoInternet} />
</Page> : null }
</View>
</SafeAreaView>
Expand Down
2 changes: 1 addition & 1 deletion mobile/app.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"expo":{"name":"The Brain Pro","icon":"./assets/icon.png","splash":{"image":"./assets/thebrainprologosplash1242x2208.png","backgroundColor":"#FEF9B0"},"version":"1.1.0","ios":{"bundleIdentifier":"com.thebrain.pro"},"sdkVersion":"23.0.0","packagerOpts":{"projectRoots":"","assetExts":["ttf"],"config":"rn-cli-config-with-links.js"}}}
{"expo":{"name":"The Brain Pro","icon":"./assets/icon.png","splash":{"image":"./assets/thebrainprologosplash1242x2208.png"},"version":"1.1.0","ios":{"bundleIdentifier":"com.thebrain.pro"},"sdkVersion":"23.0.0","packagerOpts":{"projectRoots":"","assetExts":["ttf"],"config":"rn-cli-config-with-links.js"}}}
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ class MainMenuOptions extends React.Component {

go = (path) => () => {
this.props.history.push(path)
this.props.changeSafeAreaViewBackground()
this.closeMenu()
}

Expand Down
2 changes: 1 addition & 1 deletion mobile/components/MainMenu/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class MainMenu extends React.Component {

return <View style={[{height}]}>
<MainMenuHeader level={level} currentUser={currentUser} username={username} sessionCount={sessionCount} />
<MainMenuOptions activated={activated} currentUser={currentUser} />
<MainMenuOptions activated={activated} currentUser={currentUser} changeSafeAreaViewBackground={this.props.changeSafeAreaViewBackground} />
</View>
}

Expand Down
12 changes: 10 additions & 2 deletions mobile/components/PageContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,18 @@ class PageContainer extends React.Component {
}
}

changeSafeAreaViewBackground () {
return this.props.changeSafeAreaViewBackground || this.props.location.state.changeSafeAreaViewBackground
}

renderMainMenu = () => {
return this.props.mainMenu.visible ? <MainMenu changeSafeAreaViewBackground={this.changeSafeAreaViewBackground()} /> : this.props.children
}

renderContainer = () => (
<View style={{ height: '100%', backgroundColor: 'white' }}>
<Header />
{this.props.mainMenu.visible ? <MainMenu /> : this.props.children}
{this.renderMainMenu()}
</View>)

renderKeyboardAwareContainer = () => (
Expand All @@ -50,7 +58,7 @@ class PageContainer extends React.Component {
height: '100%'
}}>
<Header hideHamburger={this.props.hideHamburger} />
{this.props.mainMenu.visible ? <MainMenu /> : this.props.children}
{this.renderMainMenu()}
</View>
</KeyboardAwareScrollView>)

Expand Down
2 changes: 1 addition & 1 deletion mobile/scenes/Calendar/Calendar.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class Calendar extends React.Component {
const year = currentDate.getFullYear()

return (
<PageContainer dontUseKeyboarAware>
<PageContainer dontUseKeyboarAware changeSafeAreaViewBackground={this.props.changeSafeAreaViewBackground}>

<PageTitle text={`REVIEWS - ${month} ${year}`} />

Expand Down
2 changes: 1 addition & 1 deletion mobile/scenes/Contact/Contact.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import PageTitle from '../../components/PageTitle'
class Contact extends React.Component {
render () {
return (
<PageContainer dontUseKeyboarAware>
<PageContainer dontUseKeyboarAware changeSafeAreaViewBackground={this.props.changeSafeAreaViewBackground}>

<PageTitle text='CONTACT' />

Expand Down
9 changes: 7 additions & 2 deletions mobile/scenes/Home/Home.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,10 @@ class Home extends React.Component {

AsyncStorage.getItem('isIntroDisabled').then((isIntroDisabled) => {
if (!isIntroDisabled) {
props.history.push('/intro')
props.history.push({
pathname: '/intro',
state: {changeSafeAreaViewBackground: props.changeSafeAreaViewBackground}
})
}
})
}
Expand Down Expand Up @@ -193,6 +196,7 @@ class Home extends React.Component {

selectCourse = async (course) => {
if (!this.props.course.selectedCourse) {
this.props.changeSafeAreaViewBackground(course.color)
const deviceId = Expo.Constants.deviceId
this.props.dispatch(courseActions.select(course))
await mutationConnectionHandler(this.props.history, () => {
Expand Down Expand Up @@ -240,6 +244,7 @@ class Home extends React.Component {
this.setState({ isExitAnimationFinished: false })
this.closeMenu()
this.enableCourseSelector()
this.props.changeSafeAreaViewBackground()
})
}

Expand Down Expand Up @@ -332,7 +337,7 @@ class Home extends React.Component {

{isExitAnimationFinished && <Course closeCourse={this.closeCourse} />}

{this.props.mainMenu.visible && <MainMenu closeCourse={this.closeCourse} logoutAction={this.logoutAction} />}
{this.props.mainMenu.visible && <MainMenu closeCourse={this.closeCourse} logoutAction={this.logoutAction} changeSafeAreaViewBackground={this.props.changeSafeAreaViewBackground} />}
</View>
)
}
Expand Down
2 changes: 1 addition & 1 deletion mobile/scenes/Lectures/Lectures.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class Lectures extends React.Component {
return <View />
}
return (
<PageContainer>
<PageContainer changeSafeAreaViewBackground={this.props.changeSafeAreaViewBackground}>
<PageTitle text='LECTURES LIST' />
<FlatList
data={this.props.lessons.Lessons}
Expand Down
2 changes: 1 addition & 1 deletion mobile/scenes/Login/Login.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ class Login extends React.Component {
return <Loading />
}
return (
<PageContainer>
<PageContainer changeSafeAreaViewBackground={this.props.changeSafeAreaViewBackground}>

<View style={{ alignItems: 'center' }}>
<Text style={[styles.infoText, { fontWeight: 'bold', fontSize: 20, marginVertical: 20 }]}>
Expand Down
2 changes: 1 addition & 1 deletion mobile/scenes/Profile/Profile.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class Profile extends React.Component {
const isFacebookUser = this.props.currentUser && this.props.currentUser.CurrentUser ? this.props.currentUser.CurrentUser.facebookId : false

return (
<PageContainer>
<PageContainer changeSafeAreaViewBackground={this.props.changeSafeAreaViewBackground}>
<PageTitle text='PROFILE' />

<View style={{
Expand Down