", {
14 | id: 'tree'
15 | }).appendTo('#body');
16 | $('#tree').tree({
17 | data: parsedJSON,
18 | autoOpen: true,
19 | onCreateLi: function (node, $li) {
20 | $li.find('.jqtree-element').click(function () {
21 | sock.send(node.name.replace(" (View) ", ""));
22 | return false;
23 | });
24 | }
25 | });
26 | } catch (e) {
27 | }
28 | } else {
29 | const blob = new Blob([e.data], {
30 | type: 'image/png'
31 | });
32 | var blobURL = blobUtil.createObjectURL(blob);
33 | document.getElementById('capture').setAttribute('src', blobURL);
34 | }
35 | });
36 |
--------------------------------------------------------------------------------
/Example/swiftpm/TicTacToe/Root/RootComponent+LoggedOut.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) 2017. Uber Technologies
3 | //
4 | // Licensed under the Apache License, Version 2.0 (the "License");
5 | // you may not use this file except in compliance with the License.
6 | // You may obtain a copy of the License at
7 | //
8 | // http://www.apache.org/licenses/LICENSE-2.0
9 | //
10 | // Unless required by applicable law or agreed to in writing, software
11 | // distributed under the License is distributed on an "AS IS" BASIS,
12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | // See the License for the specific language governing permissions and
14 | // limitations under the License.
15 | //
16 |
17 | import RIBs
18 |
19 | /// The dependencies needed from the parent scope of Root to provide for the LoggedOut scope.
20 | // TODO: Update RootDependency protocol to inherit this protocol.
21 | protocol RootDependencyLoggedOut: Dependency {
22 |
23 | // TODO: Declare dependencies needed from the parent scope of Root to provide dependencies
24 | // for the LoggedOut scope.
25 | }
26 |
27 | extension RootComponent: LoggedOutDependency {
28 |
29 | // TODO: Implement properties to provide for LoggedOut scope.
30 | }
31 |
--------------------------------------------------------------------------------
/Example/xcframework/TicTacToe/Root/RootComponent+LoggedOut.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) 2017. Uber Technologies
3 | //
4 | // Licensed under the Apache License, Version 2.0 (the "License");
5 | // you may not use this file except in compliance with the License.
6 | // You may obtain a copy of the License at
7 | //
8 | // http://www.apache.org/licenses/LICENSE-2.0
9 | //
10 | // Unless required by applicable law or agreed to in writing, software
11 | // distributed under the License is distributed on an "AS IS" BASIS,
12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | // See the License for the specific language governing permissions and
14 | // limitations under the License.
15 | //
16 |
17 | import RIBs
18 |
19 | /// The dependencies needed from the parent scope of Root to provide for the LoggedOut scope.
20 | // TODO: Update RootDependency protocol to inherit this protocol.
21 | protocol RootDependencyLoggedOut: Dependency {
22 |
23 | // TODO: Declare dependencies needed from the parent scope of Root to provide dependencies
24 | // for the LoggedOut scope.
25 | }
26 |
27 | extension RootComponent: LoggedOutDependency {
28 |
29 | // TODO: Implement properties to provide for LoggedOut scope.
30 | }
31 |
--------------------------------------------------------------------------------
/Example/swiftpm/TicTacToe/LoggedIn/LoggedInComponent+OffGame.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) 2017. Uber Technologies
3 | //
4 | // Licensed under the Apache License, Version 2.0 (the "License");
5 | // you may not use this file except in compliance with the License.
6 | // You may obtain a copy of the License at
7 | //
8 | // http://www.apache.org/licenses/LICENSE-2.0
9 | //
10 | // Unless required by applicable law or agreed to in writing, software
11 | // distributed under the License is distributed on an "AS IS" BASIS,
12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | // See the License for the specific language governing permissions and
14 | // limitations under the License.
15 | //
16 |
17 | import RIBs
18 |
19 | /// The dependencies needed from the parent scope of LoggedIn to provide for the OffGame scope.
20 | // TODO: Update LoggedInDependency protocol to inherit this protocol.
21 | protocol LoggedInDependencyOffGame: Dependency {
22 |
23 | // TODO: Declare dependencies needed from the parent scope of LoggedIn to provide dependencies
24 | // for the OffGame scope.
25 | }
26 |
27 | extension LoggedInComponent: OffGameDependency {
28 |
29 | // TODO: Implement properties to provide for OffGame scope.
30 | }
31 |
--------------------------------------------------------------------------------
/Example/xcframework/TicTacToe/LoggedIn/LoggedInComponent+OffGame.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) 2017. Uber Technologies
3 | //
4 | // Licensed under the Apache License, Version 2.0 (the "License");
5 | // you may not use this file except in compliance with the License.
6 | // You may obtain a copy of the License at
7 | //
8 | // http://www.apache.org/licenses/LICENSE-2.0
9 | //
10 | // Unless required by applicable law or agreed to in writing, software
11 | // distributed under the License is distributed on an "AS IS" BASIS,
12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | // See the License for the specific language governing permissions and
14 | // limitations under the License.
15 | //
16 |
17 | import RIBs
18 |
19 | /// The dependencies needed from the parent scope of LoggedIn to provide for the OffGame scope.
20 | // TODO: Update LoggedInDependency protocol to inherit this protocol.
21 | protocol LoggedInDependencyOffGame: Dependency {
22 |
23 | // TODO: Declare dependencies needed from the parent scope of LoggedIn to provide dependencies
24 | // for the OffGame scope.
25 | }
26 |
27 | extension LoggedInComponent: OffGameDependency {
28 |
29 | // TODO: Implement properties to provide for OffGame scope.
30 | }
31 |
--------------------------------------------------------------------------------
/Example/swiftpm/TicTacToe/LoggedIn/LoggedInComponent+TicTacToe.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) 2017. Uber Technologies
3 | //
4 | // Licensed under the Apache License, Version 2.0 (the "License");
5 | // you may not use this file except in compliance with the License.
6 | // You may obtain a copy of the License at
7 | //
8 | // http://www.apache.org/licenses/LICENSE-2.0
9 | //
10 | // Unless required by applicable law or agreed to in writing, software
11 | // distributed under the License is distributed on an "AS IS" BASIS,
12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | // See the License for the specific language governing permissions and
14 | // limitations under the License.
15 | //
16 |
17 | import RIBs
18 |
19 | /// The dependencies needed from the parent scope of LoggedIn to provide for the TicTacToe scope.
20 | // TODO: Update LoggedInDependency protocol to inherit this protocol.
21 | protocol LoggedInDependencyTicTacToe: Dependency {
22 |
23 | // TODO: Declare dependencies needed from the parent scope of LoggedIn to provide dependencies
24 | // for the TicTacToe scope.
25 | }
26 |
27 | extension LoggedInComponent: TicTacToeDependency {
28 |
29 | // TODO: Implement properties to provide for TicTacToe scope.
30 | }
31 |
--------------------------------------------------------------------------------
/Example/xcframework/TicTacToe/LoggedIn/LoggedInComponent+TicTacToe.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) 2017. Uber Technologies
3 | //
4 | // Licensed under the Apache License, Version 2.0 (the "License");
5 | // you may not use this file except in compliance with the License.
6 | // You may obtain a copy of the License at
7 | //
8 | // http://www.apache.org/licenses/LICENSE-2.0
9 | //
10 | // Unless required by applicable law or agreed to in writing, software
11 | // distributed under the License is distributed on an "AS IS" BASIS,
12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | // See the License for the specific language governing permissions and
14 | // limitations under the License.
15 | //
16 |
17 | import RIBs
18 |
19 | /// The dependencies needed from the parent scope of LoggedIn to provide for the TicTacToe scope.
20 | // TODO: Update LoggedInDependency protocol to inherit this protocol.
21 | protocol LoggedInDependencyTicTacToe: Dependency {
22 |
23 | // TODO: Declare dependencies needed from the parent scope of LoggedIn to provide dependencies
24 | // for the TicTacToe scope.
25 | }
26 |
27 | extension LoggedInComponent: TicTacToeDependency {
28 |
29 | // TODO: Implement properties to provide for TicTacToe scope.
30 | }
31 |
--------------------------------------------------------------------------------
/Example/swiftpm/TicTacToe/Root/RootComponent+LoggedIn.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) 2017. Uber Technologies
3 | //
4 | // Licensed under the Apache License, Version 2.0 (the "License");
5 | // you may not use this file except in compliance with the License.
6 | // You may obtain a copy of the License at
7 | //
8 | // http://www.apache.org/licenses/LICENSE-2.0
9 | //
10 | // Unless required by applicable law or agreed to in writing, software
11 | // distributed under the License is distributed on an "AS IS" BASIS,
12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | // See the License for the specific language governing permissions and
14 | // limitations under the License.
15 | //
16 |
17 | import RIBs
18 |
19 | /// The dependencies needed from the parent scope of Root to provide for the LoggedIn scope.
20 | // TODO: Update RootDependency protocol to inherit this protocol.
21 | protocol RootDependencyLoggedIn: Dependency {
22 |
23 | // TODO: Declare dependencies needed from the parent scope of Root to provide dependencies
24 | // for the LoggedIn scope.
25 | }
26 |
27 | extension RootComponent: LoggedInDependency {
28 |
29 | var loggedInViewController: LoggedInViewControllable {
30 | return rootViewController
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/Example/xcframework/TicTacToe/Root/RootComponent+LoggedIn.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) 2017. Uber Technologies
3 | //
4 | // Licensed under the Apache License, Version 2.0 (the "License");
5 | // you may not use this file except in compliance with the License.
6 | // You may obtain a copy of the License at
7 | //
8 | // http://www.apache.org/licenses/LICENSE-2.0
9 | //
10 | // Unless required by applicable law or agreed to in writing, software
11 | // distributed under the License is distributed on an "AS IS" BASIS,
12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | // See the License for the specific language governing permissions and
14 | // limitations under the License.
15 | //
16 |
17 | import RIBs
18 |
19 | /// The dependencies needed from the parent scope of Root to provide for the LoggedIn scope.
20 | // TODO: Update RootDependency protocol to inherit this protocol.
21 | protocol RootDependencyLoggedIn: Dependency {
22 |
23 | // TODO: Declare dependencies needed from the parent scope of Root to provide dependencies
24 | // for the LoggedIn scope.
25 | }
26 |
27 | extension RootComponent: LoggedInDependency {
28 |
29 | var loggedInViewController: LoggedInViewControllable {
30 | return rootViewController
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/Products/RIBsTreeViewerClient.xcframework/Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | AvailableLibraries
6 |
7 |
8 | LibraryIdentifier
9 | ios-x86_64_i386-simulator
10 | LibraryPath
11 | RIBsTreeViewerClient.framework
12 | SupportedArchitectures
13 |
14 | x86_64
15 | i386
16 |
17 | SupportedPlatform
18 | ios
19 | SupportedPlatformVariant
20 | simulator
21 |
22 |
23 | LibraryIdentifier
24 | ios-armv7_arm64
25 | LibraryPath
26 | RIBsTreeViewerClient.framework
27 | SupportedArchitectures
28 |
29 | armv7
30 | arm64
31 |
32 | SupportedPlatform
33 | ios
34 |
35 |
36 | CFBundlePackageType
37 | XFWK
38 | XCFrameworkFormatVersion
39 | 1.0
40 |
41 |
42 |
--------------------------------------------------------------------------------
/scripts/generate_xcframeworks.sh:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | # Delete existing file
4 |
5 | rm -r ./Products/RIBsTreeViewerClient.xcframework
6 |
7 | # Generate RIBsTreeViewerClient
8 |
9 | xcodebuild \
10 | 'ENABLE_BITCODE=YES' \
11 | 'BITCODE_GENERATION_MODE=bitcode' \
12 | 'OTHER_CFLAGS=-fembed-bitcode' \
13 | 'BUILD_LIBRARY_FOR_DISTRIBUTION=YES' \
14 | 'SKIP_INSTALL=NO' \
15 | archive \
16 | -project RIBsTreeViewerClient.xcodeproj \
17 | -scheme 'RIBsTreeViewerClient' \
18 | -destination 'generic/platform=iOS Simulator' \
19 | -configuration 'Release' \
20 | -archivePath 'build/RIBsTreeViewerClient-iOS-Simulator.xcarchive'
21 |
22 |
23 | xcodebuild \
24 | 'ENABLE_BITCODE=YES' \
25 | 'BITCODE_GENERATION_MODE=bitcode' \
26 | 'OTHER_CFLAGS=-fembed-bitcode' \
27 | 'BUILD_LIBRARY_FOR_DISTRIBUTION=YES' \
28 | 'SKIP_INSTALL=NO' \
29 | archive \
30 | -project RIBsTreeViewerClient.xcodeproj \
31 | -scheme 'RIBsTreeViewerClient' \
32 | -destination 'generic/platform=iOS' \
33 | -configuration 'Release' \
34 | -archivePath 'build/RIBsTreeViewerClient-iOS.xcarchive'
35 |
36 |
37 | xcodebuild \
38 | -create-xcframework \
39 | -framework 'build/RIBsTreeViewerClient-iOS-Simulator.xcarchive/Products/Library/Frameworks/RIBsTreeViewerClient.framework' \
40 | -framework 'build/RIBsTreeViewerClient-iOS.xcarchive/Products/Library/Frameworks/RIBsTreeViewerClient.framework' \
41 | -output 'Products/RIBsTreeViewerClient.xcframework'
--------------------------------------------------------------------------------
/Example/swiftpm/TicTacToe/LoggedIn/TicTacToeAdapter.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) 2017. Uber Technologies
3 | //
4 | // Licensed under the Apache License, Version 2.0 (the "License");
5 | // you may not use this file except in compliance with the License.
6 | // You may obtain a copy of the License at
7 | //
8 | // http://www.apache.org/licenses/LICENSE-2.0
9 | //
10 | // Unless required by applicable law or agreed to in writing, software
11 | // distributed under the License is distributed on an "AS IS" BASIS,
12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | // See the License for the specific language governing permissions and
14 | // limitations under the License.
15 | //
16 |
17 | import RIBs
18 |
19 | class TicTacToeAdapter: Game, GameBuildable, TicTacToeListener {
20 | let id = "tictactoe"
21 | let name = "Tic Tac Toe"
22 | let ticTacToeBuilder: TicTacToeBuilder
23 | var builder: GameBuildable {
24 | return self
25 | }
26 |
27 | weak var gameListener: GameListener?
28 |
29 | init(dependency: TicTacToeDependency) {
30 | ticTacToeBuilder = TicTacToeBuilder(dependency: dependency)
31 | }
32 |
33 | func build(withListener listener: GameListener) -> ViewableRouting {
34 | gameListener = listener
35 | return ticTacToeBuilder.build(withListener: self)
36 | }
37 |
38 | func ticTacToeDidEnd(with winner: PlayerType?) {
39 | gameListener?.gameDidEnd(with: winner)
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/Example/xcframework/TicTacToe/LoggedIn/TicTacToeAdapter.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) 2017. Uber Technologies
3 | //
4 | // Licensed under the Apache License, Version 2.0 (the "License");
5 | // you may not use this file except in compliance with the License.
6 | // You may obtain a copy of the License at
7 | //
8 | // http://www.apache.org/licenses/LICENSE-2.0
9 | //
10 | // Unless required by applicable law or agreed to in writing, software
11 | // distributed under the License is distributed on an "AS IS" BASIS,
12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | // See the License for the specific language governing permissions and
14 | // limitations under the License.
15 | //
16 |
17 | import RIBs
18 |
19 | class TicTacToeAdapter: Game, GameBuildable, TicTacToeListener {
20 | let id = "tictactoe"
21 | let name = "Tic Tac Toe"
22 | let ticTacToeBuilder: TicTacToeBuilder
23 | var builder: GameBuildable {
24 | return self
25 | }
26 |
27 | weak var gameListener: GameListener?
28 |
29 | init(dependency: TicTacToeDependency) {
30 | ticTacToeBuilder = TicTacToeBuilder(dependency: dependency)
31 | }
32 |
33 | func build(withListener listener: GameListener) -> ViewableRouting {
34 | gameListener = listener
35 | return ticTacToeBuilder.build(withListener: self)
36 | }
37 |
38 | func ticTacToeDidEnd(with winner: PlayerType?) {
39 | gameListener?.gameDidEnd(with: winner)
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/Example/swiftpm/TicTacToe/LoggedOut/LoggedOutRouter.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) 2017. Uber Technologies
3 | //
4 | // Licensed under the Apache License, Version 2.0 (the "License");
5 | // you may not use this file except in compliance with the License.
6 | // You may obtain a copy of the License at
7 | //
8 | // http://www.apache.org/licenses/LICENSE-2.0
9 | //
10 | // Unless required by applicable law or agreed to in writing, software
11 | // distributed under the License is distributed on an "AS IS" BASIS,
12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | // See the License for the specific language governing permissions and
14 | // limitations under the License.
15 | //
16 |
17 | import RIBs
18 |
19 | protocol LoggedOutInteractable: Interactable {
20 | var router: LoggedOutRouting? { get set }
21 | var listener: LoggedOutListener? { get set }
22 | }
23 |
24 | protocol LoggedOutViewControllable: ViewControllable {
25 | // TODO: Declare methods the router invokes to manipulate the view hierarchy.
26 | }
27 |
28 | final class LoggedOutRouter: ViewableRouter
, LoggedOutRouting {
29 |
30 | // TODO: Constructor inject child builder protocols to allow building children.
31 | override init(interactor: LoggedOutInteractable, viewController: LoggedOutViewControllable) {
32 | super.init(interactor: interactor, viewController: viewController)
33 | interactor.router = self
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/Example/swiftpm/TicTacToe/RandomWin/RandomWinRouter.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) 2017. Uber Technologies
3 | //
4 | // Licensed under the Apache License, Version 2.0 (the "License");
5 | // you may not use this file except in compliance with the License.
6 | // You may obtain a copy of the License at
7 | //
8 | // http://www.apache.org/licenses/LICENSE-2.0
9 | //
10 | // Unless required by applicable law or agreed to in writing, software
11 | // distributed under the License is distributed on an "AS IS" BASIS,
12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | // See the License for the specific language governing permissions and
14 | // limitations under the License.
15 | //
16 |
17 | import RIBs
18 |
19 | protocol RandomWinInteractable: Interactable {
20 | var router: RandomWinRouting? { get set }
21 | var listener: RandomWinListener? { get set }
22 | }
23 |
24 | protocol RandomWinViewControllable: ViewControllable {
25 | // TODO: Declare methods the router invokes to manipulate the view hierarchy.
26 | }
27 |
28 | final class RandomWinRouter: ViewableRouter, RandomWinRouting {
29 |
30 | // TODO: Constructor inject child builder protocols to allow building children.
31 | override init(interactor: RandomWinInteractable, viewController: RandomWinViewControllable) {
32 | super.init(interactor: interactor, viewController: viewController)
33 | interactor.router = self
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/Example/swiftpm/TicTacToe/TicTacToe/TicTacToeRouter.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) 2017. Uber Technologies
3 | //
4 | // Licensed under the Apache License, Version 2.0 (the "License");
5 | // you may not use this file except in compliance with the License.
6 | // You may obtain a copy of the License at
7 | //
8 | // http://www.apache.org/licenses/LICENSE-2.0
9 | //
10 | // Unless required by applicable law or agreed to in writing, software
11 | // distributed under the License is distributed on an "AS IS" BASIS,
12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | // See the License for the specific language governing permissions and
14 | // limitations under the License.
15 | //
16 |
17 | import RIBs
18 |
19 | protocol TicTacToeInteractable: Interactable {
20 | var router: TicTacToeRouting? { get set }
21 | var listener: TicTacToeListener? { get set }
22 | }
23 |
24 | protocol TicTacToeViewControllable: ViewControllable {
25 | // TODO: Declare methods the router invokes to manipulate the view hierarchy.
26 | }
27 |
28 | final class TicTacToeRouter: ViewableRouter, TicTacToeRouting {
29 |
30 | // TODO: Constructor inject child builder protocols to allow building children.
31 | override init(interactor: TicTacToeInteractable, viewController: TicTacToeViewControllable) {
32 | super.init(interactor: interactor, viewController: viewController)
33 | interactor.router = self
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/Example/xcframework/TicTacToe/LoggedOut/LoggedOutRouter.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) 2017. Uber Technologies
3 | //
4 | // Licensed under the Apache License, Version 2.0 (the "License");
5 | // you may not use this file except in compliance with the License.
6 | // You may obtain a copy of the License at
7 | //
8 | // http://www.apache.org/licenses/LICENSE-2.0
9 | //
10 | // Unless required by applicable law or agreed to in writing, software
11 | // distributed under the License is distributed on an "AS IS" BASIS,
12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | // See the License for the specific language governing permissions and
14 | // limitations under the License.
15 | //
16 |
17 | import RIBs
18 |
19 | protocol LoggedOutInteractable: Interactable {
20 | var router: LoggedOutRouting? { get set }
21 | var listener: LoggedOutListener? { get set }
22 | }
23 |
24 | protocol LoggedOutViewControllable: ViewControllable {
25 | // TODO: Declare methods the router invokes to manipulate the view hierarchy.
26 | }
27 |
28 | final class LoggedOutRouter: ViewableRouter, LoggedOutRouting {
29 |
30 | // TODO: Constructor inject child builder protocols to allow building children.
31 | override init(interactor: LoggedOutInteractable, viewController: LoggedOutViewControllable) {
32 | super.init(interactor: interactor, viewController: viewController)
33 | interactor.router = self
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/Example/xcframework/TicTacToe/RandomWin/RandomWinRouter.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) 2017. Uber Technologies
3 | //
4 | // Licensed under the Apache License, Version 2.0 (the "License");
5 | // you may not use this file except in compliance with the License.
6 | // You may obtain a copy of the License at
7 | //
8 | // http://www.apache.org/licenses/LICENSE-2.0
9 | //
10 | // Unless required by applicable law or agreed to in writing, software
11 | // distributed under the License is distributed on an "AS IS" BASIS,
12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | // See the License for the specific language governing permissions and
14 | // limitations under the License.
15 | //
16 |
17 | import RIBs
18 |
19 | protocol RandomWinInteractable: Interactable {
20 | var router: RandomWinRouting? { get set }
21 | var listener: RandomWinListener? { get set }
22 | }
23 |
24 | protocol RandomWinViewControllable: ViewControllable {
25 | // TODO: Declare methods the router invokes to manipulate the view hierarchy.
26 | }
27 |
28 | final class RandomWinRouter: ViewableRouter, RandomWinRouting {
29 |
30 | // TODO: Constructor inject child builder protocols to allow building children.
31 | override init(interactor: RandomWinInteractable, viewController: RandomWinViewControllable) {
32 | super.init(interactor: interactor, viewController: viewController)
33 | interactor.router = self
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/Example/xcframework/TicTacToe/TicTacToe/TicTacToeRouter.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) 2017. Uber Technologies
3 | //
4 | // Licensed under the Apache License, Version 2.0 (the "License");
5 | // you may not use this file except in compliance with the License.
6 | // You may obtain a copy of the License at
7 | //
8 | // http://www.apache.org/licenses/LICENSE-2.0
9 | //
10 | // Unless required by applicable law or agreed to in writing, software
11 | // distributed under the License is distributed on an "AS IS" BASIS,
12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | // See the License for the specific language governing permissions and
14 | // limitations under the License.
15 | //
16 |
17 | import RIBs
18 |
19 | protocol TicTacToeInteractable: Interactable {
20 | var router: TicTacToeRouting? { get set }
21 | var listener: TicTacToeListener? { get set }
22 | }
23 |
24 | protocol TicTacToeViewControllable: ViewControllable {
25 | // TODO: Declare methods the router invokes to manipulate the view hierarchy.
26 | }
27 |
28 | final class TicTacToeRouter: ViewableRouter, TicTacToeRouting {
29 |
30 | // TODO: Constructor inject child builder protocols to allow building children.
31 | override init(interactor: TicTacToeInteractable, viewController: TicTacToeViewControllable) {
32 | super.init(interactor: interactor, viewController: viewController)
33 | interactor.router = self
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/Example/swiftpm/TicTacToe/LoggedIn/RandomWinAdapter.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) 2017. Uber Technologies
3 | //
4 | // Licensed under the Apache License, Version 2.0 (the "License");
5 | // you may not use this file except in compliance with the License.
6 | // You may obtain a copy of the License at
7 | //
8 | // http://www.apache.org/licenses/LICENSE-2.0
9 | //
10 | // Unless required by applicable law or agreed to in writing, software
11 | // distributed under the License is distributed on an "AS IS" BASIS,
12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | // See the License for the specific language governing permissions and
14 | // limitations under the License.
15 | //
16 |
17 | import RIBs
18 |
19 | class RandomWinAdapter: Game, GameBuildable, RandomWinListener {
20 |
21 | let id = "randomwin"
22 | let name = "Random Win"
23 | var builder: GameBuildable {
24 | return self
25 | }
26 |
27 | private let randomWinBuilder: RandomWinBuilder
28 |
29 | private weak var listener: GameListener?
30 |
31 | init(dependency: RandomWinDependency) {
32 | randomWinBuilder = RandomWinBuilder(dependency: dependency)
33 | }
34 |
35 | func build(withListener listener: GameListener) -> ViewableRouting {
36 | self.listener = listener
37 | return randomWinBuilder.build(withListener: self)
38 | }
39 |
40 | func didRandomlyWin(with player: PlayerType) {
41 | listener?.gameDidEnd(with: player)
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/Example/xcframework/TicTacToe/LoggedIn/RandomWinAdapter.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) 2017. Uber Technologies
3 | //
4 | // Licensed under the Apache License, Version 2.0 (the "License");
5 | // you may not use this file except in compliance with the License.
6 | // You may obtain a copy of the License at
7 | //
8 | // http://www.apache.org/licenses/LICENSE-2.0
9 | //
10 | // Unless required by applicable law or agreed to in writing, software
11 | // distributed under the License is distributed on an "AS IS" BASIS,
12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | // See the License for the specific language governing permissions and
14 | // limitations under the License.
15 | //
16 |
17 | import RIBs
18 |
19 | class RandomWinAdapter: Game, GameBuildable, RandomWinListener {
20 |
21 | let id = "randomwin"
22 | let name = "Random Win"
23 | var builder: GameBuildable {
24 | return self
25 | }
26 |
27 | private let randomWinBuilder: RandomWinBuilder
28 |
29 | private weak var listener: GameListener?
30 |
31 | init(dependency: RandomWinDependency) {
32 | randomWinBuilder = RandomWinBuilder(dependency: dependency)
33 | }
34 |
35 | func build(withListener listener: GameListener) -> ViewableRouting {
36 | self.listener = listener
37 | return randomWinBuilder.build(withListener: self)
38 | }
39 |
40 | func didRandomlyWin(with player: PlayerType) {
41 | listener?.gameDidEnd(with: player)
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/Example/swiftpm/TicTacToe/ScoreBoard/BasicScoreBoardRouter.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) 2017. Uber Technologies
3 | //
4 | // Licensed under the Apache License, Version 2.0 (the "License");
5 | // you may not use this file except in compliance with the License.
6 | // You may obtain a copy of the License at
7 | //
8 | // http://www.apache.org/licenses/LICENSE-2.0
9 | //
10 | // Unless required by applicable law or agreed to in writing, software
11 | // distributed under the License is distributed on an "AS IS" BASIS,
12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | // See the License for the specific language governing permissions and
14 | // limitations under the License.
15 | //
16 |
17 | import RIBs
18 |
19 | protocol BasicScoreBoardInteractable: Interactable {
20 | var router: BasicScoreBoardRouting? { get set }
21 | var listener: BasicScoreBoardListener? { get set }
22 | }
23 |
24 | protocol BasicScoreBoardViewControllable: ViewControllable {
25 | // TODO: Declare methods the router invokes to manipulate the view hierarchy.
26 | }
27 |
28 | final class BasicScoreBoardRouter: ViewableRouter, BasicScoreBoardRouting {
29 |
30 | // TODO: Constructor inject child builder protocols to allow building children.
31 | override init(interactor: BasicScoreBoardInteractable, viewController: BasicScoreBoardViewControllable) {
32 | super.init(interactor: interactor, viewController: viewController)
33 | interactor.router = self
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/Example/xcframework/TicTacToe/ScoreBoard/BasicScoreBoardRouter.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) 2017. Uber Technologies
3 | //
4 | // Licensed under the Apache License, Version 2.0 (the "License");
5 | // you may not use this file except in compliance with the License.
6 | // You may obtain a copy of the License at
7 | //
8 | // http://www.apache.org/licenses/LICENSE-2.0
9 | //
10 | // Unless required by applicable law or agreed to in writing, software
11 | // distributed under the License is distributed on an "AS IS" BASIS,
12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | // See the License for the specific language governing permissions and
14 | // limitations under the License.
15 | //
16 |
17 | import RIBs
18 |
19 | protocol BasicScoreBoardInteractable: Interactable {
20 | var router: BasicScoreBoardRouting? { get set }
21 | var listener: BasicScoreBoardListener? { get set }
22 | }
23 |
24 | protocol BasicScoreBoardViewControllable: ViewControllable {
25 | // TODO: Declare methods the router invokes to manipulate the view hierarchy.
26 | }
27 |
28 | final class BasicScoreBoardRouter: ViewableRouter, BasicScoreBoardRouting {
29 |
30 | // TODO: Constructor inject child builder protocols to allow building children.
31 | override init(interactor: BasicScoreBoardInteractable, viewController: BasicScoreBoardViewControllable) {
32 | super.init(interactor: interactor, viewController: viewController)
33 | interactor.router = self
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/Example/xcframework/TicTacToe/Promo/LaunchGameWorkflow.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) 2017. Uber Technologies
3 | //
4 | // Licensed under the Apache License, Version 2.0 (the "License");
5 | // you may not use this file except in compliance with the License.
6 | // You may obtain a copy of the License at
7 | //
8 | // http://www.apache.org/licenses/LICENSE-2.0
9 | //
10 | // Unless required by applicable law or agreed to in writing, software
11 | // distributed under the License is distributed on an "AS IS" BASIS,
12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | // See the License for the specific language governing permissions and
14 | // limitations under the License.
15 | //
16 |
17 | import RIBs
18 | import RxSwift
19 |
20 | public class LaunchGameWorkflow: Workflow {
21 | public init(url: URL) {
22 | super.init()
23 |
24 | let gameId = parseGameId(from: url)
25 |
26 | self
27 | .onStep { (rootItem: RootActionableItem) -> Observable<(LoggedInActionableItem, ())> in
28 | rootItem.waitForLogin()
29 | }
30 | .onStep { (loggedInItem: LoggedInActionableItem, _) -> Observable<(LoggedInActionableItem, ())> in
31 | loggedInItem.launchGame(with: gameId)
32 | }
33 | .commit()
34 | }
35 |
36 | private func parseGameId(from url: URL) -> String? {
37 | let components = URLComponents(string: url.absoluteString)
38 | let items = components?.queryItems ?? []
39 | for item in items {
40 | if item.name == "gameId" {
41 | return item.value
42 | }
43 | }
44 |
45 | return nil
46 | }
47 | }
48 |
49 |
--------------------------------------------------------------------------------
/Example/swiftpm/TicTacToe/Promo/LaunchGameWorkflow.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) 2017. Uber Technologies
3 | //
4 | // Licensed under the Apache License, Version 2.0 (the "License");
5 | // you may not use this file except in compliance with the License.
6 | // You may obtain a copy of the License at
7 | //
8 | // http://www.apache.org/licenses/LICENSE-2.0
9 | //
10 | // Unless required by applicable law or agreed to in writing, software
11 | // distributed under the License is distributed on an "AS IS" BASIS,
12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | // See the License for the specific language governing permissions and
14 | // limitations under the License.
15 | //
16 |
17 | import Foundation
18 | import RIBs
19 | import RxSwift
20 |
21 | public class LaunchGameWorkflow: Workflow {
22 | public init(url: URL) {
23 | super.init()
24 |
25 | let gameId = parseGameId(from: url)
26 |
27 | self
28 | .onStep { (rootItem: RootActionableItem) -> Observable<(LoggedInActionableItem, ())> in
29 | rootItem.waitForLogin()
30 | }
31 | .onStep { (loggedInItem: LoggedInActionableItem, _) -> Observable<(LoggedInActionableItem, ())> in
32 | loggedInItem.launchGame(with: gameId)
33 | }
34 | .commit()
35 | }
36 |
37 | private func parseGameId(from url: URL) -> String? {
38 | let components = URLComponents(string: url.absoluteString)
39 | let items = components?.queryItems ?? []
40 | for item in items {
41 | if item.name == "gameId" {
42 | return item.value
43 | }
44 | }
45 |
46 | return nil
47 | }
48 | }
49 |
50 |
--------------------------------------------------------------------------------
/Example/swiftpm/TicTacToe/LoggedOut/LoggedOutBuilder.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) 2017. Uber Technologies
3 | //
4 | // Licensed under the Apache License, Version 2.0 (the "License");
5 | // you may not use this file except in compliance with the License.
6 | // You may obtain a copy of the License at
7 | //
8 | // http://www.apache.org/licenses/LICENSE-2.0
9 | //
10 | // Unless required by applicable law or agreed to in writing, software
11 | // distributed under the License is distributed on an "AS IS" BASIS,
12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | // See the License for the specific language governing permissions and
14 | // limitations under the License.
15 | //
16 |
17 | import RIBs
18 |
19 | protocol LoggedOutDependency: Dependency {
20 | // TODO: Declare the set of dependencies required by this RIB, but cannot be
21 | // created by this RIB.
22 | }
23 |
24 | final class LoggedOutComponent: Component {
25 |
26 | // TODO: Declare 'fileprivate' dependencies that are only used by this RIB.
27 | }
28 |
29 | // MARK: - Builder
30 |
31 | protocol LoggedOutBuildable: Buildable {
32 | func build(withListener listener: LoggedOutListener) -> LoggedOutRouting
33 | }
34 |
35 | final class LoggedOutBuilder: Builder, LoggedOutBuildable {
36 |
37 | override init(dependency: LoggedOutDependency) {
38 | super.init(dependency: dependency)
39 | }
40 |
41 | func build(withListener listener: LoggedOutListener) -> LoggedOutRouting {
42 | _ = LoggedOutComponent(dependency: dependency)
43 | let viewController = LoggedOutViewController()
44 | let interactor = LoggedOutInteractor(presenter: viewController)
45 | interactor.listener = listener
46 | return LoggedOutRouter(interactor: interactor, viewController: viewController)
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/Example/xcframework/TicTacToe/LoggedOut/LoggedOutBuilder.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) 2017. Uber Technologies
3 | //
4 | // Licensed under the Apache License, Version 2.0 (the "License");
5 | // you may not use this file except in compliance with the License.
6 | // You may obtain a copy of the License at
7 | //
8 | // http://www.apache.org/licenses/LICENSE-2.0
9 | //
10 | // Unless required by applicable law or agreed to in writing, software
11 | // distributed under the License is distributed on an "AS IS" BASIS,
12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | // See the License for the specific language governing permissions and
14 | // limitations under the License.
15 | //
16 |
17 | import RIBs
18 |
19 | protocol LoggedOutDependency: Dependency {
20 | // TODO: Declare the set of dependencies required by this RIB, but cannot be
21 | // created by this RIB.
22 | }
23 |
24 | final class LoggedOutComponent: Component {
25 |
26 | // TODO: Declare 'fileprivate' dependencies that are only used by this RIB.
27 | }
28 |
29 | // MARK: - Builder
30 |
31 | protocol LoggedOutBuildable: Buildable {
32 | func build(withListener listener: LoggedOutListener) -> LoggedOutRouting
33 | }
34 |
35 | final class LoggedOutBuilder: Builder, LoggedOutBuildable {
36 |
37 | override init(dependency: LoggedOutDependency) {
38 | super.init(dependency: dependency)
39 | }
40 |
41 | func build(withListener listener: LoggedOutListener) -> LoggedOutRouting {
42 | _ = LoggedOutComponent(dependency: dependency)
43 | let viewController = LoggedOutViewController()
44 | let interactor = LoggedOutInteractor(presenter: viewController)
45 | interactor.listener = listener
46 | return LoggedOutRouter(interactor: interactor, viewController: viewController)
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/Example/swiftpm/TicTacToe/OffGame/OffGameRouter.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) 2017. Uber Technologies
3 | //
4 | // Licensed under the Apache License, Version 2.0 (the "License");
5 | // you may not use this file except in compliance with the License.
6 | // You may obtain a copy of the License at
7 | //
8 | // http://www.apache.org/licenses/LICENSE-2.0
9 | //
10 | // Unless required by applicable law or agreed to in writing, software
11 | // distributed under the License is distributed on an "AS IS" BASIS,
12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | // See the License for the specific language governing permissions and
14 | // limitations under the License.
15 | //
16 |
17 | import RIBs
18 |
19 | protocol OffGameInteractable: Interactable, BasicScoreBoardListener {
20 | var router: OffGameRouting? { get set }
21 | var listener: OffGameListener? { get set }
22 | }
23 |
24 | protocol OffGameViewControllable: ViewControllable {
25 | func show(scoreBoardView: ViewControllable)
26 | }
27 |
28 | final class OffGameRouter: ViewableRouter, OffGameRouting {
29 |
30 | init(interactor: OffGameInteractable,
31 | viewController: OffGameViewControllable,
32 | scoreBoardBuilder: BasicScoreBoardBuildable) {
33 | self.scoreBoardBuilder = scoreBoardBuilder
34 | super.init(interactor: interactor, viewController: viewController)
35 | interactor.router = self
36 | }
37 |
38 | override func didLoad() {
39 | super.didLoad()
40 |
41 | attachScoreBoard()
42 | }
43 |
44 | // MARK: - Private
45 |
46 | private var scoreBoardBuilder: BasicScoreBoardBuildable
47 |
48 | private func attachScoreBoard() {
49 | let scoreBoard = scoreBoardBuilder.build(withListener: interactor)
50 | attachChild(scoreBoard)
51 | viewController.show(scoreBoardView: scoreBoard.viewControllable)
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/Example/swiftpm/TicTacToe/Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | $(DEVELOPMENT_LANGUAGE)
7 | CFBundleExecutable
8 | $(EXECUTABLE_NAME)
9 | CFBundleIcons
10 |
11 | CFBundleIcons~ipad
12 |
13 | CFBundleIdentifier
14 | $(PRODUCT_BUNDLE_IDENTIFIER)
15 | CFBundleInfoDictionaryVersion
16 | 6.0
17 | CFBundleName
18 | $(PRODUCT_NAME)
19 | CFBundlePackageType
20 | APPL
21 | CFBundleShortVersionString
22 | 1.0
23 | CFBundleVersion
24 | 1
25 | LSRequiresIPhoneOS
26 |
27 | UIRequiredDeviceCapabilities
28 |
29 | armv7
30 |
31 | UISupportedInterfaceOrientations
32 |
33 | UIInterfaceOrientationPortrait
34 | UIInterfaceOrientationLandscapeLeft
35 | UIInterfaceOrientationLandscapeRight
36 |
37 | UISupportedInterfaceOrientations~ipad
38 |
39 | UIInterfaceOrientationPortrait
40 | UIInterfaceOrientationPortraitUpsideDown
41 | UIInterfaceOrientationLandscapeLeft
42 | UIInterfaceOrientationLandscapeRight
43 |
44 | CFBundleURLTypes
45 |
46 |
47 | CFBundleURLName
48 | com.ubercab.Game
49 | CFBundleURLSchemes
50 |
51 | ribs-training
52 |
53 |
54 |
55 |
56 |
57 |
--------------------------------------------------------------------------------
/Example/xcframework/TicTacToe/OffGame/OffGameRouter.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) 2017. Uber Technologies
3 | //
4 | // Licensed under the Apache License, Version 2.0 (the "License");
5 | // you may not use this file except in compliance with the License.
6 | // You may obtain a copy of the License at
7 | //
8 | // http://www.apache.org/licenses/LICENSE-2.0
9 | //
10 | // Unless required by applicable law or agreed to in writing, software
11 | // distributed under the License is distributed on an "AS IS" BASIS,
12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | // See the License for the specific language governing permissions and
14 | // limitations under the License.
15 | //
16 |
17 | import RIBs
18 |
19 | protocol OffGameInteractable: Interactable, BasicScoreBoardListener {
20 | var router: OffGameRouting? { get set }
21 | var listener: OffGameListener? { get set }
22 | }
23 |
24 | protocol OffGameViewControllable: ViewControllable {
25 | func show(scoreBoardView: ViewControllable)
26 | }
27 |
28 | final class OffGameRouter: ViewableRouter, OffGameRouting {
29 |
30 | init(interactor: OffGameInteractable,
31 | viewController: OffGameViewControllable,
32 | scoreBoardBuilder: BasicScoreBoardBuildable) {
33 | self.scoreBoardBuilder = scoreBoardBuilder
34 | super.init(interactor: interactor, viewController: viewController)
35 | interactor.router = self
36 | }
37 |
38 | override func didLoad() {
39 | super.didLoad()
40 |
41 | attachScoreBoard()
42 | }
43 |
44 | // MARK: - Private
45 |
46 | private var scoreBoardBuilder: BasicScoreBoardBuildable
47 |
48 | private func attachScoreBoard() {
49 | let scoreBoard = scoreBoardBuilder.build(withListener: interactor)
50 | attachChild(scoreBoard)
51 | viewController.show(scoreBoardView: scoreBoard.viewControllable)
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/Example/xcframework/TicTacToe/Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | $(DEVELOPMENT_LANGUAGE)
7 | CFBundleExecutable
8 | $(EXECUTABLE_NAME)
9 | CFBundleIcons
10 |
11 | CFBundleIcons~ipad
12 |
13 | CFBundleIdentifier
14 | $(PRODUCT_BUNDLE_IDENTIFIER)
15 | CFBundleInfoDictionaryVersion
16 | 6.0
17 | CFBundleName
18 | $(PRODUCT_NAME)
19 | CFBundlePackageType
20 | APPL
21 | CFBundleShortVersionString
22 | 1.0
23 | CFBundleVersion
24 | 1
25 | LSRequiresIPhoneOS
26 |
27 | UIRequiredDeviceCapabilities
28 |
29 | armv7
30 |
31 | UISupportedInterfaceOrientations
32 |
33 | UIInterfaceOrientationPortrait
34 | UIInterfaceOrientationLandscapeLeft
35 | UIInterfaceOrientationLandscapeRight
36 |
37 | UISupportedInterfaceOrientations~ipad
38 |
39 | UIInterfaceOrientationPortrait
40 | UIInterfaceOrientationPortraitUpsideDown
41 | UIInterfaceOrientationLandscapeLeft
42 | UIInterfaceOrientationLandscapeRight
43 |
44 | CFBundleURLTypes
45 |
46 |
47 | CFBundleURLName
48 | com.ubercab.Game
49 | CFBundleURLSchemes
50 |
51 | ribs-training
52 |
53 |
54 |
55 |
56 |
57 |
--------------------------------------------------------------------------------
/Example/swiftpm/TicTacToe/OffGame/OffGameInteractor.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) 2017. Uber Technologies
3 | //
4 | // Licensed under the Apache License, Version 2.0 (the "License");
5 | // you may not use this file except in compliance with the License.
6 | // You may obtain a copy of the License at
7 | //
8 | // http://www.apache.org/licenses/LICENSE-2.0
9 | //
10 | // Unless required by applicable law or agreed to in writing, software
11 | // distributed under the License is distributed on an "AS IS" BASIS,
12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | // See the License for the specific language governing permissions and
14 | // limitations under the License.
15 | //
16 |
17 | import RIBs
18 | import RxSwift
19 |
20 | protocol OffGameRouting: ViewableRouting {
21 | // TODO: Declare methods the interactor can invoke to manage sub-tree via the router.
22 | }
23 |
24 | protocol OffGamePresentable: Presentable {
25 | var listener: OffGamePresentableListener? { get set }
26 | // TODO: Declare methods the interactor can invoke the presenter to present data.
27 | }
28 |
29 | protocol OffGameListener: class {
30 | func startGame(with gameBuilder: GameBuildable)
31 | }
32 |
33 | final class OffGameInteractor: PresentableInteractor, OffGameInteractable, OffGamePresentableListener {
34 |
35 | weak var router: OffGameRouting?
36 |
37 | weak var listener: OffGameListener?
38 |
39 | // TODO: Add additional dependencies to constructor. Do not perform any logic
40 | // in constructor.
41 | override init(presenter: OffGamePresentable) {
42 | super.init(presenter: presenter)
43 | presenter.listener = self
44 | }
45 |
46 | override func didBecomeActive() {
47 | super.didBecomeActive()
48 | // TODO: Implement business logic here.
49 | }
50 |
51 | override func willResignActive() {
52 | super.willResignActive()
53 | // TODO: Pause any business logic.
54 | }
55 |
56 | // MARK: - OffGamePresentableListener
57 |
58 | func start(_ game: Game) {
59 | listener?.startGame(with: game.builder)
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/Example/xcframework/TicTacToe/OffGame/OffGameInteractor.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) 2017. Uber Technologies
3 | //
4 | // Licensed under the Apache License, Version 2.0 (the "License");
5 | // you may not use this file except in compliance with the License.
6 | // You may obtain a copy of the License at
7 | //
8 | // http://www.apache.org/licenses/LICENSE-2.0
9 | //
10 | // Unless required by applicable law or agreed to in writing, software
11 | // distributed under the License is distributed on an "AS IS" BASIS,
12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | // See the License for the specific language governing permissions and
14 | // limitations under the License.
15 | //
16 |
17 | import RIBs
18 | import RxSwift
19 |
20 | protocol OffGameRouting: ViewableRouting {
21 | // TODO: Declare methods the interactor can invoke to manage sub-tree via the router.
22 | }
23 |
24 | protocol OffGamePresentable: Presentable {
25 | var listener: OffGamePresentableListener? { get set }
26 | // TODO: Declare methods the interactor can invoke the presenter to present data.
27 | }
28 |
29 | protocol OffGameListener: class {
30 | func startGame(with gameBuilder: GameBuildable)
31 | }
32 |
33 | final class OffGameInteractor: PresentableInteractor, OffGameInteractable, OffGamePresentableListener {
34 |
35 | weak var router: OffGameRouting?
36 |
37 | weak var listener: OffGameListener?
38 |
39 | // TODO: Add additional dependencies to constructor. Do not perform any logic
40 | // in constructor.
41 | override init(presenter: OffGamePresentable) {
42 | super.init(presenter: presenter)
43 | presenter.listener = self
44 | }
45 |
46 | override func didBecomeActive() {
47 | super.didBecomeActive()
48 | // TODO: Implement business logic here.
49 | }
50 |
51 | override func willResignActive() {
52 | super.willResignActive()
53 | // TODO: Pause any business logic.
54 | }
55 |
56 | // MARK: - OffGamePresentableListener
57 |
58 | func start(_ game: Game) {
59 | listener?.startGame(with: game.builder)
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/Example/swiftpm/TicTacToe/ScoreBoard/BasicScoreBoardInteractor.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) 2017. Uber Technologies
3 | //
4 | // Licensed under the Apache License, Version 2.0 (the "License");
5 | // you may not use this file except in compliance with the License.
6 | // You may obtain a copy of the License at
7 | //
8 | // http://www.apache.org/licenses/LICENSE-2.0
9 | //
10 | // Unless required by applicable law or agreed to in writing, software
11 | // distributed under the License is distributed on an "AS IS" BASIS,
12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | // See the License for the specific language governing permissions and
14 | // limitations under the License.
15 | //
16 |
17 | import RIBs
18 | import RxSwift
19 |
20 | public protocol BasicScoreBoardRouting: ViewableRouting {
21 | // TODO: Declare methods the interactor can invoke to manage sub-tree via the router.
22 | }
23 |
24 | protocol BasicScoreBoardPresentable: Presentable {
25 | var listener: BasicScoreBoardPresentableListener? { get set }
26 | func set(score: Score)
27 | }
28 |
29 | public protocol BasicScoreBoardListener: class {
30 | // TODO: Declare methods the interactor can invoke to communicate with other RIBs.
31 | }
32 |
33 | final class BasicScoreBoardInteractor: PresentableInteractor, BasicScoreBoardInteractable, BasicScoreBoardPresentableListener {
34 |
35 | weak var router: BasicScoreBoardRouting?
36 |
37 | weak var listener: BasicScoreBoardListener?
38 |
39 | init(presenter: BasicScoreBoardPresentable,
40 | scoreStream: ScoreStream) {
41 | self.scoreStream = scoreStream
42 | super.init(presenter: presenter)
43 | presenter.listener = self
44 | }
45 |
46 | override func didBecomeActive() {
47 | super.didBecomeActive()
48 |
49 | updateScore()
50 | }
51 |
52 | // MARK: - Private
53 |
54 | private let scoreStream: ScoreStream
55 |
56 | private func updateScore() {
57 | scoreStream.score
58 | .subscribe(onNext: { (score: Score) in
59 | self.presenter.set(score: score)
60 | })
61 | .disposeOnDeactivate(interactor: self)
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/Example/xcframework/TicTacToe/ScoreBoard/BasicScoreBoardInteractor.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) 2017. Uber Technologies
3 | //
4 | // Licensed under the Apache License, Version 2.0 (the "License");
5 | // you may not use this file except in compliance with the License.
6 | // You may obtain a copy of the License at
7 | //
8 | // http://www.apache.org/licenses/LICENSE-2.0
9 | //
10 | // Unless required by applicable law or agreed to in writing, software
11 | // distributed under the License is distributed on an "AS IS" BASIS,
12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | // See the License for the specific language governing permissions and
14 | // limitations under the License.
15 | //
16 |
17 | import RIBs
18 | import RxSwift
19 |
20 | public protocol BasicScoreBoardRouting: ViewableRouting {
21 | // TODO: Declare methods the interactor can invoke to manage sub-tree via the router.
22 | }
23 |
24 | protocol BasicScoreBoardPresentable: Presentable {
25 | var listener: BasicScoreBoardPresentableListener? { get set }
26 | func set(score: Score)
27 | }
28 |
29 | public protocol BasicScoreBoardListener: class {
30 | // TODO: Declare methods the interactor can invoke to communicate with other RIBs.
31 | }
32 |
33 | final class BasicScoreBoardInteractor: PresentableInteractor, BasicScoreBoardInteractable, BasicScoreBoardPresentableListener {
34 |
35 | weak var router: BasicScoreBoardRouting?
36 |
37 | weak var listener: BasicScoreBoardListener?
38 |
39 | init(presenter: BasicScoreBoardPresentable,
40 | scoreStream: ScoreStream) {
41 | self.scoreStream = scoreStream
42 | super.init(presenter: presenter)
43 | presenter.listener = self
44 | }
45 |
46 | override func didBecomeActive() {
47 | super.didBecomeActive()
48 |
49 | updateScore()
50 | }
51 |
52 | // MARK: - Private
53 |
54 | private let scoreStream: ScoreStream
55 |
56 | private func updateScore() {
57 | scoreStream.score
58 | .subscribe(onNext: { (score: Score) in
59 | self.presenter.set(score: score)
60 | })
61 | .disposeOnDeactivate(interactor: self)
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/Example/swiftpm/TicTacToe/Models/ScoreStream.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) 2017. Uber Technologies
3 | //
4 | // Licensed under the Apache License, Version 2.0 (the "License");
5 | // you may not use this file except in compliance with the License.
6 | // You may obtain a copy of the License at
7 | //
8 | // http://www.apache.org/licenses/LICENSE-2.0
9 | //
10 | // Unless required by applicable law or agreed to in writing, software
11 | // distributed under the License is distributed on an "AS IS" BASIS,
12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | // See the License for the specific language governing permissions and
14 | // limitations under the License.
15 | //
16 |
17 | import RxSwift
18 |
19 | public struct Score {
20 | public let player1Score: Int
21 | public let player2Score: Int
22 |
23 | public static func equals(lhs: Score, rhs: Score) -> Bool {
24 | return lhs.player1Score == rhs.player1Score && lhs.player2Score == rhs.player2Score
25 | }
26 | }
27 |
28 | public protocol ScoreStream: class {
29 | var score: Observable { get }
30 | }
31 |
32 | public protocol MutableScoreStream: ScoreStream {
33 | func updateScore(with winner: PlayerType)
34 | }
35 |
36 | public class ScoreStreamImpl: MutableScoreStream {
37 |
38 | public init() {}
39 |
40 | public var score: Observable {
41 | return variable
42 | .asObservable()
43 | .distinctUntilChanged { (lhs: Score, rhs: Score) -> Bool in
44 | Score.equals(lhs: lhs, rhs: rhs)
45 | }
46 | }
47 |
48 | public func updateScore(with winner: PlayerType) {
49 | let newScore: Score = {
50 | let currentScore = variable.value
51 | switch winner {
52 | case .player1:
53 | return Score(player1Score: currentScore.player1Score + 1, player2Score: currentScore.player2Score)
54 | case .player2:
55 | return Score(player1Score: currentScore.player1Score, player2Score: currentScore.player2Score + 1)
56 | }
57 | }()
58 | variable.value = newScore
59 | }
60 |
61 | // MARK: - Private
62 |
63 | private let variable = Variable(Score(player1Score: 0, player2Score: 0))
64 | }
65 |
--------------------------------------------------------------------------------
/Example/xcframework/TicTacToe/Models/ScoreStream.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) 2017. Uber Technologies
3 | //
4 | // Licensed under the Apache License, Version 2.0 (the "License");
5 | // you may not use this file except in compliance with the License.
6 | // You may obtain a copy of the License at
7 | //
8 | // http://www.apache.org/licenses/LICENSE-2.0
9 | //
10 | // Unless required by applicable law or agreed to in writing, software
11 | // distributed under the License is distributed on an "AS IS" BASIS,
12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | // See the License for the specific language governing permissions and
14 | // limitations under the License.
15 | //
16 |
17 | import RxSwift
18 |
19 | public struct Score {
20 | public let player1Score: Int
21 | public let player2Score: Int
22 |
23 | public static func equals(lhs: Score, rhs: Score) -> Bool {
24 | return lhs.player1Score == rhs.player1Score && lhs.player2Score == rhs.player2Score
25 | }
26 | }
27 |
28 | public protocol ScoreStream: class {
29 | var score: Observable { get }
30 | }
31 |
32 | public protocol MutableScoreStream: ScoreStream {
33 | func updateScore(with winner: PlayerType)
34 | }
35 |
36 | public class ScoreStreamImpl: MutableScoreStream {
37 |
38 | public init() {}
39 |
40 | public var score: Observable {
41 | return variable
42 | .asObservable()
43 | .distinctUntilChanged { (lhs: Score, rhs: Score) -> Bool in
44 | Score.equals(lhs: lhs, rhs: rhs)
45 | }
46 | }
47 |
48 | public func updateScore(with winner: PlayerType) {
49 | let newScore: Score = {
50 | let currentScore = variable.value
51 | switch winner {
52 | case .player1:
53 | return Score(player1Score: currentScore.player1Score + 1, player2Score: currentScore.player2Score)
54 | case .player2:
55 | return Score(player1Score: currentScore.player1Score, player2Score: currentScore.player2Score + 1)
56 | }
57 | }()
58 | variable.value = newScore
59 | }
60 |
61 | // MARK: - Private
62 |
63 | private let variable = Variable(Score(player1Score: 0, player2Score: 0))
64 | }
65 |
--------------------------------------------------------------------------------
/Example/swiftpm/TicTacToe/OffGame/OffGameBuilder.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) 2017. Uber Technologies
3 | //
4 | // Licensed under the Apache License, Version 2.0 (the "License");
5 | // you may not use this file except in compliance with the License.
6 | // You may obtain a copy of the License at
7 | //
8 | // http://www.apache.org/licenses/LICENSE-2.0
9 | //
10 | // Unless required by applicable law or agreed to in writing, software
11 | // distributed under the License is distributed on an "AS IS" BASIS,
12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | // See the License for the specific language governing permissions and
14 | // limitations under the License.
15 | //
16 |
17 | import RIBs
18 |
19 | public protocol OffGameDependency: Dependency {
20 | var player1Name: String { get }
21 | var player2Name: String { get }
22 | var scoreStream: ScoreStream { get }
23 | }
24 |
25 | final class OffGameComponent: Component, BasicScoreBoardDependency {
26 |
27 | var player1Name: String {
28 | return dependency.player1Name
29 | }
30 |
31 | var player2Name: String {
32 | return dependency.player2Name
33 | }
34 |
35 | var scoreStream: ScoreStream {
36 | return dependency.scoreStream
37 | }
38 | }
39 |
40 | // MARK: - Builder
41 |
42 | protocol OffGameBuildable: Buildable {
43 | func build(withListener listener: OffGameListener, games: [Game]) -> OffGameRouting
44 | }
45 |
46 | final class OffGameBuilder: Builder, OffGameBuildable {
47 |
48 | override init(dependency: OffGameDependency) {
49 | super.init(dependency: dependency)
50 | }
51 |
52 | func build(withListener listener: OffGameListener, games: [Game]) -> OffGameRouting {
53 | let component = OffGameComponent(dependency: dependency)
54 | let viewController = OffGameViewController(games: games)
55 | let interactor = OffGameInteractor(presenter: viewController)
56 | interactor.listener = listener
57 |
58 | let scoreBoardBuilder = BasicScoreBoardBuilder(dependency: component)
59 | let router = OffGameRouter(interactor: interactor,
60 | viewController: viewController,
61 | scoreBoardBuilder: scoreBoardBuilder)
62 | return router
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/Example/xcframework/TicTacToe/OffGame/OffGameBuilder.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) 2017. Uber Technologies
3 | //
4 | // Licensed under the Apache License, Version 2.0 (the "License");
5 | // you may not use this file except in compliance with the License.
6 | // You may obtain a copy of the License at
7 | //
8 | // http://www.apache.org/licenses/LICENSE-2.0
9 | //
10 | // Unless required by applicable law or agreed to in writing, software
11 | // distributed under the License is distributed on an "AS IS" BASIS,
12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | // See the License for the specific language governing permissions and
14 | // limitations under the License.
15 | //
16 |
17 | import RIBs
18 |
19 | public protocol OffGameDependency: Dependency {
20 | var player1Name: String { get }
21 | var player2Name: String { get }
22 | var scoreStream: ScoreStream { get }
23 | }
24 |
25 | final class OffGameComponent: Component, BasicScoreBoardDependency {
26 |
27 | var player1Name: String {
28 | return dependency.player1Name
29 | }
30 |
31 | var player2Name: String {
32 | return dependency.player2Name
33 | }
34 |
35 | var scoreStream: ScoreStream {
36 | return dependency.scoreStream
37 | }
38 | }
39 |
40 | // MARK: - Builder
41 |
42 | protocol OffGameBuildable: Buildable {
43 | func build(withListener listener: OffGameListener, games: [Game]) -> OffGameRouting
44 | }
45 |
46 | final class OffGameBuilder: Builder, OffGameBuildable {
47 |
48 | override init(dependency: OffGameDependency) {
49 | super.init(dependency: dependency)
50 | }
51 |
52 | func build(withListener listener: OffGameListener, games: [Game]) -> OffGameRouting {
53 | let component = OffGameComponent(dependency: dependency)
54 | let viewController = OffGameViewController(games: games)
55 | let interactor = OffGameInteractor(presenter: viewController)
56 | interactor.listener = listener
57 |
58 | let scoreBoardBuilder = BasicScoreBoardBuilder(dependency: component)
59 | let router = OffGameRouter(interactor: interactor,
60 | viewController: viewController,
61 | scoreBoardBuilder: scoreBoardBuilder)
62 | return router
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/Example/swiftpm/TicTacToe/TicTacToe/TicTacToeBuilder.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) 2017. Uber Technologies
3 | //
4 | // Licensed under the Apache License, Version 2.0 (the "License");
5 | // you may not use this file except in compliance with the License.
6 | // You may obtain a copy of the License at
7 | //
8 | // http://www.apache.org/licenses/LICENSE-2.0
9 | //
10 | // Unless required by applicable law or agreed to in writing, software
11 | // distributed under the License is distributed on an "AS IS" BASIS,
12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | // See the License for the specific language governing permissions and
14 | // limitations under the License.
15 | //
16 |
17 | import RIBs
18 |
19 | protocol TicTacToeDependency: Dependency {
20 | var player1Name: String { get }
21 | var player2Name: String { get }
22 | var mutableScoreStream: MutableScoreStream { get }
23 | }
24 |
25 | final class TicTacToeComponent: Component {
26 |
27 | fileprivate var player1Name: String {
28 | return dependency.player1Name
29 | }
30 |
31 | fileprivate var player2Name: String {
32 | return dependency.player2Name
33 | }
34 |
35 | fileprivate var mutableScoreStream: MutableScoreStream {
36 | return dependency.mutableScoreStream
37 | }
38 | }
39 |
40 | // MARK: - Builder
41 |
42 | protocol TicTacToeBuildable: Buildable {
43 | func build(withListener listener: TicTacToeListener) -> TicTacToeRouting
44 | }
45 |
46 | final class TicTacToeBuilder: Builder, TicTacToeBuildable {
47 |
48 | override init(dependency: TicTacToeDependency) {
49 | super.init(dependency: dependency)
50 | }
51 |
52 | func build(withListener listener: TicTacToeListener) -> TicTacToeRouting {
53 | let component = TicTacToeComponent(dependency: dependency)
54 | let viewController = TicTacToeViewController(player1Name: component.player1Name,
55 | player2Name: component.player2Name)
56 | let interactor = TicTacToeInteractor(presenter: viewController,
57 | mutableScoreStream: component.mutableScoreStream)
58 | interactor.listener = listener
59 | return TicTacToeRouter(interactor: interactor, viewController: viewController)
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/Example/xcframework/TicTacToe/TicTacToe/TicTacToeBuilder.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) 2017. Uber Technologies
3 | //
4 | // Licensed under the Apache License, Version 2.0 (the "License");
5 | // you may not use this file except in compliance with the License.
6 | // You may obtain a copy of the License at
7 | //
8 | // http://www.apache.org/licenses/LICENSE-2.0
9 | //
10 | // Unless required by applicable law or agreed to in writing, software
11 | // distributed under the License is distributed on an "AS IS" BASIS,
12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | // See the License for the specific language governing permissions and
14 | // limitations under the License.
15 | //
16 |
17 | import RIBs
18 |
19 | protocol TicTacToeDependency: Dependency {
20 | var player1Name: String { get }
21 | var player2Name: String { get }
22 | var mutableScoreStream: MutableScoreStream { get }
23 | }
24 |
25 | final class TicTacToeComponent: Component {
26 |
27 | fileprivate var player1Name: String {
28 | return dependency.player1Name
29 | }
30 |
31 | fileprivate var player2Name: String {
32 | return dependency.player2Name
33 | }
34 |
35 | fileprivate var mutableScoreStream: MutableScoreStream {
36 | return dependency.mutableScoreStream
37 | }
38 | }
39 |
40 | // MARK: - Builder
41 |
42 | protocol TicTacToeBuildable: Buildable {
43 | func build(withListener listener: TicTacToeListener) -> TicTacToeRouting
44 | }
45 |
46 | final class TicTacToeBuilder: Builder, TicTacToeBuildable {
47 |
48 | override init(dependency: TicTacToeDependency) {
49 | super.init(dependency: dependency)
50 | }
51 |
52 | func build(withListener listener: TicTacToeListener) -> TicTacToeRouting {
53 | let component = TicTacToeComponent(dependency: dependency)
54 | let viewController = TicTacToeViewController(player1Name: component.player1Name,
55 | player2Name: component.player2Name)
56 | let interactor = TicTacToeInteractor(presenter: viewController,
57 | mutableScoreStream: component.mutableScoreStream)
58 | interactor.listener = listener
59 | return TicTacToeRouter(interactor: interactor, viewController: viewController)
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/Example/swiftpm/TicTacToe/RandomWin/RandomWinBuilder.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) 2017. Uber Technologies
3 | //
4 | // Licensed under the Apache License, Version 2.0 (the "License");
5 | // you may not use this file except in compliance with the License.
6 | // You may obtain a copy of the License at
7 | //
8 | // http://www.apache.org/licenses/LICENSE-2.0
9 | //
10 | // Unless required by applicable law or agreed to in writing, software
11 | // distributed under the License is distributed on an "AS IS" BASIS,
12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | // See the License for the specific language governing permissions and
14 | // limitations under the License.
15 | //
16 |
17 | import RIBs
18 |
19 | public protocol RandomWinDependency: Dependency {
20 | var player1Name: String { get }
21 | var player2Name: String { get }
22 | var mutableScoreStream: MutableScoreStream { get }
23 | }
24 |
25 | final class RandomWinComponent: Component {
26 |
27 | fileprivate var player1Name: String {
28 | return dependency.player1Name
29 | }
30 |
31 | fileprivate var player2Name: String {
32 | return dependency.player2Name
33 | }
34 |
35 | fileprivate var mutableScoreStream: MutableScoreStream {
36 | return dependency.mutableScoreStream
37 | }
38 | }
39 |
40 | // MARK: - Builder
41 |
42 | protocol RandomWinBuildable: Buildable {
43 | func build(withListener listener: RandomWinListener) -> RandomWinRouting
44 | }
45 |
46 | public final class RandomWinBuilder: Builder, RandomWinBuildable {
47 |
48 | public override init(dependency: RandomWinDependency) {
49 | super.init(dependency: dependency)
50 | }
51 |
52 | public func build(withListener listener: RandomWinListener) -> RandomWinRouting {
53 | let component = RandomWinComponent(dependency: dependency)
54 | let viewController = RandomWinViewController(player1Name: component.player1Name,
55 | player2Name: component.player2Name)
56 | let interactor = RandomWinInteractor(presenter: viewController,
57 | mutableScoreStream: component.mutableScoreStream)
58 | interactor.listener = listener
59 | return RandomWinRouter(interactor: interactor, viewController: viewController)
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/Example/swiftpm/TicTacToe/Root/RootBuilder.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) 2017. Uber Technologies
3 | //
4 | // Licensed under the Apache License, Version 2.0 (the "License");
5 | // you may not use this file except in compliance with the License.
6 | // You may obtain a copy of the License at
7 | //
8 | // http://www.apache.org/licenses/LICENSE-2.0
9 | //
10 | // Unless required by applicable law or agreed to in writing, software
11 | // distributed under the License is distributed on an "AS IS" BASIS,
12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | // See the License for the specific language governing permissions and
14 | // limitations under the License.
15 | //
16 |
17 | import RIBs
18 |
19 | protocol RootDependency: Dependency {
20 | // TODO: Declare the set of dependencies required by this RIB, but cannot be
21 | // created by this RIB.
22 | }
23 |
24 | final class RootComponent: Component {
25 |
26 | let rootViewController: RootViewController
27 |
28 | init(dependency: RootDependency,
29 | rootViewController: RootViewController) {
30 | self.rootViewController = rootViewController
31 | super.init(dependency: dependency)
32 | }
33 | }
34 |
35 | // MARK: - Builder
36 |
37 | protocol RootBuildable: Buildable {
38 | func build() -> (launchRouter: LaunchRouting, urlHandler: UrlHandler)
39 | }
40 |
41 | final class RootBuilder: Builder, RootBuildable {
42 |
43 | override init(dependency: RootDependency) {
44 | super.init(dependency: dependency)
45 | }
46 |
47 | func build() -> (launchRouter: LaunchRouting, urlHandler: UrlHandler) {
48 | let viewController = RootViewController()
49 | let component = RootComponent(dependency: dependency,
50 | rootViewController: viewController)
51 | let interactor = RootInteractor(presenter: viewController)
52 |
53 | let loggedOutBuilder = LoggedOutBuilder(dependency: component)
54 | let loggedInBuilder = LoggedInBuilder(dependency: component)
55 | let router = RootRouter(interactor: interactor,
56 | viewController: viewController,
57 | loggedOutBuilder: loggedOutBuilder,
58 | loggedInBuilder: loggedInBuilder)
59 |
60 | return (router, interactor)
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/Example/xcframework/TicTacToe/RandomWin/RandomWinBuilder.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) 2017. Uber Technologies
3 | //
4 | // Licensed under the Apache License, Version 2.0 (the "License");
5 | // you may not use this file except in compliance with the License.
6 | // You may obtain a copy of the License at
7 | //
8 | // http://www.apache.org/licenses/LICENSE-2.0
9 | //
10 | // Unless required by applicable law or agreed to in writing, software
11 | // distributed under the License is distributed on an "AS IS" BASIS,
12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | // See the License for the specific language governing permissions and
14 | // limitations under the License.
15 | //
16 |
17 | import RIBs
18 |
19 | public protocol RandomWinDependency: Dependency {
20 | var player1Name: String { get }
21 | var player2Name: String { get }
22 | var mutableScoreStream: MutableScoreStream { get }
23 | }
24 |
25 | final class RandomWinComponent: Component {
26 |
27 | fileprivate var player1Name: String {
28 | return dependency.player1Name
29 | }
30 |
31 | fileprivate var player2Name: String {
32 | return dependency.player2Name
33 | }
34 |
35 | fileprivate var mutableScoreStream: MutableScoreStream {
36 | return dependency.mutableScoreStream
37 | }
38 | }
39 |
40 | // MARK: - Builder
41 |
42 | protocol RandomWinBuildable: Buildable {
43 | func build(withListener listener: RandomWinListener) -> RandomWinRouting
44 | }
45 |
46 | public final class RandomWinBuilder: Builder, RandomWinBuildable {
47 |
48 | public override init(dependency: RandomWinDependency) {
49 | super.init(dependency: dependency)
50 | }
51 |
52 | public func build(withListener listener: RandomWinListener) -> RandomWinRouting {
53 | let component = RandomWinComponent(dependency: dependency)
54 | let viewController = RandomWinViewController(player1Name: component.player1Name,
55 | player2Name: component.player2Name)
56 | let interactor = RandomWinInteractor(presenter: viewController,
57 | mutableScoreStream: component.mutableScoreStream)
58 | interactor.listener = listener
59 | return RandomWinRouter(interactor: interactor, viewController: viewController)
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/Example/xcframework/TicTacToe/Root/RootBuilder.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) 2017. Uber Technologies
3 | //
4 | // Licensed under the Apache License, Version 2.0 (the "License");
5 | // you may not use this file except in compliance with the License.
6 | // You may obtain a copy of the License at
7 | //
8 | // http://www.apache.org/licenses/LICENSE-2.0
9 | //
10 | // Unless required by applicable law or agreed to in writing, software
11 | // distributed under the License is distributed on an "AS IS" BASIS,
12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | // See the License for the specific language governing permissions and
14 | // limitations under the License.
15 | //
16 |
17 | import RIBs
18 |
19 | protocol RootDependency: Dependency {
20 | // TODO: Declare the set of dependencies required by this RIB, but cannot be
21 | // created by this RIB.
22 | }
23 |
24 | final class RootComponent: Component {
25 |
26 | let rootViewController: RootViewController
27 |
28 | init(dependency: RootDependency,
29 | rootViewController: RootViewController) {
30 | self.rootViewController = rootViewController
31 | super.init(dependency: dependency)
32 | }
33 | }
34 |
35 | // MARK: - Builder
36 |
37 | protocol RootBuildable: Buildable {
38 | func build() -> (launchRouter: LaunchRouting, urlHandler: UrlHandler)
39 | }
40 |
41 | final class RootBuilder: Builder, RootBuildable {
42 |
43 | override init(dependency: RootDependency) {
44 | super.init(dependency: dependency)
45 | }
46 |
47 | func build() -> (launchRouter: LaunchRouting, urlHandler: UrlHandler) {
48 | let viewController = RootViewController()
49 | let component = RootComponent(dependency: dependency,
50 | rootViewController: viewController)
51 | let interactor = RootInteractor(presenter: viewController)
52 |
53 | let loggedOutBuilder = LoggedOutBuilder(dependency: component)
54 | let loggedInBuilder = LoggedInBuilder(dependency: component)
55 | let router = RootRouter(interactor: interactor,
56 | viewController: viewController,
57 | loggedOutBuilder: loggedOutBuilder,
58 | loggedInBuilder: loggedInBuilder)
59 |
60 | return (router, interactor)
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/Example/swiftpm/TicTacToe/ScoreBoard/BasicScoreBoardBuilder.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) 2017. Uber Technologies
3 | //
4 | // Licensed under the Apache License, Version 2.0 (the "License");
5 | // you may not use this file except in compliance with the License.
6 | // You may obtain a copy of the License at
7 | //
8 | // http://www.apache.org/licenses/LICENSE-2.0
9 | //
10 | // Unless required by applicable law or agreed to in writing, software
11 | // distributed under the License is distributed on an "AS IS" BASIS,
12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | // See the License for the specific language governing permissions and
14 | // limitations under the License.
15 | //
16 |
17 | import RIBs
18 |
19 | public protocol BasicScoreBoardDependency: Dependency {
20 | var player1Name: String { get }
21 | var player2Name: String { get }
22 | var scoreStream: ScoreStream { get }
23 | }
24 |
25 | final class BasicScoreBoardComponent: Component {
26 |
27 | fileprivate var player1Name: String {
28 | return dependency.player1Name
29 | }
30 |
31 | fileprivate var player2Name: String {
32 | return dependency.player2Name
33 | }
34 |
35 | fileprivate var scoreStream: ScoreStream {
36 | return dependency.scoreStream
37 | }
38 | }
39 |
40 | // MARK: - Builder
41 |
42 | protocol BasicScoreBoardBuildable: Buildable {
43 | func build(withListener listener: BasicScoreBoardListener) -> BasicScoreBoardRouting
44 | }
45 |
46 | public final class BasicScoreBoardBuilder: Builder, BasicScoreBoardBuildable {
47 |
48 | public override init(dependency: BasicScoreBoardDependency) {
49 | super.init(dependency: dependency)
50 | }
51 |
52 | public func build(withListener listener: BasicScoreBoardListener) -> BasicScoreBoardRouting {
53 | let component = BasicScoreBoardComponent(dependency: dependency)
54 | let viewController = BasicScoreBoardViewController(player1Name: component.player1Name,
55 | player2Name: component.player2Name)
56 | let interactor = BasicScoreBoardInteractor(presenter: viewController,
57 | scoreStream: component.scoreStream)
58 | interactor.listener = listener
59 | return BasicScoreBoardRouter(interactor: interactor, viewController: viewController)
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/Example/xcframework/TicTacToe/ScoreBoard/BasicScoreBoardBuilder.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) 2017. Uber Technologies
3 | //
4 | // Licensed under the Apache License, Version 2.0 (the "License");
5 | // you may not use this file except in compliance with the License.
6 | // You may obtain a copy of the License at
7 | //
8 | // http://www.apache.org/licenses/LICENSE-2.0
9 | //
10 | // Unless required by applicable law or agreed to in writing, software
11 | // distributed under the License is distributed on an "AS IS" BASIS,
12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | // See the License for the specific language governing permissions and
14 | // limitations under the License.
15 | //
16 |
17 | import RIBs
18 |
19 | public protocol BasicScoreBoardDependency: Dependency {
20 | var player1Name: String { get }
21 | var player2Name: String { get }
22 | var scoreStream: ScoreStream { get }
23 | }
24 |
25 | final class BasicScoreBoardComponent: Component {
26 |
27 | fileprivate var player1Name: String {
28 | return dependency.player1Name
29 | }
30 |
31 | fileprivate var player2Name: String {
32 | return dependency.player2Name
33 | }
34 |
35 | fileprivate var scoreStream: ScoreStream {
36 | return dependency.scoreStream
37 | }
38 | }
39 |
40 | // MARK: - Builder
41 |
42 | protocol BasicScoreBoardBuildable: Buildable {
43 | func build(withListener listener: BasicScoreBoardListener) -> BasicScoreBoardRouting
44 | }
45 |
46 | public final class BasicScoreBoardBuilder: Builder, BasicScoreBoardBuildable {
47 |
48 | public override init(dependency: BasicScoreBoardDependency) {
49 | super.init(dependency: dependency)
50 | }
51 |
52 | public func build(withListener listener: BasicScoreBoardListener) -> BasicScoreBoardRouting {
53 | let component = BasicScoreBoardComponent(dependency: dependency)
54 | let viewController = BasicScoreBoardViewController(player1Name: component.player1Name,
55 | player2Name: component.player2Name)
56 | let interactor = BasicScoreBoardInteractor(presenter: viewController,
57 | scoreStream: component.scoreStream)
58 | interactor.listener = listener
59 | return BasicScoreBoardRouter(interactor: interactor, viewController: viewController)
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/Example/xcframework/TicTacToe/RandomWin/RandomWinInteractor.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) 2017. Uber Technologies
3 | //
4 | // Licensed under the Apache License, Version 2.0 (the "License");
5 | // you may not use this file except in compliance with the License.
6 | // You may obtain a copy of the License at
7 | //
8 | // http://www.apache.org/licenses/LICENSE-2.0
9 | //
10 | // Unless required by applicable law or agreed to in writing, software
11 | // distributed under the License is distributed on an "AS IS" BASIS,
12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | // See the License for the specific language governing permissions and
14 | // limitations under the License.
15 | //
16 |
17 | import RIBs
18 | import RxSwift
19 |
20 | public protocol RandomWinRouting: ViewableRouting {
21 | // TODO: Declare methods the interactor can invoke to manage sub-tree via the router.
22 | }
23 |
24 | protocol RandomWinPresentable: Presentable {
25 | var listener: RandomWinPresentableListener? { get set }
26 | func announce(winner: PlayerType, withCompletionHandler handler: @escaping () -> ())
27 | }
28 |
29 | public protocol RandomWinListener: class {
30 | func didRandomlyWin(with player: PlayerType)
31 | }
32 |
33 | final class RandomWinInteractor: PresentableInteractor, RandomWinInteractable, RandomWinPresentableListener {
34 |
35 | weak var router: RandomWinRouting?
36 |
37 | weak var listener: RandomWinListener?
38 |
39 | init(presenter: RandomWinPresentable,
40 | mutableScoreStream: MutableScoreStream) {
41 | self.mutableScoreStream = mutableScoreStream
42 | super.init(presenter: presenter)
43 | presenter.listener = self
44 | }
45 |
46 | override func didBecomeActive() {
47 | super.didBecomeActive()
48 | // TODO: Implement business logic here.
49 | }
50 |
51 | override func willResignActive() {
52 | super.willResignActive()
53 | // TODO: Pause any business logic.
54 | }
55 |
56 | // MARK: - RandomWinPresentableListener
57 |
58 | func determineWinner() {
59 | let random = arc4random_uniform(100)
60 | let winner = random > 50 ? PlayerType.player1 : PlayerType.player2
61 | presenter.announce(winner: winner) {
62 | self.mutableScoreStream.updateScore(with: winner)
63 | self.listener?.didRandomlyWin(with: winner)
64 | }
65 | }
66 |
67 | // MARK: - Private
68 |
69 | private let mutableScoreStream: MutableScoreStream
70 | }
71 |
--------------------------------------------------------------------------------
/Example/swiftpm/TicTacToe/RandomWin/RandomWinInteractor.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) 2017. Uber Technologies
3 | //
4 | // Licensed under the Apache License, Version 2.0 (the "License");
5 | // you may not use this file except in compliance with the License.
6 | // You may obtain a copy of the License at
7 | //
8 | // http://www.apache.org/licenses/LICENSE-2.0
9 | //
10 | // Unless required by applicable law or agreed to in writing, software
11 | // distributed under the License is distributed on an "AS IS" BASIS,
12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | // See the License for the specific language governing permissions and
14 | // limitations under the License.
15 | //
16 |
17 | import Foundation
18 | import RIBs
19 | import RxSwift
20 |
21 | public protocol RandomWinRouting: ViewableRouting {
22 | // TODO: Declare methods the interactor can invoke to manage sub-tree via the router.
23 | }
24 |
25 | protocol RandomWinPresentable: Presentable {
26 | var listener: RandomWinPresentableListener? { get set }
27 | func announce(winner: PlayerType, withCompletionHandler handler: @escaping () -> ())
28 | }
29 |
30 | public protocol RandomWinListener: class {
31 | func didRandomlyWin(with player: PlayerType)
32 | }
33 |
34 | final class RandomWinInteractor: PresentableInteractor, RandomWinInteractable, RandomWinPresentableListener {
35 |
36 | weak var router: RandomWinRouting?
37 |
38 | weak var listener: RandomWinListener?
39 |
40 | init(presenter: RandomWinPresentable,
41 | mutableScoreStream: MutableScoreStream) {
42 | self.mutableScoreStream = mutableScoreStream
43 | super.init(presenter: presenter)
44 | presenter.listener = self
45 | }
46 |
47 | override func didBecomeActive() {
48 | super.didBecomeActive()
49 | // TODO: Implement business logic here.
50 | }
51 |
52 | override func willResignActive() {
53 | super.willResignActive()
54 | // TODO: Pause any business logic.
55 | }
56 |
57 | // MARK: - RandomWinPresentableListener
58 |
59 | func determineWinner() {
60 | let random = arc4random_uniform(100)
61 | let winner = random > 50 ? PlayerType.player1 : PlayerType.player2
62 | presenter.announce(winner: winner) {
63 | self.mutableScoreStream.updateScore(with: winner)
64 | self.listener?.didRandomlyWin(with: winner)
65 | }
66 | }
67 |
68 | // MARK: - Private
69 |
70 | private let mutableScoreStream: MutableScoreStream
71 | }
72 |
--------------------------------------------------------------------------------
/Example/swiftpm/TicTacToe/LoggedIn/LoggedInInteractor.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) 2017. Uber Technologies
3 | //
4 | // Licensed under the Apache License, Version 2.0 (the "License");
5 | // you may not use this file except in compliance with the License.
6 | // You may obtain a copy of the License at
7 | //
8 | // http://www.apache.org/licenses/LICENSE-2.0
9 | //
10 | // Unless required by applicable law or agreed to in writing, software
11 | // distributed under the License is distributed on an "AS IS" BASIS,
12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | // See the License for the specific language governing permissions and
14 | // limitations under the License.
15 | //
16 |
17 | import RIBs
18 | import RxSwift
19 |
20 | protocol LoggedInRouting: Routing {
21 | func cleanupViews()
22 | func routeToOffGame(with games: [Game])
23 | func routeToGame(with gameBuilder: GameBuildable)
24 | }
25 |
26 | protocol LoggedInListener: class {
27 | // TODO: Declare methods the interactor can invoke to communicate with other RIBs.
28 | }
29 |
30 | final class LoggedInInteractor: Interactor, LoggedInInteractable, LoggedInActionableItem {
31 |
32 | weak var router: LoggedInRouting?
33 | weak var listener: LoggedInListener?
34 |
35 | // TODO: Add additional dependencies to constructor. Do not perform any logic
36 | // in constructor.
37 | init(games: [Game]) {
38 | self.games = games
39 | super.init()
40 | }
41 |
42 | override func didBecomeActive() {
43 | super.didBecomeActive()
44 |
45 | router?.routeToOffGame(with: games)
46 | }
47 |
48 | override func willResignActive() {
49 | super.willResignActive()
50 |
51 | router?.cleanupViews()
52 | // TODO: Pause any business logic.
53 | }
54 |
55 | // MARK: - OffGameListener
56 |
57 | func startGame(with gameBuilder: GameBuildable) {
58 | router?.routeToGame(with: gameBuilder)
59 | }
60 |
61 | // MARK: - TicTacToeListener
62 |
63 | func gameDidEnd(with winner: PlayerType?) {
64 | router?.routeToOffGame(with: games)
65 | }
66 |
67 | // MARK: - LoggedInActionableItem
68 |
69 | func launchGame(with id: String?) -> Observable<(LoggedInActionableItem, ())> {
70 | let game: Game? = games.first { game in
71 | return game.id.lowercased() == id?.lowercased()
72 | }
73 |
74 | if let game = game {
75 | router?.routeToGame(with: game.builder)
76 | }
77 |
78 | return Observable.just((self, ()))
79 | }
80 |
81 | // MARK: - Private
82 |
83 | private var games = [Game]()
84 |
85 | }
86 |
--------------------------------------------------------------------------------
/Example/xcframework/TicTacToe/LoggedIn/LoggedInInteractor.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) 2017. Uber Technologies
3 | //
4 | // Licensed under the Apache License, Version 2.0 (the "License");
5 | // you may not use this file except in compliance with the License.
6 | // You may obtain a copy of the License at
7 | //
8 | // http://www.apache.org/licenses/LICENSE-2.0
9 | //
10 | // Unless required by applicable law or agreed to in writing, software
11 | // distributed under the License is distributed on an "AS IS" BASIS,
12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | // See the License for the specific language governing permissions and
14 | // limitations under the License.
15 | //
16 |
17 | import RIBs
18 | import RxSwift
19 |
20 | protocol LoggedInRouting: Routing {
21 | func cleanupViews()
22 | func routeToOffGame(with games: [Game])
23 | func routeToGame(with gameBuilder: GameBuildable)
24 | }
25 |
26 | protocol LoggedInListener: class {
27 | // TODO: Declare methods the interactor can invoke to communicate with other RIBs.
28 | }
29 |
30 | final class LoggedInInteractor: Interactor, LoggedInInteractable, LoggedInActionableItem {
31 |
32 | weak var router: LoggedInRouting?
33 | weak var listener: LoggedInListener?
34 |
35 | // TODO: Add additional dependencies to constructor. Do not perform any logic
36 | // in constructor.
37 | init(games: [Game]) {
38 | self.games = games
39 | super.init()
40 | }
41 |
42 | override func didBecomeActive() {
43 | super.didBecomeActive()
44 |
45 | router?.routeToOffGame(with: games)
46 | }
47 |
48 | override func willResignActive() {
49 | super.willResignActive()
50 |
51 | router?.cleanupViews()
52 | // TODO: Pause any business logic.
53 | }
54 |
55 | // MARK: - OffGameListener
56 |
57 | func startGame(with gameBuilder: GameBuildable) {
58 | router?.routeToGame(with: gameBuilder)
59 | }
60 |
61 | // MARK: - TicTacToeListener
62 |
63 | func gameDidEnd(with winner: PlayerType?) {
64 | router?.routeToOffGame(with: games)
65 | }
66 |
67 | // MARK: - LoggedInActionableItem
68 |
69 | func launchGame(with id: String?) -> Observable<(LoggedInActionableItem, ())> {
70 | let game: Game? = games.first { game in
71 | return game.id.lowercased() == id?.lowercased()
72 | }
73 |
74 | if let game = game {
75 | router?.routeToGame(with: game.builder)
76 | }
77 |
78 | return Observable.just((self, ()))
79 | }
80 |
81 | // MARK: - Private
82 |
83 | private var games = [Game]()
84 |
85 | }
86 |
--------------------------------------------------------------------------------
/Example/swiftpm/TicTacToe/Root/RootRouter.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) 2017. Uber Technologies
3 | //
4 | // Licensed under the Apache License, Version 2.0 (the "License");
5 | // you may not use this file except in compliance with the License.
6 | // You may obtain a copy of the License at
7 | //
8 | // http://www.apache.org/licenses/LICENSE-2.0
9 | //
10 | // Unless required by applicable law or agreed to in writing, software
11 | // distributed under the License is distributed on an "AS IS" BASIS,
12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | // See the License for the specific language governing permissions and
14 | // limitations under the License.
15 | //
16 |
17 | import RIBs
18 |
19 | protocol RootInteractable: Interactable, LoggedOutListener, LoggedInListener {
20 | var router: RootRouting? { get set }
21 | var listener: RootListener? { get set }
22 | }
23 |
24 | protocol RootViewControllable: ViewControllable {
25 | func replaceModal(viewController: ViewControllable?)
26 | }
27 |
28 | final class RootRouter: LaunchRouter, RootRouting {
29 |
30 | init(interactor: RootInteractable,
31 | viewController: RootViewControllable,
32 | loggedOutBuilder: LoggedOutBuildable,
33 | loggedInBuilder: LoggedInBuildable) {
34 | self.loggedOutBuilder = loggedOutBuilder
35 | self.loggedInBuilder = loggedInBuilder
36 | super.init(interactor: interactor, viewController: viewController)
37 | interactor.router = self
38 | }
39 |
40 | override func didLoad() {
41 | super.didLoad()
42 |
43 | routeToLoggedOut()
44 | }
45 |
46 | func routeToLoggedIn(withPlayer1Name player1Name: String, player2Name: String) -> LoggedInActionableItem {
47 | // Detach logged out.
48 | if let loggedOut = self.loggedOut {
49 | detachChild(loggedOut)
50 | viewController.replaceModal(viewController: nil)
51 | self.loggedOut = nil
52 | }
53 |
54 | let loggedIn = loggedInBuilder.build(withListener: interactor, player1Name: player1Name, player2Name: player2Name)
55 | attachChild(loggedIn.router)
56 | return loggedIn.actionableItem
57 | }
58 |
59 | // MARK: - Private
60 |
61 | private let loggedOutBuilder: LoggedOutBuildable
62 | private let loggedInBuilder: LoggedInBuildable
63 |
64 | private var loggedOut: ViewableRouting?
65 |
66 | private func routeToLoggedOut() {
67 | let loggedOut = loggedOutBuilder.build(withListener: interactor)
68 | self.loggedOut = loggedOut
69 | attachChild(loggedOut)
70 | viewController.replaceModal(viewController: loggedOut.viewControllable)
71 | }
72 | }
73 |
--------------------------------------------------------------------------------
/Example/xcframework/TicTacToe/Root/RootRouter.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) 2017. Uber Technologies
3 | //
4 | // Licensed under the Apache License, Version 2.0 (the "License");
5 | // you may not use this file except in compliance with the License.
6 | // You may obtain a copy of the License at
7 | //
8 | // http://www.apache.org/licenses/LICENSE-2.0
9 | //
10 | // Unless required by applicable law or agreed to in writing, software
11 | // distributed under the License is distributed on an "AS IS" BASIS,
12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | // See the License for the specific language governing permissions and
14 | // limitations under the License.
15 | //
16 |
17 | import RIBs
18 |
19 | protocol RootInteractable: Interactable, LoggedOutListener, LoggedInListener {
20 | var router: RootRouting? { get set }
21 | var listener: RootListener? { get set }
22 | }
23 |
24 | protocol RootViewControllable: ViewControllable {
25 | func replaceModal(viewController: ViewControllable?)
26 | }
27 |
28 | final class RootRouter: LaunchRouter, RootRouting {
29 |
30 | init(interactor: RootInteractable,
31 | viewController: RootViewControllable,
32 | loggedOutBuilder: LoggedOutBuildable,
33 | loggedInBuilder: LoggedInBuildable) {
34 | self.loggedOutBuilder = loggedOutBuilder
35 | self.loggedInBuilder = loggedInBuilder
36 | super.init(interactor: interactor, viewController: viewController)
37 | interactor.router = self
38 | }
39 |
40 | override func didLoad() {
41 | super.didLoad()
42 |
43 | routeToLoggedOut()
44 | }
45 |
46 | func routeToLoggedIn(withPlayer1Name player1Name: String, player2Name: String) -> LoggedInActionableItem {
47 | // Detach logged out.
48 | if let loggedOut = self.loggedOut {
49 | detachChild(loggedOut)
50 | viewController.replaceModal(viewController: nil)
51 | self.loggedOut = nil
52 | }
53 |
54 | let loggedIn = loggedInBuilder.build(withListener: interactor, player1Name: player1Name, player2Name: player2Name)
55 | attachChild(loggedIn.router)
56 | return loggedIn.actionableItem
57 | }
58 |
59 | // MARK: - Private
60 |
61 | private let loggedOutBuilder: LoggedOutBuildable
62 | private let loggedInBuilder: LoggedInBuildable
63 |
64 | private var loggedOut: ViewableRouting?
65 |
66 | private func routeToLoggedOut() {
67 | let loggedOut = loggedOutBuilder.build(withListener: interactor)
68 | self.loggedOut = loggedOut
69 | attachChild(loggedOut)
70 | viewController.replaceModal(viewController: loggedOut.viewControllable)
71 | }
72 | }
73 |
--------------------------------------------------------------------------------
/Example/swiftpm/TicTacToe/LoggedOut/LoggedOutInteractor.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) 2017. Uber Technologies
3 | //
4 | // Licensed under the Apache License, Version 2.0 (the "License");
5 | // you may not use this file except in compliance with the License.
6 | // You may obtain a copy of the License at
7 | //
8 | // http://www.apache.org/licenses/LICENSE-2.0
9 | //
10 | // Unless required by applicable law or agreed to in writing, software
11 | // distributed under the License is distributed on an "AS IS" BASIS,
12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | // See the License for the specific language governing permissions and
14 | // limitations under the License.
15 | //
16 |
17 | import RIBs
18 | import RxSwift
19 |
20 | protocol LoggedOutRouting: ViewableRouting {
21 | // TODO: Declare methods the interactor can invoke to manage sub-tree via the router.
22 | }
23 |
24 | protocol LoggedOutPresentable: Presentable {
25 | var listener: LoggedOutPresentableListener? { get set }
26 | // TODO: Declare methods the interactor can invoke the presenter to present data.
27 | }
28 |
29 | protocol LoggedOutListener: class {
30 | func didLogin(withPlayer1Name player1Name: String, player2Name: String)
31 | }
32 |
33 | final class LoggedOutInteractor: PresentableInteractor, LoggedOutInteractable, LoggedOutPresentableListener {
34 |
35 | weak var router: LoggedOutRouting?
36 |
37 | weak var listener: LoggedOutListener?
38 |
39 | // TODO: Add additional dependencies to constructor. Do not perform any logic
40 | // in constructor.
41 | override init(presenter: LoggedOutPresentable) {
42 | super.init(presenter: presenter)
43 | presenter.listener = self
44 | }
45 |
46 | override func didBecomeActive() {
47 | super.didBecomeActive()
48 | // TODO: Implement business logic here.
49 | }
50 |
51 | override func willResignActive() {
52 | super.willResignActive()
53 | // TODO: Pause any business logic.
54 | }
55 |
56 | // MARK: - LoggedOutPresentableListener
57 |
58 | func login(withPlayer1Name player1Name: String?, player2Name: String?) {
59 | let player1NameWithDefault = playerName(player1Name, withDefaultName: "Player 1")
60 | let player2NameWithDefault = playerName(player2Name, withDefaultName: "Player 2")
61 |
62 | listener?.didLogin(withPlayer1Name: player1NameWithDefault, player2Name: player2NameWithDefault)
63 | }
64 |
65 | private func playerName(_ name: String?, withDefaultName defaultName: String) -> String {
66 | if let name = name {
67 | return name.isEmpty ? defaultName : name
68 | } else {
69 | return defaultName
70 | }
71 | }
72 | }
73 |
--------------------------------------------------------------------------------
/Example/xcframework/TicTacToe/LoggedOut/LoggedOutInteractor.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) 2017. Uber Technologies
3 | //
4 | // Licensed under the Apache License, Version 2.0 (the "License");
5 | // you may not use this file except in compliance with the License.
6 | // You may obtain a copy of the License at
7 | //
8 | // http://www.apache.org/licenses/LICENSE-2.0
9 | //
10 | // Unless required by applicable law or agreed to in writing, software
11 | // distributed under the License is distributed on an "AS IS" BASIS,
12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | // See the License for the specific language governing permissions and
14 | // limitations under the License.
15 | //
16 |
17 | import RIBs
18 | import RxSwift
19 |
20 | protocol LoggedOutRouting: ViewableRouting {
21 | // TODO: Declare methods the interactor can invoke to manage sub-tree via the router.
22 | }
23 |
24 | protocol LoggedOutPresentable: Presentable {
25 | var listener: LoggedOutPresentableListener? { get set }
26 | // TODO: Declare methods the interactor can invoke the presenter to present data.
27 | }
28 |
29 | protocol LoggedOutListener: class {
30 | func didLogin(withPlayer1Name player1Name: String, player2Name: String)
31 | }
32 |
33 | final class LoggedOutInteractor: PresentableInteractor, LoggedOutInteractable, LoggedOutPresentableListener {
34 |
35 | weak var router: LoggedOutRouting?
36 |
37 | weak var listener: LoggedOutListener?
38 |
39 | // TODO: Add additional dependencies to constructor. Do not perform any logic
40 | // in constructor.
41 | override init(presenter: LoggedOutPresentable) {
42 | super.init(presenter: presenter)
43 | presenter.listener = self
44 | }
45 |
46 | override func didBecomeActive() {
47 | super.didBecomeActive()
48 | // TODO: Implement business logic here.
49 | }
50 |
51 | override func willResignActive() {
52 | super.willResignActive()
53 | // TODO: Pause any business logic.
54 | }
55 |
56 | // MARK: - LoggedOutPresentableListener
57 |
58 | func login(withPlayer1Name player1Name: String?, player2Name: String?) {
59 | let player1NameWithDefault = playerName(player1Name, withDefaultName: "Player 1")
60 | let player2NameWithDefault = playerName(player2Name, withDefaultName: "Player 2")
61 |
62 | listener?.didLogin(withPlayer1Name: player1NameWithDefault, player2Name: player2NameWithDefault)
63 | }
64 |
65 | private func playerName(_ name: String?, withDefaultName defaultName: String) -> String {
66 | if let name = name {
67 | return name.isEmpty ? defaultName : name
68 | } else {
69 | return defaultName
70 | }
71 | }
72 | }
73 |
--------------------------------------------------------------------------------
/Example/swiftpm/TicTacToe/LoggedIn/LoggedInRouter.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) 2017. Uber Technologies
3 | //
4 | // Licensed under the Apache License, Version 2.0 (the "License");
5 | // you may not use this file except in compliance with the License.
6 | // You may obtain a copy of the License at
7 | //
8 | // http://www.apache.org/licenses/LICENSE-2.0
9 | //
10 | // Unless required by applicable law or agreed to in writing, software
11 | // distributed under the License is distributed on an "AS IS" BASIS,
12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | // See the License for the specific language governing permissions and
14 | // limitations under the License.
15 | //
16 |
17 | import RIBs
18 |
19 | protocol LoggedInInteractable: Interactable, OffGameListener, GameListener {
20 | var router: LoggedInRouting? { get set }
21 | var listener: LoggedInListener? { get set }
22 | }
23 |
24 | protocol LoggedInViewControllable: ViewControllable {
25 | func replaceModal(viewController: ViewControllable?)
26 | }
27 |
28 | final class LoggedInRouter: Router, LoggedInRouting {
29 |
30 | init(interactor: LoggedInInteractable,
31 | viewController: LoggedInViewControllable,
32 | offGameBuilder: OffGameBuildable) {
33 | self.viewController = viewController
34 | self.offGameBuilder = offGameBuilder
35 | super.init(interactor: interactor)
36 | interactor.router = self
37 | }
38 |
39 | // MARK: - LoggedInRouting
40 |
41 | func cleanupViews() {
42 | if currentChild != nil {
43 | viewController.replaceModal(viewController: nil)
44 | }
45 | }
46 |
47 | func routeToOffGame(with games: [Game]) {
48 | detachCurrentChild()
49 | attachOffGame(with: games)
50 | }
51 |
52 | func routeToGame(with gameBuilder: GameBuildable) {
53 | detachCurrentChild()
54 |
55 | let game = gameBuilder.build(withListener: interactor)
56 | self.currentChild = game
57 | attachChild(game)
58 | viewController.replaceModal(viewController: game.viewControllable)
59 | }
60 |
61 | // MARK: - Private
62 |
63 | private let viewController: LoggedInViewControllable
64 | private let offGameBuilder: OffGameBuildable
65 |
66 | private var currentChild: ViewableRouting?
67 |
68 | private func attachOffGame(with games: [Game]) {
69 | let offGame = offGameBuilder.build(withListener: interactor, games: games)
70 | self.currentChild = offGame
71 | attachChild(offGame)
72 | viewController.replaceModal(viewController: offGame.viewControllable)
73 | }
74 |
75 | private func detachCurrentChild() {
76 | if let currentChild = currentChild {
77 | detachChild(currentChild)
78 | viewController.replaceModal(viewController: nil)
79 | }
80 | }
81 | }
82 |
--------------------------------------------------------------------------------
/Example/swiftpm/TicTacToe/Root/RootViewController.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) 2017. Uber Technologies
3 | //
4 | // Licensed under the Apache License, Version 2.0 (the "License");
5 | // you may not use this file except in compliance with the License.
6 | // You may obtain a copy of the License at
7 | //
8 | // http://www.apache.org/licenses/LICENSE-2.0
9 | //
10 | // Unless required by applicable law or agreed to in writing, software
11 | // distributed under the License is distributed on an "AS IS" BASIS,
12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | // See the License for the specific language governing permissions and
14 | // limitations under the License.
15 | //
16 |
17 | import RIBs
18 | import SnapKit
19 | import UIKit
20 |
21 | protocol RootPresentableListener: class {
22 | // TODO: Declare properties and methods that the view controller can invoke to perform
23 | // business logic, such as signIn(). This protocol is implemented by the corresponding
24 | // interactor class.
25 | }
26 |
27 | final class RootViewController: UIViewController, RootPresentable, RootViewControllable {
28 |
29 | weak var listener: RootPresentableListener?
30 |
31 | init() {
32 | super.init(nibName: nil, bundle: nil)
33 | }
34 |
35 | required init?(coder aDecoder: NSCoder) {
36 | fatalError("Method is not supported")
37 | }
38 |
39 | override func viewDidLoad() {
40 | super.viewDidLoad()
41 |
42 | view.backgroundColor = UIColor.white
43 | }
44 |
45 | // MARK: - RootViewControllable
46 |
47 | func replaceModal(viewController: ViewControllable?) {
48 | targetViewController = viewController
49 |
50 | guard !animationInProgress else {
51 | return
52 | }
53 |
54 | if presentedViewController != nil {
55 | animationInProgress = true
56 | dismiss(animated: true) { [weak self] in
57 | if self?.targetViewController != nil {
58 | self?.presentTargetViewController()
59 | } else {
60 | self?.animationInProgress = false
61 | }
62 | }
63 | } else {
64 | presentTargetViewController()
65 | }
66 | }
67 |
68 | // MARK: - Private
69 |
70 | private var targetViewController: ViewControllable?
71 | private var animationInProgress = false
72 |
73 | private func presentTargetViewController() {
74 | if let targetViewController = targetViewController {
75 | animationInProgress = true
76 | present(targetViewController.uiviewController, animated: true) { [weak self] in
77 | self?.animationInProgress = false
78 | }
79 | }
80 | }
81 | }
82 |
83 | // MARK: LoggedInViewControllable
84 |
85 | extension RootViewController: LoggedInViewControllable {
86 |
87 | }
88 |
--------------------------------------------------------------------------------
/Example/xcframework/TicTacToe/LoggedIn/LoggedInRouter.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) 2017. Uber Technologies
3 | //
4 | // Licensed under the Apache License, Version 2.0 (the "License");
5 | // you may not use this file except in compliance with the License.
6 | // You may obtain a copy of the License at
7 | //
8 | // http://www.apache.org/licenses/LICENSE-2.0
9 | //
10 | // Unless required by applicable law or agreed to in writing, software
11 | // distributed under the License is distributed on an "AS IS" BASIS,
12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | // See the License for the specific language governing permissions and
14 | // limitations under the License.
15 | //
16 |
17 | import RIBs
18 |
19 | protocol LoggedInInteractable: Interactable, OffGameListener, GameListener {
20 | var router: LoggedInRouting? { get set }
21 | var listener: LoggedInListener? { get set }
22 | }
23 |
24 | protocol LoggedInViewControllable: ViewControllable {
25 | func replaceModal(viewController: ViewControllable?)
26 | }
27 |
28 | final class LoggedInRouter: Router, LoggedInRouting {
29 |
30 | init(interactor: LoggedInInteractable,
31 | viewController: LoggedInViewControllable,
32 | offGameBuilder: OffGameBuildable) {
33 | self.viewController = viewController
34 | self.offGameBuilder = offGameBuilder
35 | super.init(interactor: interactor)
36 | interactor.router = self
37 | }
38 |
39 | // MARK: - LoggedInRouting
40 |
41 | func cleanupViews() {
42 | if currentChild != nil {
43 | viewController.replaceModal(viewController: nil)
44 | }
45 | }
46 |
47 | func routeToOffGame(with games: [Game]) {
48 | detachCurrentChild()
49 | attachOffGame(with: games)
50 | }
51 |
52 | func routeToGame(with gameBuilder: GameBuildable) {
53 | detachCurrentChild()
54 |
55 | let game = gameBuilder.build(withListener: interactor)
56 | self.currentChild = game
57 | attachChild(game)
58 | viewController.replaceModal(viewController: game.viewControllable)
59 | }
60 |
61 | // MARK: - Private
62 |
63 | private let viewController: LoggedInViewControllable
64 | private let offGameBuilder: OffGameBuildable
65 |
66 | private var currentChild: ViewableRouting?
67 |
68 | private func attachOffGame(with games: [Game]) {
69 | let offGame = offGameBuilder.build(withListener: interactor, games: games)
70 | self.currentChild = offGame
71 | attachChild(offGame)
72 | viewController.replaceModal(viewController: offGame.viewControllable)
73 | }
74 |
75 | private func detachCurrentChild() {
76 | if let currentChild = currentChild {
77 | detachChild(currentChild)
78 | viewController.replaceModal(viewController: nil)
79 | }
80 | }
81 | }
82 |
--------------------------------------------------------------------------------
/Example/xcframework/TicTacToe/Root/RootViewController.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) 2017. Uber Technologies
3 | //
4 | // Licensed under the Apache License, Version 2.0 (the "License");
5 | // you may not use this file except in compliance with the License.
6 | // You may obtain a copy of the License at
7 | //
8 | // http://www.apache.org/licenses/LICENSE-2.0
9 | //
10 | // Unless required by applicable law or agreed to in writing, software
11 | // distributed under the License is distributed on an "AS IS" BASIS,
12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | // See the License for the specific language governing permissions and
14 | // limitations under the License.
15 | //
16 |
17 | import RIBs
18 | import SnapKit
19 | import UIKit
20 |
21 | protocol RootPresentableListener: class {
22 | // TODO: Declare properties and methods that the view controller can invoke to perform
23 | // business logic, such as signIn(). This protocol is implemented by the corresponding
24 | // interactor class.
25 | }
26 |
27 | final class RootViewController: UIViewController, RootPresentable, RootViewControllable {
28 |
29 | weak var listener: RootPresentableListener?
30 |
31 | init() {
32 | super.init(nibName: nil, bundle: nil)
33 | }
34 |
35 | required init?(coder aDecoder: NSCoder) {
36 | fatalError("Method is not supported")
37 | }
38 |
39 | override func viewDidLoad() {
40 | super.viewDidLoad()
41 |
42 | view.backgroundColor = UIColor.white
43 | }
44 |
45 | // MARK: - RootViewControllable
46 |
47 | func replaceModal(viewController: ViewControllable?) {
48 | targetViewController = viewController
49 |
50 | guard !animationInProgress else {
51 | return
52 | }
53 |
54 | if presentedViewController != nil {
55 | animationInProgress = true
56 | dismiss(animated: true) { [weak self] in
57 | if self?.targetViewController != nil {
58 | self?.presentTargetViewController()
59 | } else {
60 | self?.animationInProgress = false
61 | }
62 | }
63 | } else {
64 | presentTargetViewController()
65 | }
66 | }
67 |
68 | // MARK: - Private
69 |
70 | private var targetViewController: ViewControllable?
71 | private var animationInProgress = false
72 |
73 | private func presentTargetViewController() {
74 | if let targetViewController = targetViewController {
75 | animationInProgress = true
76 | present(targetViewController.uiviewController, animated: true) { [weak self] in
77 | self?.animationInProgress = false
78 | }
79 | }
80 | }
81 | }
82 |
83 | // MARK: LoggedInViewControllable
84 |
85 | extension RootViewController: LoggedInViewControllable {
86 |
87 | }
88 |
--------------------------------------------------------------------------------
/Example/swiftpm/TicTacToe/LoggedIn/LoggedInBuilder.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) 2017. Uber Technologies
3 | //
4 | // Licensed under the Apache License, Version 2.0 (the "License");
5 | // you may not use this file except in compliance with the License.
6 | // You may obtain a copy of the License at
7 | //
8 | // http://www.apache.org/licenses/LICENSE-2.0
9 | //
10 | // Unless required by applicable law or agreed to in writing, software
11 | // distributed under the License is distributed on an "AS IS" BASIS,
12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | // See the License for the specific language governing permissions and
14 | // limitations under the License.
15 | //
16 |
17 | import RIBs
18 |
19 | protocol LoggedInDependency: Dependency {
20 | var loggedInViewController: LoggedInViewControllable { get }
21 | }
22 |
23 | final class LoggedInComponent: Component {
24 |
25 | fileprivate var loggedInViewController: LoggedInViewControllable {
26 | return dependency.loggedInViewController
27 | }
28 |
29 | fileprivate var games: [Game] {
30 | return shared {
31 | return [RandomWinAdapter(dependency: self), TicTacToeAdapter(dependency: self)]
32 | }
33 | }
34 |
35 | var mutableScoreStream: MutableScoreStream {
36 | return shared { ScoreStreamImpl() }
37 | }
38 |
39 | var scoreStream: ScoreStream {
40 | return mutableScoreStream
41 | }
42 |
43 | let player1Name: String
44 | let player2Name: String
45 |
46 | init(dependency: LoggedInDependency, player1Name: String, player2Name: String) {
47 | self.player1Name = player1Name
48 | self.player2Name = player2Name
49 | super.init(dependency: dependency)
50 | }
51 | }
52 |
53 | // MARK: - Builder
54 |
55 | protocol LoggedInBuildable: Buildable {
56 | func build(withListener listener: LoggedInListener, player1Name: String, player2Name: String) -> (router: LoggedInRouting, actionableItem: LoggedInActionableItem)
57 | }
58 |
59 | final class LoggedInBuilder: Builder, LoggedInBuildable {
60 |
61 | override init(dependency: LoggedInDependency) {
62 | super.init(dependency: dependency)
63 | }
64 |
65 | func build(withListener listener: LoggedInListener, player1Name: String, player2Name: String) -> (router: LoggedInRouting, actionableItem: LoggedInActionableItem) {
66 | let component = LoggedInComponent(dependency: dependency,
67 | player1Name: player1Name,
68 | player2Name: player2Name)
69 | let interactor = LoggedInInteractor(games: component.games)
70 | interactor.listener = listener
71 |
72 | let offGameBuilder = OffGameBuilder(dependency: component)
73 | let router = LoggedInRouter(interactor: interactor,
74 | viewController: component.loggedInViewController,
75 | offGameBuilder: offGameBuilder)
76 | return (router, interactor)
77 | }
78 | }
79 |
--------------------------------------------------------------------------------
/Example/xcframework/TicTacToe/LoggedIn/LoggedInBuilder.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) 2017. Uber Technologies
3 | //
4 | // Licensed under the Apache License, Version 2.0 (the "License");
5 | // you may not use this file except in compliance with the License.
6 | // You may obtain a copy of the License at
7 | //
8 | // http://www.apache.org/licenses/LICENSE-2.0
9 | //
10 | // Unless required by applicable law or agreed to in writing, software
11 | // distributed under the License is distributed on an "AS IS" BASIS,
12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | // See the License for the specific language governing permissions and
14 | // limitations under the License.
15 | //
16 |
17 | import RIBs
18 |
19 | protocol LoggedInDependency: Dependency {
20 | var loggedInViewController: LoggedInViewControllable { get }
21 | }
22 |
23 | final class LoggedInComponent: Component {
24 |
25 | fileprivate var loggedInViewController: LoggedInViewControllable {
26 | return dependency.loggedInViewController
27 | }
28 |
29 | fileprivate var games: [Game] {
30 | return shared {
31 | return [RandomWinAdapter(dependency: self), TicTacToeAdapter(dependency: self)]
32 | }
33 | }
34 |
35 | var mutableScoreStream: MutableScoreStream {
36 | return shared { ScoreStreamImpl() }
37 | }
38 |
39 | var scoreStream: ScoreStream {
40 | return mutableScoreStream
41 | }
42 |
43 | let player1Name: String
44 | let player2Name: String
45 |
46 | init(dependency: LoggedInDependency, player1Name: String, player2Name: String) {
47 | self.player1Name = player1Name
48 | self.player2Name = player2Name
49 | super.init(dependency: dependency)
50 | }
51 | }
52 |
53 | // MARK: - Builder
54 |
55 | protocol LoggedInBuildable: Buildable {
56 | func build(withListener listener: LoggedInListener, player1Name: String, player2Name: String) -> (router: LoggedInRouting, actionableItem: LoggedInActionableItem)
57 | }
58 |
59 | final class LoggedInBuilder: Builder, LoggedInBuildable {
60 |
61 | override init(dependency: LoggedInDependency) {
62 | super.init(dependency: dependency)
63 | }
64 |
65 | func build(withListener listener: LoggedInListener, player1Name: String, player2Name: String) -> (router: LoggedInRouting, actionableItem: LoggedInActionableItem) {
66 | let component = LoggedInComponent(dependency: dependency,
67 | player1Name: player1Name,
68 | player2Name: player2Name)
69 | let interactor = LoggedInInteractor(games: component.games)
70 | interactor.listener = listener
71 |
72 | let offGameBuilder = OffGameBuilder(dependency: component)
73 | let router = LoggedInRouter(interactor: interactor,
74 | viewController: component.loggedInViewController,
75 | offGameBuilder: offGameBuilder)
76 | return (router, interactor)
77 | }
78 | }
79 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | 
2 | [](https://github.com/Carthage/Carthage)
3 | # RIBsTreeViewer
4 |
5 | 
6 |
7 | Real Time viewing attached RIBs Tree on Browser
8 |
9 | ## Demo
10 |
11 | 
12 |
13 | ## Using the Libraries
14 |
15 | ### XCFramework
16 |
17 | Add the xcframework to your project。
18 |
19 | ```
20 | ./Products/RIBsTreeViewerClient.xcframework
21 | ```
22 |
23 | ### CocoaPods
24 |
25 | This is not supported because the RIBs do not provide an up-to-date PodSpec, making it difficult to resolve dependencies.
26 |
27 | ### Carthage
28 |
29 | ```shell
30 | github "srea/RIBsTreeViewerClient"
31 | ```
32 |
33 | ```
34 | $ carthage update --platform iOS --no-use-binaries
35 | ```
36 |
37 | #### Build Phase
38 |
39 | 
40 | 
41 |
42 | Carthage CopyFrameworks (ONLY DEBUG)
43 |
44 | ```shell
45 | if [ ${CONFIGURATION%%-*} == "Debug" ]; then
46 | /usr/local/bin/carthage copy-frameworks
47 | fi
48 | ```
49 |
50 | ## Basic setup
51 |
52 | ```swift
53 | @UIApplicationMain
54 | public class AppDelegate: UIResponder, UIApplicationDelegate {
55 |
56 | private var ribsTreeViewer: RIBsTreeViewer? = nil
57 |
58 | public func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
59 | let window = UIWindow(frame: UIScreen.main.bounds)
60 | self.window = window
61 |
62 | let result = RootBuilder(dependency: AppComponent()).build()
63 | let launchRouter = result.launchRouter
64 | self.launchRouter = launchRouter
65 | urlHandler = result.urlHandler
66 | launchRouter.launch(from: window)
67 | startRIBsTreeViewer(launchRouter: launchRouter)
68 | return true
69 | }
70 | }
71 | ```
72 |
73 | ```swift
74 | // MARK: - RIBsTreeViewer
75 |
76 | #if DEBUG
77 | import RIBsTreeViewerClient
78 |
79 | extension AppDelegate {
80 | private func startRIBsTreeViewer(launchRouter: Routing) {
81 | if #available(iOS 13.0, *) {
82 | ribsTreeViewer = RIBsTreeViewerImpl.init(router: launchRouter,
83 | options: [.webSocketURL("ws://0.0.0.0:8080"),
84 | .monitoringIntervalMillis(1000)])
85 | ribsTreeViewer?.start()
86 | } else {
87 | // RIBsTreeViewer is not supported OS version.
88 | }
89 | }
90 | }
91 | #endif
92 | ```
93 |
94 | ### Installing
95 |
96 | ```
97 | $ npm install yarn
98 | ```
99 |
100 | ### Starting the websocke server
101 |
102 | ```shell
103 | $ npx yarn install
104 | $ node index.js
105 | ```
106 |
107 | ## Open the page.
108 |
109 | ```shell
110 | $ npx yarn install
111 | $ npx webpack
112 | $ open ./public/index.html
113 | ```
--------------------------------------------------------------------------------
/Example/xcframework/TicTacToe/Root/RootInteractor.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) 2017. Uber Technologies
3 | //
4 | // Licensed under the Apache License, Version 2.0 (the "License");
5 | // you may not use this file except in compliance with the License.
6 | // You may obtain a copy of the License at
7 | //
8 | // http://www.apache.org/licenses/LICENSE-2.0
9 | //
10 | // Unless required by applicable law or agreed to in writing, software
11 | // distributed under the License is distributed on an "AS IS" BASIS,
12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | // See the License for the specific language governing permissions and
14 | // limitations under the License.
15 | //
16 |
17 | import RIBs
18 | import RxSwift
19 |
20 | protocol RootRouting: ViewableRouting {
21 | func routeToLoggedIn(withPlayer1Name player1Name: String, player2Name: String) -> LoggedInActionableItem
22 | }
23 |
24 | protocol RootPresentable: Presentable {
25 | var listener: RootPresentableListener? { get set }
26 | // TODO: Declare methods the interactor can invoke the presenter to present data.
27 | }
28 |
29 | protocol RootListener: class {
30 | // TODO: Declare methods the interactor can invoke to communicate with other RIBs.
31 | }
32 |
33 | final class RootInteractor: PresentableInteractor, RootInteractable, RootPresentableListener, RootActionableItem, UrlHandler {
34 |
35 | weak var router: RootRouting?
36 |
37 | weak var listener: RootListener?
38 |
39 | // TODO: Add additional dependencies to constructor. Do not perform any logic
40 | // in constructor.
41 | override init(presenter: RootPresentable) {
42 | super.init(presenter: presenter)
43 | presenter.listener = self
44 | }
45 |
46 | override func didBecomeActive() {
47 | super.didBecomeActive()
48 | // TODO: Implement business logic here.
49 | }
50 |
51 | override func willResignActive() {
52 | super.willResignActive()
53 | // TODO: Pause any business logic.
54 | }
55 |
56 | // MARK: - LoggedOutListener
57 |
58 | func didLogin(withPlayer1Name player1Name: String, player2Name: String) {
59 | let loggedInActionableItem = router?.routeToLoggedIn(withPlayer1Name: player1Name, player2Name: player2Name)
60 | if let loggedInActionableItem = loggedInActionableItem {
61 | loggedInActionableItemSubject.onNext(loggedInActionableItem)
62 | }
63 | }
64 |
65 | // MARK: - UrlHandler
66 |
67 | func handle(_ url: URL) {
68 | let launchGameWorkflow = LaunchGameWorkflow(url: url)
69 | launchGameWorkflow
70 | .subscribe(self)
71 | .disposeOnDeactivate(interactor: self)
72 | }
73 |
74 | // MARK: - RootActionableItem
75 |
76 | func waitForLogin() -> Observable<(LoggedInActionableItem, ())> {
77 | return loggedInActionableItemSubject
78 | .map { (loggedInItem: LoggedInActionableItem) -> (LoggedInActionableItem, ()) in
79 | (loggedInItem, ())
80 | }
81 | }
82 |
83 | // MARK: - Private
84 |
85 | private let loggedInActionableItemSubject = ReplaySubject.create(bufferSize: 1)
86 | }
87 |
--------------------------------------------------------------------------------
/Example/swiftpm/TicTacToe/Root/RootInteractor.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) 2017. Uber Technologies
3 | //
4 | // Licensed under the Apache License, Version 2.0 (the "License");
5 | // you may not use this file except in compliance with the License.
6 | // You may obtain a copy of the License at
7 | //
8 | // http://www.apache.org/licenses/LICENSE-2.0
9 | //
10 | // Unless required by applicable law or agreed to in writing, software
11 | // distributed under the License is distributed on an "AS IS" BASIS,
12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | // See the License for the specific language governing permissions and
14 | // limitations under the License.
15 | //
16 |
17 | import Foundation
18 | import RIBs
19 | import RxSwift
20 |
21 | protocol RootRouting: ViewableRouting {
22 | func routeToLoggedIn(withPlayer1Name player1Name: String, player2Name: String) -> LoggedInActionableItem
23 | }
24 |
25 | protocol RootPresentable: Presentable {
26 | var listener: RootPresentableListener? { get set }
27 | // TODO: Declare methods the interactor can invoke the presenter to present data.
28 | }
29 |
30 | protocol RootListener: class {
31 | // TODO: Declare methods the interactor can invoke to communicate with other RIBs.
32 | }
33 |
34 | final class RootInteractor: PresentableInteractor, RootInteractable, RootPresentableListener, RootActionableItem, UrlHandler {
35 |
36 | weak var router: RootRouting?
37 |
38 | weak var listener: RootListener?
39 |
40 | // TODO: Add additional dependencies to constructor. Do not perform any logic
41 | // in constructor.
42 | override init(presenter: RootPresentable) {
43 | super.init(presenter: presenter)
44 | presenter.listener = self
45 | }
46 |
47 | override func didBecomeActive() {
48 | super.didBecomeActive()
49 | // TODO: Implement business logic here.
50 | }
51 |
52 | override func willResignActive() {
53 | super.willResignActive()
54 | // TODO: Pause any business logic.
55 | }
56 |
57 | // MARK: - LoggedOutListener
58 |
59 | func didLogin(withPlayer1Name player1Name: String, player2Name: String) {
60 | let loggedInActionableItem = router?.routeToLoggedIn(withPlayer1Name: player1Name, player2Name: player2Name)
61 | if let loggedInActionableItem = loggedInActionableItem {
62 | loggedInActionableItemSubject.onNext(loggedInActionableItem)
63 | }
64 | }
65 |
66 | // MARK: - UrlHandler
67 |
68 | func handle(_ url: URL) {
69 | let launchGameWorkflow = LaunchGameWorkflow(url: url)
70 | launchGameWorkflow
71 | .subscribe(self)
72 | .disposeOnDeactivate(interactor: self)
73 | }
74 |
75 | // MARK: - RootActionableItem
76 |
77 | func waitForLogin() -> Observable<(LoggedInActionableItem, ())> {
78 | return loggedInActionableItemSubject
79 | .map { (loggedInItem: LoggedInActionableItem) -> (LoggedInActionableItem, ()) in
80 | (loggedInItem, ())
81 | }
82 | }
83 |
84 | // MARK: - Private
85 |
86 | private let loggedInActionableItemSubject = ReplaySubject.create(bufferSize: 1)
87 | }
88 |
--------------------------------------------------------------------------------
/Example/swiftpm/TicTacToe/RandomWin/RandomWinViewController.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) 2017. Uber Technologies
3 | //
4 | // Licensed under the Apache License, Version 2.0 (the "License");
5 | // you may not use this file except in compliance with the License.
6 | // You may obtain a copy of the License at
7 | //
8 | // http://www.apache.org/licenses/LICENSE-2.0
9 | //
10 | // Unless required by applicable law or agreed to in writing, software
11 | // distributed under the License is distributed on an "AS IS" BASIS,
12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | // See the License for the specific language governing permissions and
14 | // limitations under the License.
15 | //
16 |
17 | import RIBs
18 | import RxCocoa
19 | import RxSwift
20 | import SnapKit
21 | import UIKit
22 |
23 | protocol RandomWinPresentableListener: class {
24 | func determineWinner()
25 | }
26 |
27 | final class RandomWinViewController: UIViewController, RandomWinPresentable, RandomWinViewControllable {
28 |
29 | weak var listener: RandomWinPresentableListener?
30 |
31 | init(player1Name: String,
32 | player2Name: String) {
33 | self.player1Name = player1Name
34 | self.player2Name = player2Name
35 | super.init(nibName: nil, bundle: nil)
36 | }
37 |
38 | required init?(coder aDecoder: NSCoder) {
39 | fatalError("Method is not supported")
40 | }
41 |
42 | override func viewDidLoad() {
43 | super.viewDidLoad()
44 |
45 | view.backgroundColor = UIColor.cyan
46 | buildGoButton()
47 | }
48 |
49 | // MARK: - RandomWinPresentable
50 |
51 | func announce(winner: PlayerType, withCompletionHandler handler: @escaping () -> ()) {
52 | let winnerString: String = {
53 | switch winner {
54 | case .player1:
55 | return "\(player1Name) Won!"
56 | case .player2:
57 | return "\(player2Name) Won!"
58 | }
59 | }()
60 | let alert = UIAlertController(title: winnerString, message: nil, preferredStyle: .alert)
61 | let closeAction = UIAlertAction(title: "That was random...", style: UIAlertActionStyle.default) { _ in
62 | handler()
63 | }
64 | alert.addAction(closeAction)
65 | present(alert, animated: true, completion: nil)
66 | }
67 |
68 | // MARK: - Private
69 |
70 | private let player1Name: String
71 | private let player2Name: String
72 |
73 | private func buildGoButton() {
74 | let button = UIButton()
75 | button.setTitle("Magic", for: .normal)
76 | button.backgroundColor = UIColor.purple
77 | button.setTitleColor(UIColor.white, for: .normal)
78 | view.addSubview(button)
79 | button.snp.makeConstraints { (maker: ConstraintMaker) in
80 | maker.center.equalTo(self.view.snp.center)
81 | maker.leading.trailing.equalTo(self.view).inset(20)
82 | maker.height.equalTo(100)
83 | }
84 |
85 | button.rx.tap
86 | .subscribe(onNext: { [weak self] in
87 | self?.listener?.determineWinner()
88 | })
89 | .disposed(by: disposeBag)
90 | }
91 |
92 | private let disposeBag = DisposeBag()
93 | }
94 |
--------------------------------------------------------------------------------
/Example/xcframework/TicTacToe/RandomWin/RandomWinViewController.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) 2017. Uber Technologies
3 | //
4 | // Licensed under the Apache License, Version 2.0 (the "License");
5 | // you may not use this file except in compliance with the License.
6 | // You may obtain a copy of the License at
7 | //
8 | // http://www.apache.org/licenses/LICENSE-2.0
9 | //
10 | // Unless required by applicable law or agreed to in writing, software
11 | // distributed under the License is distributed on an "AS IS" BASIS,
12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | // See the License for the specific language governing permissions and
14 | // limitations under the License.
15 | //
16 |
17 | import RIBs
18 | import RxCocoa
19 | import RxSwift
20 | import SnapKit
21 | import UIKit
22 |
23 | protocol RandomWinPresentableListener: class {
24 | func determineWinner()
25 | }
26 |
27 | final class RandomWinViewController: UIViewController, RandomWinPresentable, RandomWinViewControllable {
28 |
29 | weak var listener: RandomWinPresentableListener?
30 |
31 | init(player1Name: String,
32 | player2Name: String) {
33 | self.player1Name = player1Name
34 | self.player2Name = player2Name
35 | super.init(nibName: nil, bundle: nil)
36 | }
37 |
38 | required init?(coder aDecoder: NSCoder) {
39 | fatalError("Method is not supported")
40 | }
41 |
42 | override func viewDidLoad() {
43 | super.viewDidLoad()
44 |
45 | view.backgroundColor = UIColor.cyan
46 | buildGoButton()
47 | }
48 |
49 | // MARK: - RandomWinPresentable
50 |
51 | func announce(winner: PlayerType, withCompletionHandler handler: @escaping () -> ()) {
52 | let winnerString: String = {
53 | switch winner {
54 | case .player1:
55 | return "\(player1Name) Won!"
56 | case .player2:
57 | return "\(player2Name) Won!"
58 | }
59 | }()
60 | let alert = UIAlertController(title: winnerString, message: nil, preferredStyle: .alert)
61 | let closeAction = UIAlertAction(title: "That was random...", style: UIAlertActionStyle.default) { _ in
62 | handler()
63 | }
64 | alert.addAction(closeAction)
65 | present(alert, animated: true, completion: nil)
66 | }
67 |
68 | // MARK: - Private
69 |
70 | private let player1Name: String
71 | private let player2Name: String
72 |
73 | private func buildGoButton() {
74 | let button = UIButton()
75 | button.setTitle("Magic", for: .normal)
76 | button.backgroundColor = UIColor.purple
77 | button.setTitleColor(UIColor.white, for: .normal)
78 | view.addSubview(button)
79 | button.snp.makeConstraints { (maker: ConstraintMaker) in
80 | maker.center.equalTo(self.view.snp.center)
81 | maker.leading.trailing.equalTo(self.view).inset(20)
82 | maker.height.equalTo(100)
83 | }
84 |
85 | button.rx.tap
86 | .subscribe(onNext: { [weak self] in
87 | self?.listener?.determineWinner()
88 | })
89 | .disposed(by: disposeBag)
90 | }
91 |
92 | private let disposeBag = DisposeBag()
93 | }
94 |
--------------------------------------------------------------------------------
/RIBsTreeViewerClient.xcodeproj/xcshareddata/xcschemes/RIBsTreeViewerClient.xcscheme:
--------------------------------------------------------------------------------
1 |
2 |
5 |
8 |
9 |
15 |
21 |
22 |
23 |
24 |
25 |
30 |
31 |
32 |
33 |
34 |
35 |
45 |
46 |
52 |
53 |
54 |
55 |
56 |
57 |
63 |
64 |
70 |
71 |
72 |
73 |
75 |
76 |
79 |
80 |
81 |
--------------------------------------------------------------------------------
/Example/swiftpm/TicTacToe/AppStart/AppDelegate.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) 2017. Uber Technologies
3 | //
4 | // Licensed under the Apache License, Version 2.0 (the "License");
5 | // you may not use this file except in compliance with the License.
6 | // You may obtain a copy of the License at
7 | //
8 | // http://www.apache.org/licenses/LICENSE-2.0
9 | //
10 | // Unless required by applicable law or agreed to in writing, software
11 | // distributed under the License is distributed on an "AS IS" BASIS,
12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | // See the License for the specific language governing permissions and
14 | // limitations under the License.
15 | //
16 |
17 | import RIBs
18 | import RxSwift
19 | import UIKit
20 |
21 | /// Game app delegate.
22 | @UIApplicationMain
23 | public class AppDelegate: UIResponder, UIApplicationDelegate {
24 |
25 | /// The window.
26 | public var window: UIWindow?
27 |
28 | private var ribsTreeViewer: RIBsTreeViewer? = nil
29 |
30 | /// Tells the delegate that the launch process is almost done and the app is almost ready to run.
31 | ///
32 | /// - parameter application: Your singleton app object.
33 | /// - parameter launchOptions: A dictionary indicating the reason the app was launched (if any). The contents of
34 | /// this dictionary may be empty in situations where the user launched the app directly. For information about
35 | /// the possible keys in this dictionary and how to handle them, see Launch Options Keys.
36 | /// - returns: false if the app cannot handle the URL resource or continue a user activity, otherwise return true.
37 | public func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
38 | let window = UIWindow(frame: UIScreen.main.bounds)
39 | self.window = window
40 |
41 | let result = RootBuilder(dependency: AppComponent()).build()
42 | let launchRouter = result.launchRouter
43 | self.launchRouter = launchRouter
44 | urlHandler = result.urlHandler
45 | launchRouter.launch(from: window)
46 | startRIBsTreeViewer(launchRouter: launchRouter)
47 | return true
48 | }
49 |
50 | public func application(_ application: UIApplication, open url: URL, sourceApplication: String?, annotation: Any) -> Bool {
51 | urlHandler?.handle(url)
52 | return true
53 | }
54 |
55 | // MARK: - Private
56 |
57 | private var launchRouter: LaunchRouting?
58 | private var urlHandler: UrlHandler?
59 | }
60 |
61 | protocol UrlHandler: class {
62 | func handle(_ url: URL)
63 | }
64 |
65 |
66 | // MARK: - RIBsTreeViewer
67 |
68 | #if DEBUG
69 | import RIBsTreeViewerClient
70 |
71 | extension AppDelegate {
72 | private func startRIBsTreeViewer(launchRouter: Routing) {
73 | if #available(iOS 13.0, *) {
74 | ribsTreeViewer = RIBsTreeViewerImpl.init(router: launchRouter,
75 | options: [.webSocketURL("ws://0.0.0.0:8080"),
76 | .monitoringIntervalMillis(1000)])
77 | ribsTreeViewer?.start()
78 | } else {
79 | // RIBsTreeViewer is not supported OS version.
80 | }
81 | }
82 | }
83 | #endif
84 |
--------------------------------------------------------------------------------
/Example/xcframework/TicTacToe/AppStart/AppDelegate.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) 2017. Uber Technologies
3 | //
4 | // Licensed under the Apache License, Version 2.0 (the "License");
5 | // you may not use this file except in compliance with the License.
6 | // You may obtain a copy of the License at
7 | //
8 | // http://www.apache.org/licenses/LICENSE-2.0
9 | //
10 | // Unless required by applicable law or agreed to in writing, software
11 | // distributed under the License is distributed on an "AS IS" BASIS,
12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | // See the License for the specific language governing permissions and
14 | // limitations under the License.
15 | //
16 |
17 | import RIBs
18 | import RxSwift
19 | import UIKit
20 |
21 | /// Game app delegate.
22 | @UIApplicationMain
23 | public class AppDelegate: UIResponder, UIApplicationDelegate {
24 |
25 | /// The window.
26 | public var window: UIWindow?
27 |
28 | private var ribsTreeViewer: RIBsTreeViewer? = nil
29 |
30 | /// Tells the delegate that the launch process is almost done and the app is almost ready to run.
31 | ///
32 | /// - parameter application: Your singleton app object.
33 | /// - parameter launchOptions: A dictionary indicating the reason the app was launched (if any). The contents of
34 | /// this dictionary may be empty in situations where the user launched the app directly. For information about
35 | /// the possible keys in this dictionary and how to handle them, see Launch Options Keys.
36 | /// - returns: false if the app cannot handle the URL resource or continue a user activity, otherwise return true.
37 | public func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
38 | let window = UIWindow(frame: UIScreen.main.bounds)
39 | self.window = window
40 |
41 | let result = RootBuilder(dependency: AppComponent()).build()
42 | let launchRouter = result.launchRouter
43 | self.launchRouter = launchRouter
44 | urlHandler = result.urlHandler
45 | launchRouter.launch(from: window)
46 | startRIBsTreeViewer(launchRouter: launchRouter)
47 | return true
48 | }
49 |
50 | public func application(_ application: UIApplication, open url: URL, sourceApplication: String?, annotation: Any) -> Bool {
51 | urlHandler?.handle(url)
52 | return true
53 | }
54 |
55 | // MARK: - Private
56 |
57 | private var launchRouter: LaunchRouting?
58 | private var urlHandler: UrlHandler?
59 | }
60 |
61 | protocol UrlHandler: class {
62 | func handle(_ url: URL)
63 | }
64 |
65 |
66 | // MARK: - RIBsTreeViewer
67 |
68 | #if DEBUG
69 | import RIBsTreeViewerClient
70 |
71 | extension AppDelegate {
72 | private func startRIBsTreeViewer(launchRouter: Routing) {
73 | if #available(iOS 13.0, *) {
74 | ribsTreeViewer = RIBsTreeViewerImpl.init(router: launchRouter,
75 | options: [.webSocketURL("ws://0.0.0.0:8080"),
76 | .monitoringIntervalMillis(1000)])
77 | ribsTreeViewer?.start()
78 | } else {
79 | // RIBsTreeViewer is not supported OS version.
80 | }
81 | }
82 | }
83 | #endif
84 |
--------------------------------------------------------------------------------
/Example/swiftpm/TicTacToe/OffGame/OffGameViewController.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) 2017. Uber Technologies
3 | //
4 | // Licensed under the Apache License, Version 2.0 (the "License");
5 | // you may not use this file except in compliance with the License.
6 | // You may obtain a copy of the License at
7 | //
8 | // http://www.apache.org/licenses/LICENSE-2.0
9 | //
10 | // Unless required by applicable law or agreed to in writing, software
11 | // distributed under the License is distributed on an "AS IS" BASIS,
12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | // See the License for the specific language governing permissions and
14 | // limitations under the License.
15 | //
16 |
17 | import RIBs
18 | import RxCocoa
19 | import RxSwift
20 | import SnapKit
21 | import UIKit
22 |
23 | protocol OffGamePresentableListener: class {
24 | func start(_ game: Game)
25 | }
26 |
27 | final class OffGameViewController: UIViewController, OffGamePresentable, OffGameViewControllable {
28 |
29 | weak var listener: OffGamePresentableListener?
30 |
31 | init(games: [Game]) {
32 | self.games = games
33 | super.init(nibName: nil, bundle: nil)
34 | }
35 |
36 | required init?(coder aDecoder: NSCoder) {
37 | fatalError("Method is not supported")
38 | }
39 |
40 | override func viewDidLoad() {
41 | super.viewDidLoad()
42 |
43 | view.backgroundColor = UIColor.yellow
44 | buildStartButtons()
45 | }
46 |
47 | func show(scoreBoardView: ViewControllable) {
48 | addChildViewController(scoreBoardView.uiviewController)
49 | view.addSubview(scoreBoardView.uiviewController.view)
50 | scoreBoardView.uiviewController.view.snp.makeConstraints { (maker: ConstraintMaker) in
51 | maker.top.equalTo(self.view).offset(70)
52 | maker.leading.trailing.equalTo(self.view).inset(20)
53 | maker.height.equalTo(120)
54 | }
55 | }
56 |
57 | // MARK: - Private
58 |
59 | private let games: [Game]
60 |
61 | private func buildStartButtons() {
62 | var previousButton: UIView?
63 | for game in games {
64 | previousButton = buildStartButton(with: game, previousButton: previousButton)
65 | }
66 | }
67 |
68 | private func buildStartButton(with game: Game, previousButton: UIView?) -> UIButton {
69 | let startButton = UIButton()
70 | view.addSubview(startButton)
71 | startButton.accessibilityIdentifier = game.name
72 | startButton.snp.makeConstraints { (maker: ConstraintMaker) in
73 | if let previousButton = previousButton {
74 | maker.bottom.equalTo(previousButton.snp.top).offset(-20)
75 | } else {
76 | maker.bottom.equalTo(self.view.snp.bottom).inset(30)
77 | }
78 | maker.leading.trailing.equalTo(self.view).inset(40)
79 | maker.height.equalTo(50)
80 | }
81 | startButton.setTitle(game.name, for: .normal)
82 | startButton.setTitleColor(UIColor.white, for: .normal)
83 | startButton.backgroundColor = UIColor.black
84 | startButton.rx.tap
85 | .subscribe(onNext: { [weak self] in
86 | self?.listener?.start(game)
87 | })
88 | .disposed(by: disposeBag)
89 |
90 | return startButton
91 | }
92 |
93 | private let disposeBag = DisposeBag()
94 | }
95 |
--------------------------------------------------------------------------------
/Example/xcframework/TicTacToe/OffGame/OffGameViewController.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) 2017. Uber Technologies
3 | //
4 | // Licensed under the Apache License, Version 2.0 (the "License");
5 | // you may not use this file except in compliance with the License.
6 | // You may obtain a copy of the License at
7 | //
8 | // http://www.apache.org/licenses/LICENSE-2.0
9 | //
10 | // Unless required by applicable law or agreed to in writing, software
11 | // distributed under the License is distributed on an "AS IS" BASIS,
12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | // See the License for the specific language governing permissions and
14 | // limitations under the License.
15 | //
16 |
17 | import RIBs
18 | import RxCocoa
19 | import RxSwift
20 | import SnapKit
21 | import UIKit
22 |
23 | protocol OffGamePresentableListener: class {
24 | func start(_ game: Game)
25 | }
26 |
27 | final class OffGameViewController: UIViewController, OffGamePresentable, OffGameViewControllable {
28 |
29 | weak var listener: OffGamePresentableListener?
30 |
31 | init(games: [Game]) {
32 | self.games = games
33 | super.init(nibName: nil, bundle: nil)
34 | }
35 |
36 | required init?(coder aDecoder: NSCoder) {
37 | fatalError("Method is not supported")
38 | }
39 |
40 | override func viewDidLoad() {
41 | super.viewDidLoad()
42 |
43 | view.backgroundColor = UIColor.yellow
44 | buildStartButtons()
45 | }
46 |
47 | func show(scoreBoardView: ViewControllable) {
48 | addChildViewController(scoreBoardView.uiviewController)
49 | view.addSubview(scoreBoardView.uiviewController.view)
50 | scoreBoardView.uiviewController.view.snp.makeConstraints { (maker: ConstraintMaker) in
51 | maker.top.equalTo(self.view).offset(70)
52 | maker.leading.trailing.equalTo(self.view).inset(20)
53 | maker.height.equalTo(120)
54 | }
55 | }
56 |
57 | // MARK: - Private
58 |
59 | private let games: [Game]
60 |
61 | private func buildStartButtons() {
62 | var previousButton: UIView?
63 | for game in games {
64 | previousButton = buildStartButton(with: game, previousButton: previousButton)
65 | }
66 | }
67 |
68 | private func buildStartButton(with game: Game, previousButton: UIView?) -> UIButton {
69 | let startButton = UIButton()
70 | view.addSubview(startButton)
71 | startButton.accessibilityIdentifier = game.name
72 | startButton.snp.makeConstraints { (maker: ConstraintMaker) in
73 | if let previousButton = previousButton {
74 | maker.bottom.equalTo(previousButton.snp.top).offset(-20)
75 | } else {
76 | maker.bottom.equalTo(self.view.snp.bottom).inset(30)
77 | }
78 | maker.leading.trailing.equalTo(self.view).inset(40)
79 | maker.height.equalTo(50)
80 | }
81 | startButton.setTitle(game.name, for: .normal)
82 | startButton.setTitleColor(UIColor.white, for: .normal)
83 | startButton.backgroundColor = UIColor.black
84 | startButton.rx.tap
85 | .subscribe(onNext: { [weak self] in
86 | self?.listener?.start(game)
87 | })
88 | .disposed(by: disposeBag)
89 |
90 | return startButton
91 | }
92 |
93 | private let disposeBag = DisposeBag()
94 | }
95 |
--------------------------------------------------------------------------------
/Example/swiftpm/TicTacToe/LoggedOut/LoggedOutViewController.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) 2017. Uber Technologies
3 | //
4 | // Licensed under the Apache License, Version 2.0 (the "License");
5 | // you may not use this file except in compliance with the License.
6 | // You may obtain a copy of the License at
7 | //
8 | // http://www.apache.org/licenses/LICENSE-2.0
9 | //
10 | // Unless required by applicable law or agreed to in writing, software
11 | // distributed under the License is distributed on an "AS IS" BASIS,
12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | // See the License for the specific language governing permissions and
14 | // limitations under the License.
15 | //
16 |
17 | import RIBs
18 | import RxCocoa
19 | import RxSwift
20 | import SnapKit
21 | import UIKit
22 |
23 | protocol LoggedOutPresentableListener: class {
24 | func login(withPlayer1Name: String?, player2Name: String?)
25 | }
26 |
27 | final class LoggedOutViewController: UIViewController, LoggedOutPresentable, LoggedOutViewControllable {
28 |
29 | weak var listener: LoggedOutPresentableListener?
30 |
31 | init() {
32 | super.init(nibName: nil, bundle: nil)
33 | }
34 |
35 | required init?(coder aDecoder: NSCoder) {
36 | fatalError("Method is not supported")
37 | }
38 |
39 | override func viewDidLoad() {
40 | super.viewDidLoad()
41 |
42 | view.backgroundColor = UIColor.white
43 | let playerFields = buildPlayerFields()
44 | buildLoginButton(withPlayer1Field: playerFields.player1Field, player2Field: playerFields.player2Field)
45 | }
46 |
47 | // MARK: - Private
48 |
49 | private func buildPlayerFields() -> (player1Field: UITextField, player2Field: UITextField) {
50 | let player1Field = UITextField()
51 | player1Field.borderStyle = UITextBorderStyle.line
52 | view.addSubview(player1Field)
53 | player1Field.placeholder = "Player 1 name"
54 | player1Field.snp.makeConstraints { (maker: ConstraintMaker) in
55 | maker.top.equalTo(self.view).offset(100)
56 | maker.leading.trailing.equalTo(self.view).inset(40)
57 | maker.height.equalTo(40)
58 | }
59 |
60 | let player2Field = UITextField()
61 | player2Field.borderStyle = UITextBorderStyle.line
62 | view.addSubview(player2Field)
63 | player2Field.placeholder = "Player 2 name"
64 | player2Field.snp.makeConstraints { (maker: ConstraintMaker) in
65 | maker.top.equalTo(player1Field.snp.bottom).offset(20)
66 | maker.left.right.height.equalTo(player1Field)
67 | }
68 |
69 | return (player1Field, player2Field)
70 | }
71 |
72 | private func buildLoginButton(withPlayer1Field player1Field: UITextField, player2Field: UITextField) {
73 | let loginButton = UIButton()
74 | view.addSubview(loginButton)
75 | loginButton.snp.makeConstraints { (maker: ConstraintMaker) in
76 | maker.top.equalTo(player2Field.snp.bottom).offset(20)
77 | maker.left.right.height.equalTo(player1Field)
78 | }
79 | loginButton.setTitle("Login", for: .normal)
80 | loginButton.setTitleColor(UIColor.white, for: .normal)
81 | loginButton.backgroundColor = UIColor.black
82 | loginButton.rx.tap
83 | .subscribe(onNext: { [weak self] in
84 | self?.listener?.login(withPlayer1Name: player1Field.text, player2Name: player2Field.text)
85 | })
86 | .disposed(by: disposeBag)
87 | }
88 |
89 | private let disposeBag = DisposeBag()
90 | }
91 |
--------------------------------------------------------------------------------
/Example/xcframework/TicTacToe/LoggedOut/LoggedOutViewController.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) 2017. Uber Technologies
3 | //
4 | // Licensed under the Apache License, Version 2.0 (the "License");
5 | // you may not use this file except in compliance with the License.
6 | // You may obtain a copy of the License at
7 | //
8 | // http://www.apache.org/licenses/LICENSE-2.0
9 | //
10 | // Unless required by applicable law or agreed to in writing, software
11 | // distributed under the License is distributed on an "AS IS" BASIS,
12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | // See the License for the specific language governing permissions and
14 | // limitations under the License.
15 | //
16 |
17 | import RIBs
18 | import RxCocoa
19 | import RxSwift
20 | import SnapKit
21 | import UIKit
22 |
23 | protocol LoggedOutPresentableListener: class {
24 | func login(withPlayer1Name: String?, player2Name: String?)
25 | }
26 |
27 | final class LoggedOutViewController: UIViewController, LoggedOutPresentable, LoggedOutViewControllable {
28 |
29 | weak var listener: LoggedOutPresentableListener?
30 |
31 | init() {
32 | super.init(nibName: nil, bundle: nil)
33 | }
34 |
35 | required init?(coder aDecoder: NSCoder) {
36 | fatalError("Method is not supported")
37 | }
38 |
39 | override func viewDidLoad() {
40 | super.viewDidLoad()
41 |
42 | view.backgroundColor = UIColor.white
43 | let playerFields = buildPlayerFields()
44 | buildLoginButton(withPlayer1Field: playerFields.player1Field, player2Field: playerFields.player2Field)
45 | }
46 |
47 | // MARK: - Private
48 |
49 | private func buildPlayerFields() -> (player1Field: UITextField, player2Field: UITextField) {
50 | let player1Field = UITextField()
51 | player1Field.borderStyle = UITextBorderStyle.line
52 | view.addSubview(player1Field)
53 | player1Field.placeholder = "Player 1 name"
54 | player1Field.snp.makeConstraints { (maker: ConstraintMaker) in
55 | maker.top.equalTo(self.view).offset(100)
56 | maker.leading.trailing.equalTo(self.view).inset(40)
57 | maker.height.equalTo(40)
58 | }
59 |
60 | let player2Field = UITextField()
61 | player2Field.borderStyle = UITextBorderStyle.line
62 | view.addSubview(player2Field)
63 | player2Field.placeholder = "Player 2 name"
64 | player2Field.snp.makeConstraints { (maker: ConstraintMaker) in
65 | maker.top.equalTo(player1Field.snp.bottom).offset(20)
66 | maker.left.right.height.equalTo(player1Field)
67 | }
68 |
69 | return (player1Field, player2Field)
70 | }
71 |
72 | private func buildLoginButton(withPlayer1Field player1Field: UITextField, player2Field: UITextField) {
73 | let loginButton = UIButton()
74 | view.addSubview(loginButton)
75 | loginButton.snp.makeConstraints { (maker: ConstraintMaker) in
76 | maker.top.equalTo(player2Field.snp.bottom).offset(20)
77 | maker.left.right.height.equalTo(player1Field)
78 | }
79 | loginButton.setTitle("Login", for: .normal)
80 | loginButton.setTitleColor(UIColor.white, for: .normal)
81 | loginButton.backgroundColor = UIColor.black
82 | loginButton.rx.tap
83 | .subscribe(onNext: { [weak self] in
84 | self?.listener?.login(withPlayer1Name: player1Field.text, player2Name: player2Field.text)
85 | })
86 | .disposed(by: disposeBag)
87 | }
88 |
89 | private let disposeBag = DisposeBag()
90 | }
91 |
--------------------------------------------------------------------------------
/Example/swiftpm/TicTacToe/ScoreBoard/BasicScoreBoardViewController.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) 2017. Uber Technologies
3 | //
4 | // Licensed under the Apache License, Version 2.0 (the "License");
5 | // you may not use this file except in compliance with the License.
6 | // You may obtain a copy of the License at
7 | //
8 | // http://www.apache.org/licenses/LICENSE-2.0
9 | //
10 | // Unless required by applicable law or agreed to in writing, software
11 | // distributed under the License is distributed on an "AS IS" BASIS,
12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | // See the License for the specific language governing permissions and
14 | // limitations under the License.
15 | //
16 |
17 | import RIBs
18 | import SnapKit
19 | import UIKit
20 |
21 | protocol BasicScoreBoardPresentableListener: class {
22 | // TODO: Declare properties and methods that the view controller can invoke to perform
23 | // business logic, such as signIn(). This protocol is implemented by the corresponding
24 | // interactor class.
25 | }
26 |
27 | final class BasicScoreBoardViewController: UIViewController, BasicScoreBoardPresentable, BasicScoreBoardViewControllable {
28 |
29 | weak var listener: BasicScoreBoardPresentableListener?
30 |
31 | init(player1Name: String,
32 | player2Name: String) {
33 | self.player1Name = player1Name
34 | self.player2Name = player2Name
35 | super.init(nibName: nil, bundle: nil)
36 | }
37 |
38 | required init?(coder aDecoder: NSCoder) {
39 | fatalError("Method is not supported")
40 | }
41 |
42 | override func viewDidLoad() {
43 | super.viewDidLoad()
44 |
45 | view.backgroundColor = UIColor.clear
46 | buildPlayerLabels()
47 | }
48 |
49 | // MARK: - OffGamePresentable
50 |
51 | func set(score: Score) {
52 | self.score = score
53 | }
54 |
55 | // MARK: - Private
56 |
57 | private let player1Name: String
58 | private let player2Name: String
59 |
60 | private var score: Score?
61 |
62 | private var player1Label: UILabel?
63 | private var player2Label: UILabel?
64 |
65 | private func buildPlayerLabels() {
66 | let labelBuilder: (UIColor) -> UILabel = { (color: UIColor) in
67 | let label = UILabel()
68 | label.font = UIFont.boldSystemFont(ofSize: 35)
69 | label.backgroundColor = UIColor.clear
70 | label.textColor = color
71 | label.textAlignment = .center
72 | return label
73 | }
74 |
75 | let player1Label = labelBuilder(PlayerType.player1.color)
76 | self.player1Label = player1Label
77 | view.addSubview(player1Label)
78 | player1Label.snp.makeConstraints { (maker: ConstraintMaker) in
79 | maker.top.leading.trailing.equalTo(self.view)
80 | maker.height.equalTo(40)
81 | }
82 |
83 | let vsLabel = UILabel()
84 | vsLabel.font = UIFont.systemFont(ofSize: 25)
85 | vsLabel.backgroundColor = UIColor.clear
86 | vsLabel.textColor = UIColor.darkGray
87 | vsLabel.textAlignment = .center
88 | vsLabel.text = "vs"
89 | view.addSubview(vsLabel)
90 | vsLabel.snp.makeConstraints { (maker: ConstraintMaker) in
91 | maker.top.equalTo(player1Label.snp.bottom).offset(10)
92 | maker.leading.trailing.equalTo(player1Label)
93 | maker.height.equalTo(20)
94 | }
95 |
96 | let player2Label = labelBuilder(PlayerType.player2.color)
97 | self.player2Label = player2Label
98 | view.addSubview(player2Label)
99 | player2Label.snp.makeConstraints { (maker: ConstraintMaker) in
100 | maker.top.equalTo(vsLabel.snp.bottom).offset(10)
101 | maker.height.leading.trailing.equalTo(player1Label)
102 | }
103 |
104 | updatePlayerLabels()
105 | }
106 |
107 | private func updatePlayerLabels() {
108 | let player1Score = score?.player1Score ?? 0
109 | player1Label?.text = "\(player1Name) (\(player1Score))"
110 |
111 | let player2Score = score?.player2Score ?? 0
112 | player2Label?.text = "\(player2Name) (\(player2Score))"
113 | }
114 | }
115 |
--------------------------------------------------------------------------------
/Example/xcframework/TicTacToe/ScoreBoard/BasicScoreBoardViewController.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) 2017. Uber Technologies
3 | //
4 | // Licensed under the Apache License, Version 2.0 (the "License");
5 | // you may not use this file except in compliance with the License.
6 | // You may obtain a copy of the License at
7 | //
8 | // http://www.apache.org/licenses/LICENSE-2.0
9 | //
10 | // Unless required by applicable law or agreed to in writing, software
11 | // distributed under the License is distributed on an "AS IS" BASIS,
12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | // See the License for the specific language governing permissions and
14 | // limitations under the License.
15 | //
16 |
17 | import RIBs
18 | import SnapKit
19 | import UIKit
20 |
21 | protocol BasicScoreBoardPresentableListener: class {
22 | // TODO: Declare properties and methods that the view controller can invoke to perform
23 | // business logic, such as signIn(). This protocol is implemented by the corresponding
24 | // interactor class.
25 | }
26 |
27 | final class BasicScoreBoardViewController: UIViewController, BasicScoreBoardPresentable, BasicScoreBoardViewControllable {
28 |
29 | weak var listener: BasicScoreBoardPresentableListener?
30 |
31 | init(player1Name: String,
32 | player2Name: String) {
33 | self.player1Name = player1Name
34 | self.player2Name = player2Name
35 | super.init(nibName: nil, bundle: nil)
36 | }
37 |
38 | required init?(coder aDecoder: NSCoder) {
39 | fatalError("Method is not supported")
40 | }
41 |
42 | override func viewDidLoad() {
43 | super.viewDidLoad()
44 |
45 | view.backgroundColor = UIColor.clear
46 | buildPlayerLabels()
47 | }
48 |
49 | // MARK: - OffGamePresentable
50 |
51 | func set(score: Score) {
52 | self.score = score
53 | }
54 |
55 | // MARK: - Private
56 |
57 | private let player1Name: String
58 | private let player2Name: String
59 |
60 | private var score: Score?
61 |
62 | private var player1Label: UILabel?
63 | private var player2Label: UILabel?
64 |
65 | private func buildPlayerLabels() {
66 | let labelBuilder: (UIColor) -> UILabel = { (color: UIColor) in
67 | let label = UILabel()
68 | label.font = UIFont.boldSystemFont(ofSize: 35)
69 | label.backgroundColor = UIColor.clear
70 | label.textColor = color
71 | label.textAlignment = .center
72 | return label
73 | }
74 |
75 | let player1Label = labelBuilder(PlayerType.player1.color)
76 | self.player1Label = player1Label
77 | view.addSubview(player1Label)
78 | player1Label.snp.makeConstraints { (maker: ConstraintMaker) in
79 | maker.top.leading.trailing.equalTo(self.view)
80 | maker.height.equalTo(40)
81 | }
82 |
83 | let vsLabel = UILabel()
84 | vsLabel.font = UIFont.systemFont(ofSize: 25)
85 | vsLabel.backgroundColor = UIColor.clear
86 | vsLabel.textColor = UIColor.darkGray
87 | vsLabel.textAlignment = .center
88 | vsLabel.text = "vs"
89 | view.addSubview(vsLabel)
90 | vsLabel.snp.makeConstraints { (maker: ConstraintMaker) in
91 | maker.top.equalTo(player1Label.snp.bottom).offset(10)
92 | maker.leading.trailing.equalTo(player1Label)
93 | maker.height.equalTo(20)
94 | }
95 |
96 | let player2Label = labelBuilder(PlayerType.player2.color)
97 | self.player2Label = player2Label
98 | view.addSubview(player2Label)
99 | player2Label.snp.makeConstraints { (maker: ConstraintMaker) in
100 | maker.top.equalTo(vsLabel.snp.bottom).offset(10)
101 | maker.height.leading.trailing.equalTo(player1Label)
102 | }
103 |
104 | updatePlayerLabels()
105 | }
106 |
107 | private func updatePlayerLabels() {
108 | let player1Score = score?.player1Score ?? 0
109 | player1Label?.text = "\(player1Name) (\(player1Score))"
110 |
111 | let player2Score = score?.player2Score ?? 0
112 | player2Label?.text = "\(player2Name) (\(player2Score))"
113 | }
114 | }
115 |
--------------------------------------------------------------------------------