Skip to content

Commit

Permalink
Added facade for SvgXml, fixed #15
Browse files Browse the repository at this point in the history
  • Loading branch information
viktor-podzigun committed May 20, 2020
1 parent dab9ef1 commit 541f00a
Show file tree
Hide file tree
Showing 23 changed files with 442 additions and 14 deletions.
23 changes: 20 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,14 @@ val scommonsReactNativeVer = "1.0.0-SNAPSHOT"

libraryDependencies ++= Seq(
"org.scommons.react-native" %%% "scommons-react-native-core" % scommonsReactNativeVer,
"org.scommons.react-native" %%% "scommons-react-native-community" % scommonsReactNativeVer,
"org.scommons.react-native" %%% "scommons-react-navigation" % scommonsReactNativeVer,
"org.scommons.react-native" %%% "scommons-expo" % scommonsReactNativeVer,

// ui module already includes all above modules
"org.scommons.react-native" %%% "scommons-react-native-ui" % scommonsReactNativeVer,
"org.scommons.react-native" %%% "scommons-expo" % scommonsReactNativeVer,

// mocks of native Components and APIs
"org.scommons.react-native" %%% "scommons-react-native-test" % scommonsReactNativeVer % "test"
)
```
Expand All @@ -35,11 +38,20 @@ resolvers += "Sonatype Snapshots" at "https://oss.sonatype.org/content/repositor

### How to use it

Note: Almost all examples are from an excellent book [React Native in Action](https://www.manning.com/books/react-native-in-action) by [Nader Dabit](https://github.com/dabit3)
Note: Many examples are from an excellent book [React Native in Action](https://www.manning.com/books/react-native-in-action) by [Nader Dabit](https://github.com/dabit3)

#### Demo Application

* [live expo link](https://expo.io/@viktorpodzigun/showcase) => [How to Build and Run](showcase/README.md)
##### How to Build and Run

See [showcase/README.md](showcase/README.md)

* [live expo link](https://expo.io/@viktorpodzigun/showcase)
* [mobile browser](https://scommons.org/scommons-react-native/showcase.html)
* [web emulator](https://scommons.org/scommons-react-native/showcase.browser.html)

##### Demo Ui Components

* [app](showcase/src/main/scala/showcase/app/ShowcaseApp.scala) => [tests](showcase/src/test/scala/showcase/app/ShowcaseAppSpec.scala)
* [controller](showcase/src/main/scala/showcase/app/ShowcaseController.scala) => [tests](showcase/src/test/scala/showcase/app/ShowcaseControllerSpec.scala)
* [screen](showcase/src/main/scala/showcase/app/ShowcaseScreen.scala) => [tests](showcase/src/test/scala/showcase/app/ShowcaseScreenSpec.scala)
Expand Down Expand Up @@ -83,6 +95,11 @@ Note: Almost all examples are from an excellent book [React Native in Action](ht
* [TextStyle](showcase/src/main/scala/showcase/TextStyleDemo.scala) => [tests](showcase/src/test/scala/showcase/TextStyleDemoSpec.scala)
* [ViewStyle](showcase/src/main/scala/showcase/ViewStyleDemo.scala) => [tests](showcase/src/test/scala/showcase/ViewStyleDemoSpec.scala)

#### react-native-community

* [react-native-svg](https://github.com/react-native-community/react-native-svg)
* [SvgXml](showcase/src/main/scala/showcase/app/community/SvgXmlDemo.scala) => [tests](showcase/src/test/scala/showcase/app/community/SvgXmlDemoSpec.scala)

#### react-navigation (v5)

* [Components](https://reactnavigation.org/docs/en/hello-react-navigation.html)
Expand Down
6 changes: 4 additions & 2 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,18 @@ lazy val `scommons-react-native` = (project in file("."))
)
.aggregate(
`scommons-react-native-core`,
`scommons-react-native-ui`,
`scommons-react-native-test`,
`scommons-react-native-community`,
`scommons-react-navigation`,
`scommons-expo`,
`scommons-react-native-ui`,
`scommons-react-native-showcase`
)

lazy val `scommons-react-native-core` = ReactNativeCore.definition
lazy val `scommons-react-native-ui` = ReactNativeUi.definition
lazy val `scommons-react-native-test` = ReactNativeTest.definition
lazy val `scommons-react-native-community` = ReactNativeCommunity.definition
lazy val `scommons-react-navigation` = ReactNavigation.definition
lazy val `scommons-expo` = Expo.definition
lazy val `scommons-react-native-ui` = ReactNativeUi.definition
lazy val `scommons-react-native-showcase` = ReactNativeShowcase.definition
19 changes: 19 additions & 0 deletions community/src/main/scala/scommons/reactnative/svg/package.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package scommons.reactnative

import io.github.shogowada.scalajs.reactjs.VirtualDOM.VirtualDOMElements.ReactClassElementSpec
import io.github.shogowada.scalajs.reactjs.VirtualDOM._
import io.github.shogowada.statictags._

/** @see https://github.com/react-native-community/react-native-svg
*/
package object svg {

implicit class SvgVirtualDOMElements(elements: VirtualDOMElements) {
lazy val SvgXml: ReactClassElementSpec = elements(svg.raw.SvgXml)
}

implicit class SvgVirtualDOMAttributes(attributes: VirtualDOMAttributes) {

lazy val xml = StringAttributeSpec("xml")
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package scommons.reactnative.svg

import scommons.react.ReactClass

import scala.scalajs.js
import scala.scalajs.js.annotation.JSImport

package object raw {

@js.native
@JSImport("react-native-svg", "SvgXml")
object SvgXml extends ReactClass

}
4 changes: 1 addition & 3 deletions project/src/main/scala/definitions/Expo.scala
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@ object Expo extends ScalaJsModule {

override val superRepoProjectsDependencies: Seq[(String, String, Option[String])] = Nil

override val runtimeDependencies: Def.Initialize[Seq[ModuleID]] = Def.setting(Seq(
Libs.scommonsReactCore.value
))
override val runtimeDependencies: Def.Initialize[Seq[ModuleID]] = Def.setting(Nil)

override val testDependencies: Def.Initialize[Seq[ModuleID]] = Def.setting(Seq(
TestLibs.scalaTestJs.value,
Expand Down
37 changes: 37 additions & 0 deletions project/src/main/scala/definitions/ReactNativeCommunity.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package definitions

import common.TestLibs
import sbt.Keys._
import sbt._
import scoverage.ScoverageKeys.coverageExcludedPackages

import scalajsbundler.sbtplugin.ScalaJSBundlerPlugin.autoImport._

object ReactNativeCommunity extends ScalaJsModule {

override val id: String = "scommons-react-native-community"

override val base: File = file("community")

override def definition: Project = super.definition
.settings(
description := "Scala.js facades for react-native-community Components and APIs",

requireJsDomEnv in Test := false,

coverageExcludedPackages := "scommons.reactnative.*raw"
)

override val internalDependencies: Seq[ClasspathDep[ProjectReference]] = Seq(
ReactNativeCore.definition
)

override val superRepoProjectsDependencies: Seq[(String, String, Option[String])] = Nil

override val runtimeDependencies: Def.Initialize[Seq[ModuleID]] = Def.setting(Nil)

override val testDependencies: Def.Initialize[Seq[ModuleID]] = Def.setting(Seq(
TestLibs.scalaTestJs.value,
TestLibs.scalaMockJs.value
).map(_ % "test"))
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ object ReactNativeShowcase extends ScalaJsModule {

override val internalDependencies: Seq[ClasspathDep[ProjectReference]] = Seq(
ReactNativeUi.definition,
Expo.definition,
ReactNativeTest.definition % "test"
)

Expand Down
2 changes: 1 addition & 1 deletion project/src/main/scala/definitions/ReactNativeTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ object ReactNativeTest extends ScalaJsModule {

override def definition: Project = super.definition
.settings(
description := "Core Scala.js, React Native (react-native) testing utilities",
description := "Core Scala.js react-native testing utilities and mocks",
coverageExcludedPackages := "scommons.reactnative.test.raw",

requireJsDomEnv in Test := false,
Expand Down
2 changes: 2 additions & 0 deletions project/src/main/scala/definitions/ReactNativeUi.scala
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ object ReactNativeUi extends ScalaJsModule {

override val internalDependencies: Seq[ClasspathDep[ProjectReference]] = Seq(
ReactNativeCore.definition,
ReactNativeCommunity.definition,
ReactNavigation.definition,
Expo.definition,
ReactNativeTest.definition % "test"
)

Expand Down
94 changes: 94 additions & 0 deletions showcase/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions showcase/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"react-native-safe-area-context": "0.6.0",
"react-native-screens": "2.0.0-alpha.12",
"react-native-web": "~0.11.7",
"react-native-svg": "9.13.3",
"react-redux": "^5.0.3",
"redux": "^3.6.0"
},
Expand Down
10 changes: 10 additions & 0 deletions showcase/src/main/scala/showcase/app/ShowcaseRoot.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package showcase.app

import showcase.app.community._
import showcase.app.expo._
import scommons.react._
import scommons.react.navigation._
Expand Down Expand Up @@ -41,6 +42,15 @@ object ShowcaseRoot extends FunctionComponent[Unit] {
}: js.Function1[TabBarIconParams, ReactElement]
}
)(),
<(Tab.Screen)(
^.name := "community",
^.component := CommunityDemoScreen.communityStackComp,
^.options := new TabScreenOptions {
override val tabBarIcon = { params =>
<(ShowcaseIcons.FontAwesome5)(^.name := "reacteurope", ^.rnSize := params.size, ^.color := params.color)()
}: js.Function1[TabBarIconParams, ReactElement]
}
)(),
<(Tab.Screen)(
^.name := "expo",
^.component := ExpoDemoScreen.expoStackComp,
Expand Down
1 change: 1 addition & 0 deletions showcase/src/main/scala/showcase/app/ShowcaseScreen.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ object ShowcaseScreen extends FunctionComponent[ShowcaseScreenProps] {
<(ShowcaseListView())(^.wrapped := ShowcaseListViewProps(
items = List(
"ReactNative" -> "Demo core components",
"Community" -> "Demo community components",
"Expo" -> "Demo expo components",
"Styles" -> "Demo different styles",
"DemoTask" -> "Demo API tasks"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package showcase.app.community

import showcase.app.ShowcaseStateDef
import io.github.shogowada.scalajs.reactjs.redux.Redux.Dispatch
import scommons.react._
import scommons.react.navigation._
import scommons.reactnative.app.BaseStateAndRouteController

object CommunityDemoController
extends BaseStateAndRouteController[ShowcaseStateDef, CommunityDemoScreenProps] {

lazy val uiComponent: UiComponent[CommunityDemoScreenProps] = CommunityDemoScreen

def mapStateAndRouteToProps(dispatch: Dispatch,
state: ShowcaseStateDef,
nav: Navigation): CommunityDemoScreenProps = {
CommunityDemoScreenProps(
navigate = { screen =>
nav.navigate(screen)
}
)
}
}
Loading

0 comments on commit 541f00a

Please sign in to comment.