agentic-mobile-kit 0.0.2 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +20 -8
- package/bin/cli.js +31 -5
- package/lib/init.js +199 -0
- package/package.json +9 -3
- package/stacks/react-native/template/.agents/skills/LICENSE-callstack +21 -0
- package/stacks/react-native/template/.agents/skills/THIRD_PARTY.md +9 -0
- package/stacks/react-native/template/.agents/skills/m-bugfix/SKILL.md +23 -0
- package/stacks/react-native/template/.agents/skills/m-bugfix/agents/openai.yaml +3 -0
- package/stacks/react-native/template/.agents/skills/m-continue/SKILL.md +22 -0
- package/stacks/react-native/template/.agents/skills/m-continue/agents/openai.yaml +3 -0
- package/stacks/react-native/template/.agents/skills/m-feature/SKILL.md +50 -0
- package/stacks/react-native/template/.agents/skills/m-feature/agents/openai.yaml +3 -0
- package/stacks/react-native/template/.agents/skills/m-pause/SKILL.md +14 -0
- package/stacks/react-native/template/.agents/skills/m-pause/agents/openai.yaml +3 -0
- package/stacks/react-native/template/.agents/skills/m-review/SKILL.md +29 -0
- package/stacks/react-native/template/.agents/skills/m-review/agents/openai.yaml +3 -0
- package/stacks/react-native/template/.agents/skills/react-native-best-practices/POWER.md +172 -0
- package/stacks/react-native/template/.agents/skills/react-native-best-practices/SKILL.md +238 -0
- package/stacks/react-native/template/.agents/skills/react-native-best-practices/agents/openai.yaml +4 -0
- package/stacks/react-native/template/.agents/skills/react-native-best-practices/references/bundle-analyze-app.md +208 -0
- package/stacks/react-native/template/.agents/skills/react-native-best-practices/references/bundle-analyze-js.md +264 -0
- package/stacks/react-native/template/.agents/skills/react-native-best-practices/references/bundle-barrel-exports.md +250 -0
- package/stacks/react-native/template/.agents/skills/react-native-best-practices/references/bundle-code-splitting.md +255 -0
- package/stacks/react-native/template/.agents/skills/react-native-best-practices/references/bundle-hermes-mmap.md +167 -0
- package/stacks/react-native/template/.agents/skills/react-native-best-practices/references/bundle-library-size.md +164 -0
- package/stacks/react-native/template/.agents/skills/react-native-best-practices/references/bundle-native-assets.md +208 -0
- package/stacks/react-native/template/.agents/skills/react-native-best-practices/references/bundle-r8-android.md +231 -0
- package/stacks/react-native/template/.agents/skills/react-native-best-practices/references/bundle-tree-shaking.md +215 -0
- package/stacks/react-native/template/.agents/skills/react-native-best-practices/references/js-animations-reanimated.md +273 -0
- package/stacks/react-native/template/.agents/skills/react-native-best-practices/references/js-atomic-state.md +190 -0
- package/stacks/react-native/template/.agents/skills/react-native-best-practices/references/js-bottomsheet.md +339 -0
- package/stacks/react-native/template/.agents/skills/react-native-best-practices/references/js-concurrent-react.md +238 -0
- package/stacks/react-native/template/.agents/skills/react-native-best-practices/references/js-lists-flatlist-flashlist.md +223 -0
- package/stacks/react-native/template/.agents/skills/react-native-best-practices/references/js-measure-fps.md +178 -0
- package/stacks/react-native/template/.agents/skills/react-native-best-practices/references/js-memory-leaks.md +168 -0
- package/stacks/react-native/template/.agents/skills/react-native-best-practices/references/js-profile-react.md +138 -0
- package/stacks/react-native/template/.agents/skills/react-native-best-practices/references/js-react-compiler.md +261 -0
- package/stacks/react-native/template/.agents/skills/react-native-best-practices/references/js-uncontrolled-components.md +219 -0
- package/stacks/react-native/template/.agents/skills/react-native-best-practices/references/native-android-16kb-alignment.md +114 -0
- package/stacks/react-native/template/.agents/skills/react-native-best-practices/references/native-measure-tti.md +221 -0
- package/stacks/react-native/template/.agents/skills/react-native-best-practices/references/native-memory-leaks.md +206 -0
- package/stacks/react-native/template/.agents/skills/react-native-best-practices/references/native-memory-patterns.md +240 -0
- package/stacks/react-native/template/.agents/skills/react-native-best-practices/references/native-platform-setup.md +112 -0
- package/stacks/react-native/template/.agents/skills/react-native-best-practices/references/native-profiling.md +140 -0
- package/stacks/react-native/template/.agents/skills/react-native-best-practices/references/native-sdks-over-polyfills.md +192 -0
- package/stacks/react-native/template/.agents/skills/react-native-best-practices/references/native-threading-model.md +230 -0
- package/stacks/react-native/template/.agents/skills/react-native-best-practices/references/native-turbo-modules.md +210 -0
- package/stacks/react-native/template/.agents/skills/react-native-best-practices/references/native-view-flattening.md +180 -0
- package/stacks/react-native/template/.agents/skills/react-navigation/SKILL.md +63 -0
- package/stacks/react-native/template/.agents/skills/react-navigation/agents/openai.yaml +4 -0
- package/stacks/react-native/template/.agents/skills/react-navigation/references/bottom-tabs.md +496 -0
- package/stacks/react-native/template/.agents/skills/react-navigation/references/drawers.md +474 -0
- package/stacks/react-native/template/.agents/skills/react-navigation/references/form-sheet.md +305 -0
- package/stacks/react-native/template/.agents/skills/react-navigation/references/header.md +270 -0
- package/stacks/react-native/template/.agents/skills/react-navigation/references/material-top-tabs.md +453 -0
- package/stacks/react-native/template/.agents/skills/react-navigation/references/native-bottom-tabs.md +365 -0
- package/stacks/react-native/template/.agents/skills/react-navigation/references/safe-areas.md +95 -0
- package/stacks/react-native/template/.agents/skills/react-navigation/references/stacks.md +392 -0
- package/stacks/react-native/template/.agents/skills/upgrading-react-native/SKILL.md +79 -0
- package/stacks/react-native/template/.agents/skills/upgrading-react-native/agents/openai.yaml +4 -0
- package/stacks/react-native/template/.agents/skills/upgrading-react-native/references/expo-sdk-upgrade.md +65 -0
- package/stacks/react-native/template/.agents/skills/upgrading-react-native/references/monorepo-singlerepo-targeting.md +34 -0
- package/stacks/react-native/template/.agents/skills/upgrading-react-native/references/react.md +42 -0
- package/stacks/react-native/template/.agents/skills/upgrading-react-native/references/upgrade-helper-core.md +122 -0
- package/stacks/react-native/template/.agents/skills/upgrading-react-native/references/upgrade-verification.md +53 -0
- package/stacks/react-native/template/.agents/skills/upgrading-react-native/references/upgrading-dependencies.md +41 -0
- package/stacks/react-native/template/.agents/skills/upgrading-react-native/references/upgrading-react-native.md +52 -0
- package/stacks/react-native/template/.githooks/pre-commit +49 -0
- package/stacks/react-native/template/.githooks/pre-push +5 -0
- package/stacks/react-native/template/.github/pull_request_template.md +19 -0
- package/stacks/react-native/template/.github/workflows/ci.yml +61 -0
- package/stacks/react-native/template/.github/workflows/e2e.yml +72 -0
- package/stacks/react-native/template/.github/workflows/ios.yml +43 -0
- package/stacks/react-native/template/.gitleaks.toml +12 -0
- package/stacks/react-native/template/.rulesync/hooks.jsonc +8 -0
- package/stacks/react-native/template/.rulesync/permissions.jsonc +36 -0
- package/stacks/react-native/template/.rulesync/subagents/m-reviewer.md +15 -0
- package/stacks/react-native/template/AGENTS.md +46 -0
- package/stacks/react-native/template/CLAUDE.md +1 -0
- package/stacks/react-native/template/docs/ai/conventions.md +8 -0
- package/stacks/react-native/template/docs/ai/decisions.md +6 -0
- package/stacks/react-native/template/docs/ai/known-issues.md +17 -0
- package/stacks/react-native/template/docs/ai/product.md +7 -0
- package/stacks/react-native/template/docs/ai/react-native.md +27 -0
- package/stacks/react-native/template/docs/ai/structure.md +7 -0
- package/stacks/react-native/template/docs/ai/team-process.md +9 -0
- package/stacks/react-native/template/docs/ai/tech.md +7 -0
- package/stacks/react-native/template/rulesync.jsonc +9 -0
- package/stacks/react-native/template/scripts/ai/guard.js +35 -0
- package/stacks/react-native/template/scripts/ai/handoff-check.js +28 -0
- package/stacks/react-native/template/scripts/ai/install-deps.sh +14 -0
- package/stacks/react-native/template/scripts/ai/ios-build.sh +14 -0
- package/stacks/react-native/template/scripts/ai/pm-run.sh +16 -0
- package/stacks/react-native/template/scripts/ai/verify.sh +139 -0
- package/stacks/react-native/template/specs/_templates/design.md +15 -0
- package/stacks/react-native/template/specs/_templates/flow.yaml +14 -0
- package/stacks/react-native/template/specs/_templates/progress.md +14 -0
- package/stacks/react-native/template/specs/_templates/requirements.md +30 -0
- package/stacks/react-native/template/specs/_templates/tasks.md +6 -0
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Fast Native Modules
|
|
3
|
+
impact: HIGH
|
|
4
|
+
tags: turbo-modules, native, swift, kotlin, c++
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# Skill: Fast Native Modules
|
|
8
|
+
|
|
9
|
+
Build performant Turbo Modules using modern languages and background threading.
|
|
10
|
+
|
|
11
|
+
## Quick Pattern
|
|
12
|
+
|
|
13
|
+
**Incorrect (sync method blocks JS thread):**
|
|
14
|
+
|
|
15
|
+
```swift
|
|
16
|
+
@objc func heavyWork() -> NSNumber {
|
|
17
|
+
Thread.sleep(forTimeInterval: 2) // Blocks JS for 2s!
|
|
18
|
+
return 42
|
|
19
|
+
}
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
**Correct (async on background thread):**
|
|
23
|
+
|
|
24
|
+
```swift
|
|
25
|
+
@objc func heavyWork(
|
|
26
|
+
resolve: @escaping RCTPromiseResolveBlock,
|
|
27
|
+
reject: RCTPromiseRejectBlock
|
|
28
|
+
) {
|
|
29
|
+
DispatchQueue.global().async {
|
|
30
|
+
let result = self.compute()
|
|
31
|
+
resolve(result)
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## When to Use
|
|
37
|
+
|
|
38
|
+
- Creating new native modules
|
|
39
|
+
- Optimizing existing module performance
|
|
40
|
+
- Heavy computation needs to run off JS thread
|
|
41
|
+
- Cross-platform C++ code needed
|
|
42
|
+
|
|
43
|
+
## Prerequisites
|
|
44
|
+
|
|
45
|
+
- React Native Builder Bob for scaffolding
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
npx create-react-native-library@latest my-library
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## Step-by-Step Instructions
|
|
52
|
+
|
|
53
|
+
### 1. Scaffold with Builder Bob
|
|
54
|
+
|
|
55
|
+
```bash
|
|
56
|
+
npx create-react-native-library@latest awesome-library
|
|
57
|
+
# Follow prompts: choose Turbo Module, select languages
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
Creates ready-to-publish library with:
|
|
61
|
+
- iOS (Obj-C/Swift) support
|
|
62
|
+
- Android (Kotlin) support
|
|
63
|
+
- TypeScript definitions
|
|
64
|
+
- Codegen setup
|
|
65
|
+
|
|
66
|
+
For local modules:
|
|
67
|
+
|
|
68
|
+
```bash
|
|
69
|
+
npx create-react-native-library@latest awesome-library --local
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
### 2. Run on Background Thread (iOS)
|
|
73
|
+
|
|
74
|
+
```swift
|
|
75
|
+
@objc func heavyOperation(
|
|
76
|
+
_ input: Double,
|
|
77
|
+
resolve: @escaping RCTPromiseResolveBlock,
|
|
78
|
+
reject: RCTPromiseRejectBlock
|
|
79
|
+
) {
|
|
80
|
+
DispatchQueue.global().async {
|
|
81
|
+
// Heavy work on background thread
|
|
82
|
+
let result = self.expensiveComputation(input)
|
|
83
|
+
resolve(result)
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
### 3. Run on Background Thread (Android)
|
|
89
|
+
|
|
90
|
+
```kotlin
|
|
91
|
+
class AwesomeLibraryModule(reactContext: ReactApplicationContext) :
|
|
92
|
+
NativeAwesomeLibrarySpec(reactContext) {
|
|
93
|
+
|
|
94
|
+
private val moduleScope = CoroutineScope(Dispatchers.Default + SupervisorJob())
|
|
95
|
+
|
|
96
|
+
override fun heavyOperation(input: Double, promise: Promise?) {
|
|
97
|
+
moduleScope.launch {
|
|
98
|
+
// Heavy work on coroutine
|
|
99
|
+
val result = expensiveComputation(input)
|
|
100
|
+
promise?.resolve(result)
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
override fun invalidate() {
|
|
105
|
+
super.invalidate()
|
|
106
|
+
moduleScope.cancel() // Prevent memory leaks!
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
Use structured concurrency: keep a module-owned `CoroutineScope`, cancel it in `invalidate()`, avoid `GlobalScope.launch`, use `SupervisorJob` so one failed operation does not cancel unrelated in-flight work, and choose `Dispatchers.Default` for CPU work or `Dispatchers.IO` for disk/network/database work.
|
|
112
|
+
|
|
113
|
+
### 4. Use C++ for Cross-Platform Code
|
|
114
|
+
|
|
115
|
+
Create C++ Turbo Module for shared logic:
|
|
116
|
+
|
|
117
|
+
```cpp
|
|
118
|
+
// MyCppModule.h
|
|
119
|
+
#pragma once
|
|
120
|
+
|
|
121
|
+
#include <ReactCommon/TurboModule.h>
|
|
122
|
+
|
|
123
|
+
namespace facebook::react {
|
|
124
|
+
|
|
125
|
+
class MyCppModule : public TurboModule {
|
|
126
|
+
public:
|
|
127
|
+
MyCppModule(std::shared_ptr<CallInvoker> jsInvoker);
|
|
128
|
+
|
|
129
|
+
double multiply(double a, double b);
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
} // namespace facebook::react
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
Follow the registration mechanism documented for the React Native version you target. Avoid copying old `+load` registration workarounds unless current RN docs or template output still require them.
|
|
136
|
+
|
|
137
|
+
## Threading Summary
|
|
138
|
+
|
|
139
|
+
| Method Type | Default Thread | Best Practice |
|
|
140
|
+
|-------------|----------------|---------------|
|
|
141
|
+
| Sync | JS thread | Keep fast (<16ms) |
|
|
142
|
+
| Async | Native modules thread | OK for moderate work |
|
|
143
|
+
| Heavy async | Custom background | Use DispatchQueue/Coroutines |
|
|
144
|
+
|
|
145
|
+
## Language Interop Costs
|
|
146
|
+
|
|
147
|
+
| Interface | Overhead | Notes |
|
|
148
|
+
|-----------|----------|-------|
|
|
149
|
+
| Obj-C / Obj-C++ ↔ C++ | Low | Common iOS interop path |
|
|
150
|
+
| Swift ↔ C++ | Version-dependent | Verify supported Swift/Xcode/RN setup |
|
|
151
|
+
| Kotlin ↔ C++ (JNI) | Higher | Batch calls and avoid per-item crossings |
|
|
152
|
+
| C++ Turbo Module | Low | JSI direct access when correctly registered |
|
|
153
|
+
|
|
154
|
+
**Tip**: C++ Turbo Modules skip JNI at runtime since JS holds direct C++ function references via JSI.
|
|
155
|
+
|
|
156
|
+
## Code Example: Complete Async Operation
|
|
157
|
+
|
|
158
|
+
```typescript
|
|
159
|
+
// TypeScript interface
|
|
160
|
+
export interface Spec extends TurboModule {
|
|
161
|
+
multiply(a: number, b: number): number; // Sync
|
|
162
|
+
heavyOperation(input: number): Promise<number>; // Async
|
|
163
|
+
}
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
```kotlin
|
|
167
|
+
// Android implementation
|
|
168
|
+
override fun heavyOperation(input: Double, promise: Promise?) {
|
|
169
|
+
moduleScope.launch {
|
|
170
|
+
try {
|
|
171
|
+
val result = withContext(Dispatchers.Default) {
|
|
172
|
+
// Simulate heavy work
|
|
173
|
+
delay(1000)
|
|
174
|
+
input * 2
|
|
175
|
+
}
|
|
176
|
+
promise?.resolve(result)
|
|
177
|
+
} catch (e: Exception) {
|
|
178
|
+
promise?.reject("ERROR", e.message)
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
```swift
|
|
185
|
+
// iOS implementation
|
|
186
|
+
@objc func heavyOperation(
|
|
187
|
+
_ input: Double,
|
|
188
|
+
resolve: @escaping RCTPromiseResolveBlock,
|
|
189
|
+
reject: @escaping RCTPromiseRejectBlock
|
|
190
|
+
) {
|
|
191
|
+
DispatchQueue.global(qos: .userInitiated).async {
|
|
192
|
+
// Simulate heavy work
|
|
193
|
+
Thread.sleep(forTimeInterval: 1.0)
|
|
194
|
+
let result = input * 2
|
|
195
|
+
resolve(result)
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
## Common Pitfalls
|
|
201
|
+
|
|
202
|
+
- **Sync methods that block**: Keep sync methods trivial and deterministic; make anything that can block, allocate heavily, perform I/O, or wait on locks async/background work
|
|
203
|
+
- **Forgetting to cancel coroutine scope**: Causes memory leaks
|
|
204
|
+
- **Not handling errors in async**: Always try/catch with reject
|
|
205
|
+
- **Accessing UI from background**: Dispatch to main thread
|
|
206
|
+
|
|
207
|
+
## Related Skills
|
|
208
|
+
|
|
209
|
+
- [native-threading-model.md](./native-threading-model.md) - Thread details
|
|
210
|
+
- [native-memory-patterns.md](./native-memory-patterns.md) - Memory in native code
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: View Flattening
|
|
3
|
+
impact: MEDIUM
|
|
4
|
+
tags: views, flattening, collapsable, hierarchy
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# Skill: View Flattening
|
|
8
|
+
|
|
9
|
+
Understand and debug React Native's view flattening optimization.
|
|
10
|
+
|
|
11
|
+
## Quick Pattern
|
|
12
|
+
|
|
13
|
+
**Problem (children get flattened unexpectedly):**
|
|
14
|
+
|
|
15
|
+
```jsx
|
|
16
|
+
<NativeTabBar>
|
|
17
|
+
<Tab1 /> // May be flattened, breaking native component
|
|
18
|
+
<Tab2 />
|
|
19
|
+
</NativeTabBar>
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
**Solution (prevent flattening):**
|
|
23
|
+
|
|
24
|
+
```jsx
|
|
25
|
+
<NativeTabBar>
|
|
26
|
+
<Tab1 collapsable={false} />
|
|
27
|
+
<Tab2 collapsable={false} />
|
|
28
|
+
</NativeTabBar>
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## When to Use
|
|
32
|
+
|
|
33
|
+
- Native component receives unexpected number of children
|
|
34
|
+
- Layout debugging with native components
|
|
35
|
+
- Building native components that accept children
|
|
36
|
+
- Understanding React Native rendering
|
|
37
|
+
|
|
38
|
+
> **Note**: This skill involves visual view hierarchy tools (Xcode Debug View Hierarchy, Android Layout Inspector). Use `agent-device` for screen evidence; install it through the environment's approved/trusted path or ask the user if verification needs it and it is missing. Native hierarchy inspection may still require Xcode, Android Studio, or human review. Record native child counts and component names in text when asking an agent to reason about them.
|
|
39
|
+
|
|
40
|
+
## What is View Flattening?
|
|
41
|
+
|
|
42
|
+
React Native's renderer automatically removes "layout-only" views that:
|
|
43
|
+
- Only affect layout (no visual rendering)
|
|
44
|
+
- Don't need to exist in native view hierarchy
|
|
45
|
+
|
|
46
|
+
**Benefits**: Reduced memory, faster rendering, shallower view tree.
|
|
47
|
+
|
|
48
|
+
## The Problem with Native Components
|
|
49
|
+
|
|
50
|
+
```tsx
|
|
51
|
+
// You expect 3 children
|
|
52
|
+
<MyNativeComponent>
|
|
53
|
+
<Child1 />
|
|
54
|
+
<Child2 />
|
|
55
|
+
<Child3 />
|
|
56
|
+
</MyNativeComponent>
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
If a child wrapper is flattened, native code may receive a different child count or shape than the JS tree suggests.
|
|
60
|
+
|
|
61
|
+
## Preventing Flattening with `collapsable`
|
|
62
|
+
|
|
63
|
+
```tsx
|
|
64
|
+
<MyNativeComponent>
|
|
65
|
+
<Child1 collapsable={false} />
|
|
66
|
+
<Child2 collapsable={false} />
|
|
67
|
+
<Child3 collapsable={false} />
|
|
68
|
+
</MyNativeComponent>
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
The direct views marked `collapsable={false}` are preserved as native children.
|
|
72
|
+
|
|
73
|
+
## Debugging View Hierarchy
|
|
74
|
+
|
|
75
|
+

|
|
76
|
+
|
|
77
|
+
Use native debugging tools to see the actual view hierarchy:
|
|
78
|
+
|
|
79
|
+
### Xcode (iOS)
|
|
80
|
+
|
|
81
|
+
1. Run app via Xcode
|
|
82
|
+
2. Click **"Debug View Hierarchy"** in debug toolbar (shown in image)
|
|
83
|
+
3. Inspect 3D view of native hierarchy
|
|
84
|
+
|
|
85
|
+
Component class names vary by architecture and React Native version; verify the actual native hierarchy in the tool.
|
|
86
|
+
|
|
87
|
+
### Android Studio
|
|
88
|
+
|
|
89
|
+
1. Run app via Android Studio
|
|
90
|
+
2. **View → Tool Windows → Layout Inspector**
|
|
91
|
+
3. Select running process
|
|
92
|
+
|
|
93
|
+
Component class names vary by architecture and React Native version; verify the actual native hierarchy in the tool.
|
|
94
|
+
|
|
95
|
+
## Code Examples
|
|
96
|
+
|
|
97
|
+
### When Flattening Breaks Your Component
|
|
98
|
+
|
|
99
|
+
```tsx
|
|
100
|
+
// Your native component expects exactly 2 tabs
|
|
101
|
+
const NativeTabBar = requireNativeComponent('RCTTabBar');
|
|
102
|
+
|
|
103
|
+
// BAD: TabContent might get flattened
|
|
104
|
+
const MyTabs = () => (
|
|
105
|
+
<NativeTabBar>
|
|
106
|
+
<TabContent title="Home">
|
|
107
|
+
<View><Text>Home content</Text></View>
|
|
108
|
+
</TabContent>
|
|
109
|
+
<TabContent title="Profile">
|
|
110
|
+
<View><Text>Profile content</Text></View>
|
|
111
|
+
</TabContent>
|
|
112
|
+
</NativeTabBar>
|
|
113
|
+
);
|
|
114
|
+
|
|
115
|
+
// GOOD: Prevent flattening
|
|
116
|
+
const MyTabs = () => (
|
|
117
|
+
<NativeTabBar>
|
|
118
|
+
<TabContent title="Home" collapsable={false}>
|
|
119
|
+
<View><Text>Home content</Text></View>
|
|
120
|
+
</TabContent>
|
|
121
|
+
<TabContent title="Profile" collapsable={false}>
|
|
122
|
+
<View><Text>Profile content</Text></View>
|
|
123
|
+
</TabContent>
|
|
124
|
+
</NativeTabBar>
|
|
125
|
+
);
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
### Wrapper Component with collapsable
|
|
129
|
+
|
|
130
|
+
```tsx
|
|
131
|
+
// Wrapper that prevents flattening
|
|
132
|
+
const NativeChildWrapper = ({ children, ...props }) => (
|
|
133
|
+
<View collapsable={false} {...props}>
|
|
134
|
+
{children}
|
|
135
|
+
</View>
|
|
136
|
+
);
|
|
137
|
+
|
|
138
|
+
// Usage
|
|
139
|
+
<NativeComponent>
|
|
140
|
+
<NativeChildWrapper>
|
|
141
|
+
<ComplexChild />
|
|
142
|
+
</NativeChildWrapper>
|
|
143
|
+
</NativeComponent>
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
## When Views Get Flattened
|
|
147
|
+
|
|
148
|
+
React Native can flatten layout-only wrappers that do not need their own native view for drawing, events, accessibility, measurement, or native-component child semantics. The exact rules vary across renderer versions.
|
|
149
|
+
|
|
150
|
+
## Forcing a View to Stay
|
|
151
|
+
|
|
152
|
+
Use `collapsable={false}` as the stable fix. Style or handler changes can be useful as debugging probes, but do not keep them as the production solution:
|
|
153
|
+
|
|
154
|
+
```tsx
|
|
155
|
+
// Diagnostic probes only
|
|
156
|
+
<View style={{ backgroundColor: 'transparent' }} />
|
|
157
|
+
<View style={{ borderWidth: 0.01 }} />
|
|
158
|
+
<View style={{ opacity: 0.99 }} />
|
|
159
|
+
<View onLayout={() => {}} />
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
Remove these probes after confirming flattening is the issue.
|
|
163
|
+
|
|
164
|
+
## Debugging Checklist
|
|
165
|
+
|
|
166
|
+
1. **Check native child count**: Log received children in native code
|
|
167
|
+
2. **Use Layout Inspector**: Visual hierarchy debugging
|
|
168
|
+
3. **Add collapsable={false}**: Test if flattening is the issue
|
|
169
|
+
4. **Check wrapper components**: Intermediate views may be flattened
|
|
170
|
+
|
|
171
|
+
## Common Pitfalls
|
|
172
|
+
|
|
173
|
+
- **Assuming JS children = native children**: Flattening changes this
|
|
174
|
+
- **Not documenting native component requirements**: If your native component expects specific child count, document it
|
|
175
|
+
- **Over-using collapsable={false}**: Only use when necessary (loses optimization benefits)
|
|
176
|
+
|
|
177
|
+
## Related Skills
|
|
178
|
+
|
|
179
|
+
- [native-platform-setup.md](./native-platform-setup.md) - IDE setup for debugging
|
|
180
|
+
- [native-profiling.md](./native-profiling.md) - Performance impact analysis
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: react-navigation
|
|
3
|
+
description: Provides React Navigation UI patterns for stacks, tabs, drawers etc. Use when building navigation UIs with React Navigation, configuring headers, bottom sheets or handling safe areas and insets.
|
|
4
|
+
license: MIT
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# React Navigation
|
|
8
|
+
|
|
9
|
+
## Overview
|
|
10
|
+
|
|
11
|
+
Guide for building navigation UIs with React Navigation.
|
|
12
|
+
|
|
13
|
+
This skill only applies to React Navigation 7. The API and patterns may not work with different versions.
|
|
14
|
+
|
|
15
|
+
## API Selection
|
|
16
|
+
|
|
17
|
+
React Navigation offers two API - object-based `Static API` and component-based `Dynamic API`.
|
|
18
|
+
|
|
19
|
+
- **Existing Apps**: Check the current navigation setup and follow the same API style when using the references
|
|
20
|
+
- **New Apps**: If the app does not have an existing navigation setup yet, prefer `Static API`
|
|
21
|
+
|
|
22
|
+
## When to Apply
|
|
23
|
+
|
|
24
|
+
Reference this skill when:
|
|
25
|
+
|
|
26
|
+
- Building navigation UI patterns such as stacks, tabs, drawers, sheets etc.
|
|
27
|
+
- Configuring headers and other built-in navigator UI
|
|
28
|
+
- Handling safe areas and insets in navigation UI
|
|
29
|
+
|
|
30
|
+
## References
|
|
31
|
+
|
|
32
|
+
| File | Description |
|
|
33
|
+
| ------------------------------------------- | ------------------------------ |
|
|
34
|
+
| [stacks.md][stacks] | Stack based navigation |
|
|
35
|
+
| [form-sheet.md][form-sheet] | Bottom sheet and form sheets |
|
|
36
|
+
| [bottom-tabs.md][bottom-tabs] | Cross-platform bottom tabs |
|
|
37
|
+
| [native-bottom-tabs.md][native-bottom-tabs] | Native bottom tabs |
|
|
38
|
+
| [material-top-tabs.md][material-top-tabs] | Swipeable Top tabs |
|
|
39
|
+
| [drawers.md][drawers] | Drawer navigation and sidebars |
|
|
40
|
+
| [header.md][header] | Configuring headers |
|
|
41
|
+
| [safe-areas.md][safe-areas] | Safe-area handling |
|
|
42
|
+
|
|
43
|
+
## Problem -> Skill Mapping
|
|
44
|
+
|
|
45
|
+
| Problem | Start With |
|
|
46
|
+
| ------------------------------------------------------------------------- | ------------------------------------------- |
|
|
47
|
+
| Showing screens and modals in a stack | [stacks.md][stacks] |
|
|
48
|
+
| Showing bottom sheets or form sheets | [form-sheet.md][form-sheet] |
|
|
49
|
+
| Showing screens in bottom tabs or responsive sidebars with web support | [bottom-tabs.md][bottom-tabs] |
|
|
50
|
+
| Showing screens in native tabs on iOS & Android | [native-bottom-tabs.md][native-bottom-tabs] |
|
|
51
|
+
| Showing content in swipeable top tabs | [material-top-tabs.md][material-top-tabs] |
|
|
52
|
+
| Using a drawer or sidebar | [drawers.md][drawers] |
|
|
53
|
+
| Configuring the header in bottom tab or drawer navigator | [header.md][header] |
|
|
54
|
+
| Handling safe-area such as status bar, header insets, tab bar insets etc. | [safe-areas.md][safe-areas] |
|
|
55
|
+
|
|
56
|
+
[stacks]: references/stacks.md
|
|
57
|
+
[form-sheet]: references/form-sheet.md
|
|
58
|
+
[safe-areas]: references/safe-areas.md
|
|
59
|
+
[bottom-tabs]: references/bottom-tabs.md
|
|
60
|
+
[native-bottom-tabs]: references/native-bottom-tabs.md
|
|
61
|
+
[material-top-tabs]: references/material-top-tabs.md
|
|
62
|
+
[drawers]: references/drawers.md
|
|
63
|
+
[header]: references/header.md
|