-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathShowcaseRoot.scala
119 lines (107 loc) · 4.1 KB
/
ShowcaseRoot.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
package showcase.app
import showcase.app.community._
import showcase.app.expo._
import scommons.react._
import scommons.react.navigation._
import scommons.react.navigation.stack._
import scommons.react.navigation.tab.TabBarOptions._
import scommons.react.navigation.tab._
import scommons.reactnative._
import scommons.reactnative.safearea._
import scala.scalajs.js
case class ShowcaseRootProps(darkTheme: Boolean)
object ShowcaseRoot extends FunctionComponent[ShowcaseRootProps] {
protected def render(compProps: Props): ReactElement = {
val props = compProps.wrapped
def getScreenTitle(navProps: NavigationProps): String = {
val routeName = getFocusedRouteNameFromRoute(navProps.route)
.getOrElse(navProps.route.name)
routeName match {
case "App" => "Showcase"
case "Home" => "Showcase"
case _ => routeName
}
}
<.>()(
<.StatusBar(^.barStyle := {
if (props.darkTheme) StatusBar.BarStyle.`light-content`
else StatusBar.BarStyle.`dark-content`
})(),
<.SafeAreaProvider()(
<.NavigationContainer(^.theme := {
if (props.darkTheme) DarkTheme
else DefaultTheme
})(
<(AppStack.Navigator)(
^.screenOptions := { navProps: NavigationProps =>
val screenTitle = getScreenTitle(navProps)
val options = new StackScreenOptions {
val headerBackTitleVisible = false
override val title = screenTitle
}
options
}
)(
<(AppStack.Screen)(^.name := "App", ^.component := homeTabComp)(),
ShowcaseScreen.getHomeScreens(AppStack),
ReactNativeDemoScreen.getReactNativeScreens(AppStack),
CommunityDemoScreen.getCommunityScreens(AppStack),
ExpoDemoScreen.getExpoScreens(AppStack)
)
)
)
)
}
private[app] lazy val AppStack = createStackNavigator()
private[app] lazy val HomeTab = createBottomTabNavigator()
private[app] lazy val homeTabComp: ReactClass = new FunctionComponent[Unit] {
protected def render(props: Props): ReactElement = {
<(HomeTab.Navigator)(
^.initialRouteName := "Home",
^.screenOptions := new TabScreenOptions {
//override val activeTintColor = "#e91e63"
override val headerShown = false
override val `lazy` = false
override val tabBarLabelPosition = LabelPosition.`below-icon`
}
)(
<(HomeTab.Screen)(
^.name := "Home",
^.component := ShowcaseController(),
^.options := new TabScreenOptions {
override val tabBarIcon = { params =>
<(ShowcaseIcons.FontAwesome5)(^.name := "home", ^.rnSize := params.size, ^.color := params.color)()
}: js.Function1[TabBarIconParams, ReactElement]
}
)(),
<(HomeTab.Screen)(
^.name := "react-native",
^.component := ReactNativeDemoController(),
^.options := new TabScreenOptions {
override val tabBarIcon = { params =>
<(ShowcaseIcons.FontAwesome5)(^.name := "react", ^.rnSize := params.size, ^.color := params.color)()
}: js.Function1[TabBarIconParams, ReactElement]
}
)(),
<(HomeTab.Screen)(
^.name := "community",
^.component := CommunityDemoController(),
^.options := new TabScreenOptions {
override val tabBarIcon = { params =>
<(ShowcaseIcons.FontAwesome5)(^.name := "reacteurope", ^.rnSize := params.size, ^.color := params.color)()
}: js.Function1[TabBarIconParams, ReactElement]
}
)(),
<(HomeTab.Screen)(
^.name := "expo",
^.component := ExpoDemoController(),
^.options := new TabScreenOptions {
override val tabBarIcon = { params =>
<(ShowcaseIcons.Ionicons)(^.name := "ios-apps", ^.rnSize := params.size, ^.color := params.color)()
}: js.Function1[TabBarIconParams, ReactElement]
}
)()
)
}
}.apply()
}