Skip to content

Commit f87ac66

Browse files
committed
feat: integrate into tester app
1 parent dbbd340 commit f87ac66

6 files changed

Lines changed: 30 additions & 20 deletions

File tree

apps/AppleApp/Brownfield Apple App/BrownfieldAppleApp.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import BrownfieldLib
2+
import Brownie
23
import ReactBrownfield
34
import SwiftUI
45

@@ -15,6 +16,8 @@ struct BrownfieldAppleApp: App {
1516
ReactNativeBrownfield.shared.startReactNative {
1617
print("React Native has been loaded")
1718
}
19+
20+
_ = Store(initialState, key: BrownfieldStore.storeName)
1821
}
1922

2023
var body: some Scene {

apps/AppleApp/Brownfield Apple App/ContentView.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ struct MainScreen: View {
3434

3535
struct GreetingCard: View {
3636
let name: String
37-
@State private var counter: Int = 0
37+
@UseStore(\BrownfieldStore.counter) var counter
3838

3939
var body: some View {
4040
VStack(spacing: 12) {
@@ -43,13 +43,13 @@ struct GreetingCard: View {
4343
.multilineTextAlignment(.center)
4444

4545
Text(
46-
"You clicked the button \(counter) time\(counter == 1 ? "" : "s")"
46+
"You clicked the button \(Int(counter)) time\(counter == 1 ? "" : "s")"
4747
)
4848
.multilineTextAlignment(.center)
4949
.font(.body)
5050

5151
Button("Increment counter") {
52-
counter += 1
52+
$counter.set { $0 + 1 }
5353
}
5454
.buttonStyle(.borderedProminent)
5555
}

apps/RNApp/App.tsx

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
import React, { useEffect } from 'react';
1+
import { useEffect } from 'react';
22
import { StyleSheet, Text, View, Button } from 'react-native';
3+
import { useStore } from '@callstack/brownie';
4+
import './BrownfieldStore.brownie';
35
import {
46
createNativeStackNavigator,
57
type NativeStackScreenProps,
@@ -26,6 +28,7 @@ type Props = NativeStackScreenProps<RootStackParamList, 'Home'>;
2628

2729
function HomeScreen({ navigation, route }: Props) {
2830
const colors = route.params?.theme || getRandomTheme();
31+
const [counter, setState] = useStore('BrownfieldStore', (s) => s.counter);
2932

3033
useEffect(() => {
3134
const unsubscribe = navigation.addListener('focus', () => {
@@ -41,6 +44,16 @@ function HomeScreen({ navigation, route }: Props) {
4144
React Native Screen
4245
</Text>
4346

47+
<Text style={[styles.text, { color: colors.secondary }]}>
48+
Count: {counter}
49+
</Text>
50+
51+
<Button
52+
onPress={() => setState((prev) => ({ counter: prev.counter + 1 }))}
53+
color={colors.secondary}
54+
title="Increment"
55+
/>
56+
4457
<Button
4558
onPress={() => {
4659
navigation.push('Home', {

apps/RNApp/metro.config.js

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,8 @@
1-
const { getDefaultConfig, mergeConfig } = require('@react-native/metro-config');
21
const path = require('path');
2+
const { getDefaultConfig } = require('@react-native/metro-config');
3+
const { withMetroConfig } = require('react-native-monorepo-config');
34

4-
const root = path.resolve(__dirname, '..', '..');
5-
6-
/**
7-
* Metro configuration
8-
* https://reactnative.dev/docs/metro
9-
*
10-
* @type {import('@react-native/metro-config').MetroConfig}
11-
*/
12-
const config = {
13-
watchFolders: [root],
14-
};
15-
16-
module.exports = mergeConfig(getDefaultConfig(__dirname), config);
5+
module.exports = withMetroConfig(getDefaultConfig(__dirname), {
6+
root: path.resolve(__dirname, '../..'),
7+
dirname: __dirname,
8+
});

apps/RNApp/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"build:example:ios-rn": "react-native build-ios",
1010
"brownfield:package:android": "brownfield package:android --module-name :BrownfieldLib --variant release --verbose",
1111
"brownfield:publish:android": "brownfield publish:android --module-name :BrownfieldLib --verbose",
12-
"brownfield:package:ios": "brownfield package:ios --scheme BrownfieldLib --configuration Release --verbose",
12+
"brownfield:package:ios": "brownfield package:ios --scheme BrownfieldLib",
1313
"lint": "eslint .",
1414
"start": "react-native start",
1515
"test": "jest",
@@ -45,6 +45,7 @@
4545
"eslint": "^8.19.0",
4646
"jest": "^29.6.3",
4747
"prettier": "2.8.8",
48+
"react-native-monorepo-config": "^0.3.2",
4849
"react-native-safe-area-context": "^5.3.0",
4950
"react-native-screens": "^4.15.2",
5051
"react-test-renderer": "19.1.1",

yarn.lock

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2218,6 +2218,7 @@ __metadata:
22182218
prettier: "npm:2.8.8"
22192219
react: "npm:19.1.1"
22202220
react-native: "npm:0.82.1"
2221+
react-native-monorepo-config: "npm:^0.3.2"
22212222
react-native-safe-area-context: "npm:^5.3.0"
22222223
react-native-screens: "npm:^4.15.2"
22232224
react-test-renderer: "npm:19.1.1"
@@ -13682,7 +13683,7 @@ __metadata:
1368213683
languageName: node
1368313684
linkType: hard
1368413685

13685-
"react-native-monorepo-config@npm:^0.3.1":
13686+
"react-native-monorepo-config@npm:^0.3.1, react-native-monorepo-config@npm:^0.3.2":
1368613687
version: 0.3.2
1368713688
resolution: "react-native-monorepo-config@npm:0.3.2"
1368813689
dependencies:

0 commit comments

Comments
 (0)