docs(cndocs): 同步多篇 React Native 中文文档更新#1008
Conversation
❌ Deploy Preview for reactnativecn failed. Why did it fail? →
|
📝 WalkthroughWalkthroughThe PR updates Chinese React Native documentation with improved API signatures and deprecation notices for Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 5
🧹 Nitpick comments (1)
cndocs/_remove-global-cli.md (1)
2-2: Consider mentioning both packages in the warning text.The warning text mentions the
react-native-clipackage, but the command removes bothreact-native-cliand@react-native-community/cli. While the command is correct, explicitly mentioning both packages in the warning text would improve clarity and help users understand why both are being removed.📝 Optional refinement for clarity
-如果你之前全局安装过 `react-native-cli` 包,请将其移除,因为它可能会导致一些意外问题: +如果你之前全局安装过 `react-native-cli` 或 `@react-native-community/cli` 包,请将其移除,因为它们可能会导致一些意外问题:Also applies to: 5-5
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@cndocs/_remove-global-cli.md` at line 2, Update the warning sentence that currently only names "react-native-cli" so it explicitly mentions both "react-native-cli" and "@react-native-community/cli" to match the uninstall command; locate the sentence containing the string "react-native-cli" in the document and rewrite it to mention both package names (and mirror this change in the other occurrence noted by "Also applies to: 5-5").
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@cndocs/accessibilityinfo.md`:
- Around line 230-242: Add missing semicolons to the TypeScript method
signatures: terminate the declarations for static isHighTextContrastEnabled():
Promise<boolean> and static isDarkerSystemColorsEnabled(): Promise<boolean> with
a trailing semicolon to match the rest of the file's signature style and restore
consistency.
- Around line 280-282: The method signature for sendAccessibilityEvent is
missing an explicit return type; update the declaration of
sendAccessibilityEvent(host: HostInstance, eventType: AccessibilityEventTypes)
to include an explicit void return annotation (i.e., append : void) to match
other void-returning methods like announceForAccessibility and
setAccessibilityFocus and improve clarity and consistency.
In `@cndocs/dimensions.md`:
- Around line 57-66: The mapped Text nodes rendering
Object.entries(dimensions.window) and Object.entries(dimensions.screen) lack
stable key props causing React warnings; update both map callbacks (the
expressions using Object.entries(dimensions.window).map and
Object.entries(dimensions.screen).map) to add a unique key prop—e.g., use the
entry key (key) or a combined string like `${key}-window` / `${key}-screen`—on
each <Text> element so each rendered list item has a stable React key.
In `@cndocs/turbo-native-modules-ios.md`:
- Around line 155-158: The workspace name in the iOS command snippet is
inconsistent: replace the reference to SampleApp.xcworkspace with
TurboModuleExample.xcworkspace so it matches the earlier step that opens
TurboModuleExample.xcworkspace; update the `open` command in the block so the
snippet uses `TurboModuleExample.xcworkspace` while keeping the preceding
`bundle exec pod install` line unchanged.
In `@scripts/sync-translations.sh`:
- Around line 63-69: The script's git log assignments (e.g., upstream_epoch and
translation_epoch) can be empty even though the command exits 0, so the numeric
comparisons fail; change the capture to explicitly default empty output to 0
(for example: run git log -1 --format="%ct" ... into a variable, then set
variable=${variable:-0}) and apply the same pattern to any other epoch captures
and the date fallback so the subsequent -eq and -gt numeric comparisons work
correctly (update the usages around upstream_epoch, translation_epoch and any
other epoch/date variables in sync-translations.sh).
---
Nitpick comments:
In `@cndocs/_remove-global-cli.md`:
- Line 2: Update the warning sentence that currently only names
"react-native-cli" so it explicitly mentions both "react-native-cli" and
"@react-native-community/cli" to match the uninstall command; locate the
sentence containing the string "react-native-cli" in the document and rewrite it
to mention both package names (and mirror this change in the other occurrence
noted by "Also applies to: 5-5").
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 026b1c61-ad16-4204-a9ef-b68daa2840bd
📒 Files selected for processing (7)
cndocs/_remove-global-cli.mdcndocs/accessibilityinfo.mdcndocs/devsettings.mdcndocs/dimensions.mdcndocs/turbo-native-modules-ios.mdpackage.jsonscripts/sync-translations.sh
| ```tsx | ||
| static isHighTextContrastEnabled(): Promise<boolean> | ||
| ``` | ||
|
|
||
| 查询是否启用了高对比度文本。返回 Promise,启用为 `true`,否则为 `false`。 | ||
|
|
||
| --- | ||
|
|
||
| ### `isDarkerSystemColorsEnabled()` <div className="label ios">iOS</div> | ||
|
|
||
| ```tsx | ||
| static isDarkerSystemColorsEnabled(): Promise<boolean> | ||
| ``` |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
# First, find and read the file to check the lines mentioned
wc -l cndocs/accessibilityinfo.mdRepository: reactnativecn/react-native-website
Length of output: 109
🏁 Script executed:
# Read lines 220-250 to see the context and verify the lines mentioned
sed -n '220,250p' cndocs/accessibilityinfo.md | cat -nRepository: reactnativecn/react-native-website
Length of output: 888
🏁 Script executed:
# Search for all TypeScript method signatures in the file to check semicolon patterns
rg -n "static.*\(\).*Promise" cndocs/accessibilityinfo.mdRepository: reactnativecn/react-native-website
Length of output: 638
🏁 Script executed:
# More broadly, check all tsx code blocks for TypeScript signatures to understand the pattern
rg -B2 -A2 "^static.*\(\)" cndocs/accessibilityinfo.mdRepository: reactnativecn/react-native-website
Length of output: 757
Add semicolons to the two API method signatures to maintain consistency with the rest of the file.
Lines 231 and 241 are missing semicolons at the end of the TypeScript signatures. All other method signatures in the file (except for a typo on line 171) end with semicolons. This is a style inconsistency that should be fixed.
✏️ Suggested fix
-static isHighTextContrastEnabled(): Promise<boolean>
+static isHighTextContrastEnabled(): Promise<boolean>;
...
-static isDarkerSystemColorsEnabled(): Promise<boolean>
+static isDarkerSystemColorsEnabled(): Promise<boolean>;🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@cndocs/accessibilityinfo.md` around lines 230 - 242, Add missing semicolons
to the TypeScript method signatures: terminate the declarations for static
isHighTextContrastEnabled(): Promise<boolean> and static
isDarkerSystemColorsEnabled(): Promise<boolean> with a trailing semicolon to
match the rest of the file's signature style and restore consistency.
| ```tsx | ||
| static sendAccessibilityEvent(host: HostInstance, eventType: AccessibilityEventTypes); | ||
| ``` |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
# First, check if the file exists and read the relevant lines
cat -n cndocs/accessibilityinfo.md | sed -n '275,290p'Repository: reactnativecn/react-native-website
Length of output: 586
🏁 Script executed:
# Get more context around the file
wc -l cndocs/accessibilityinfo.mdRepository: reactnativecn/react-native-website
Length of output: 109
🏁 Script executed:
# Search for sendAccessibilityEvent in the codebase
rg "sendAccessibilityEvent" --type ts --type tsx -A 3 -B 1Repository: reactnativecn/react-native-website
Length of output: 105
🏁 Script executed:
# Search for sendAccessibilityEvent in all files
rg "sendAccessibilityEvent" -A 3 -B 1Repository: reactnativecn/react-native-website
Length of output: 50392
🏁 Script executed:
# Look for TypeScript definition files
fd -e "d.ts" | head -20Repository: reactnativecn/react-native-website
Length of output: 203
🏁 Script executed:
# Search specifically in type definition or source files
rg "sendAccessibilityEvent" --type typescript -A 3 -B 1Repository: reactnativecn/react-native-website
Length of output: 112
🏁 Script executed:
# Check English version of docs for comparison
cat -n docs/accessibilityinfo.md | sed -n '275,290p'Repository: reactnativecn/react-native-website
Length of output: 985
🏁 Script executed:
# Search for AccessibilityInfo interface/type definition
rg "interface AccessibilityInfo|class AccessibilityInfo|type AccessibilityInfo" -A 15Repository: reactnativecn/react-native-website
Length of output: 60
🏁 Script executed:
# Look for any .d.ts files that might contain type definitions
find . -name "*.d.ts" -type f | head -10Repository: reactnativecn/react-native-website
Length of output: 209
🏁 Script executed:
# Search for any React Native type definitions or imports in the docs
rg "HostInstance|AccessibilityEventTypes" -A 2 -B 2 | head -50Repository: reactnativecn/react-native-website
Length of output: 5145
🏁 Script executed:
# Check if there are any actual source files beyond documentation
find . -path ./node_modules -prune -o -name "*.ts" -o -name "*.tsx" | grep -v node_modules | grep -v versioned_docs | head -20Repository: reactnativecn/react-native-website
Length of output: 854
🏁 Script executed:
# Check if other methods in the same file have return types specified
cat -n cndocs/accessibilityinfo.md | sed -n '200,350p' | grep -E "static|function|\(" | head -20Repository: reactnativecn/react-native-website
Length of output: 1030
🏁 Script executed:
# Check broader context around sendAccessibilityEvent - look for other method signatures
rg "static \w+\(" cndocs/accessibilityinfo.md -A 1 -B 1Repository: reactnativecn/react-native-website
Length of output: 1254
Add explicit return type : void to sendAccessibilityEvent signature.
Line 281: The method signature lacks an explicit return type annotation. While other void-returning methods in the same file (announceForAccessibility, setAccessibilityFocus) follow the same pattern, explicitly declaring : void improves clarity and consistency with Promise-returning methods in the documentation.
✏️ Suggested fix
-static sendAccessibilityEvent(host: HostInstance, eventType: AccessibilityEventTypes);
+static sendAccessibilityEvent(
+ host: HostInstance,
+ eventType: AccessibilityEventTypes,
+): void;📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| ```tsx | |
| static sendAccessibilityEvent(host: HostInstance, eventType: AccessibilityEventTypes); | |
| ``` | |
| static sendAccessibilityEvent( | |
| host: HostInstance, | |
| eventType: AccessibilityEventTypes, | |
| ): void; |
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@cndocs/accessibilityinfo.md` around lines 280 - 282, The method signature for
sendAccessibilityEvent is missing an explicit return type; update the
declaration of sendAccessibilityEvent(host: HostInstance, eventType:
AccessibilityEventTypes) to include an explicit void return annotation (i.e.,
append : void) to match other void-returning methods like
announceForAccessibility and setAccessibilityFocus and improve clarity and
consistency.
| {Object.entries(dimensions.window).map(([key, value]) => ( | ||
| <Text> | ||
| {key} - {value} | ||
| </Text> | ||
| ))} | ||
| <Text style={styles.header}>Screen Dimensions</Text> | ||
| {Object.entries(dimensions.screen).map(([key, value]) => ( | ||
| <Text> | ||
| {key} - {value} | ||
| </Text> |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
# First, check if the file exists and examine its content around lines 57-66
head -70 cndocs/dimensions.md | tail -20Repository: reactnativecn/react-native-website
Length of output: 621
🏁 Script executed:
# Check the file type and context
head -20 cndocs/dimensions.mdRepository: reactnativecn/react-native-website
Length of output: 450
🏁 Script executed:
# Get the full context around lines 57-66 with line numbers
sed -n '50,75p' cndocs/dimensions.md | cat -nRepository: reactnativecn/react-native-website
Length of output: 911
Add stable key props to the mapped <Text> nodes.
Both Object.entries(...).map() blocks render lists without keys, which will trigger React warnings. Documentation examples should demonstrate best practices.
Proposed fix
- {Object.entries(dimensions.window).map(([key, value]) => (
- <Text>
+ {Object.entries(dimensions.window).map(([key, value]) => (
+ <Text key={`window-${key}`}>
{key} - {value}
</Text>
))}
<Text style={styles.header}>Screen Dimensions</Text>
- {Object.entries(dimensions.screen).map(([key, value]) => (
- <Text>
+ {Object.entries(dimensions.screen).map(([key, value]) => (
+ <Text key={`screen-${key}`}>
{key} - {value}
</Text>
))}📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| {Object.entries(dimensions.window).map(([key, value]) => ( | |
| <Text> | |
| {key} - {value} | |
| </Text> | |
| ))} | |
| <Text style={styles.header}>Screen Dimensions</Text> | |
| {Object.entries(dimensions.screen).map(([key, value]) => ( | |
| <Text> | |
| {key} - {value} | |
| </Text> | |
| {Object.entries(dimensions.window).map(([key, value]) => ( | |
| <Text key={`window-${key}`}> | |
| {key} - {value} | |
| </Text> | |
| ))} | |
| <Text style={styles.header}>Screen Dimensions</Text> | |
| {Object.entries(dimensions.screen).map(([key, value]) => ( | |
| <Text key={`screen-${key}`}> | |
| {key} - {value} | |
| </Text> |
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@cndocs/dimensions.md` around lines 57 - 66, The mapped Text nodes rendering
Object.entries(dimensions.window) and Object.entries(dimensions.screen) lack
stable key props causing React warnings; update both map callbacks (the
expressions using Object.entries(dimensions.window).map and
Object.entries(dimensions.screen).map) to add a unique key prop—e.g., use the
entry key (key) or a combined string like `${key}-window` / `${key}-screen`—on
each <Text> element so each rendered list item has a stable React key.
| ```bash | ||
| # from the ios folder | ||
| bundle exec pod install | ||
| open SampleApp.xcworkspace |
There was a problem hiding this comment.
Keep the workspace name consistent with the rest of the tutorial.
Earlier steps open TurboModuleExample.xcworkspace at Line 18, but this command switches to SampleApp.xcworkspace. Following the guide verbatim will point readers at the wrong workspace name.
Proposed fix
-open SampleApp.xcworkspace
+open TurboModuleExample.xcworkspace🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@cndocs/turbo-native-modules-ios.md` around lines 155 - 158, The workspace
name in the iOS command snippet is inconsistent: replace the reference to
SampleApp.xcworkspace with TurboModuleExample.xcworkspace so it matches the
earlier step that opens TurboModuleExample.xcworkspace; update the `open`
command in the block so the snippet uses `TurboModuleExample.xcworkspace` while
keeping the preceding `bundle exec pod install` line unchanged.
| upstream_epoch=$(git log -1 --format="%ct" upstream/main -- "$source" 2>/dev/null || echo 0) | ||
| translation_epoch=$(git log -1 --format="%ct" production -- "$target" 2>/dev/null || echo 0) | ||
|
|
||
| # Fallback for translations not yet present on production. | ||
| if [ "$translation_epoch" -eq 0 ] 2>/dev/null; then | ||
| translation_epoch=$(git log -1 --format="%ct" -- "$target" 2>/dev/null || echo 0) | ||
| fi |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
# First, let's find and read the script file
find . -name "sync-translations.sh" -type fRepository: reactnativecn/react-native-website
Length of output: 108
🏁 Script executed:
# Test git log behavior when ref exists but path has no commits
# This tests the core claim of the review comment
python3 << 'EOF'
import subprocess
import tempfile
import os
import shutil
# Create a temporary git repo to test the behavior
tmpdir = tempfile.mkdtemp()
os.chdir(tmpdir)
# Initialize repo with two branches
subprocess.run(['git', 'init'], check=True, capture_output=True)
subprocess.run(['git', 'config', 'user.email', 'test@test.com'], check=True, capture_output=True)
subprocess.run(['git', 'config', 'user.name', 'Test User'], check=True, capture_output=True)
# Create initial commit on main
with open('file.txt', 'w') as f:
f.write('content')
subprocess.run(['git', 'add', 'file.txt'], check=True, capture_output=True)
subprocess.run(['git', 'commit', '-m', 'initial'], check=True, capture_output=True)
# Create production branch but don't add the target file there
subprocess.run(['git', 'checkout', '-b', 'production'], check=True, capture_output=True)
with open('other.txt', 'w') as f:
f.write('other')
subprocess.run(['git', 'add', 'other.txt'], check=True, capture_output=True)
subprocess.run(['git', 'commit', '-m', 'production commit'], check=True, capture_output=True)
# Now test git log on a path that doesn't exist on production
result = subprocess.run(
['git', 'log', '-1', '--format=%ct', 'production', '--', 'target_file.txt'],
capture_output=True,
text=True
)
print(f"Exit code: {result.returncode}")
print(f"Stdout: '{result.stdout}'")
print(f"Stderr: '{result.stderr}'")
print(f"Stdout is empty: {result.stdout == ''}")
print(f"Stdout after strip: '{result.stdout.strip()}'")
os.chdir('/')
shutil.rmtree(tmpdir)
EOFRepository: reactnativecn/react-native-website
Length of output: 157
🏁 Script executed:
# Test bash behavior with empty variable assignment and -eq comparison
bash << 'EOF'
# Test 1: What happens when command substitution produces empty output?
var=$(echo "")
echo "Test 1 - Empty echo:"
echo " var='$var'"
echo " var is unset: $([[ -z $var ]] && echo yes || echo no)"
# Test 2: What does -eq 0 do with empty string?
var=""
echo ""
echo "Test 2 - -eq comparison with empty string:"
if [ "$var" -eq 0 ] 2>/dev/null; then
echo " [ \"\$var\" -eq 0 ] returned true"
else
echo " [ \"\$var\" -eq 0 ] returned false"
fi
# Test 3: What about unset variable?
unset var
echo ""
echo "Test 3 - -eq comparison with unset variable:"
if [ "$var" -eq 0 ] 2>/dev/null; then
echo " [ \"\$var\" -eq 0 ] returned true"
else
echo " [ \"\$var\" -eq 0 ] returned false"
fi
# Test 4: Using :- operator
var=""
result=${var:-0}
echo ""
echo "Test 4 - Using :- operator with empty string:"
echo " \${var:-0} = '$result'"
EOFRepository: reactnativecn/react-native-website
Length of output: 350
🏁 Script executed:
# Now let's examine the actual script at the problematic lines
if [ -f scripts/sync-translations.sh ]; then
echo "=== Reading scripts/sync-translations.sh, lines 60-75 ==="
sed -n '60,75p' scripts/sync-translations.sh
fiRepository: reactnativecn/react-native-website
Length of output: 939
🏁 Script executed:
# Let's see where the epoch values are used in the script
sed -n '1,100p' scripts/sync-translations.sh | head -100Repository: reactnativecn/react-native-website
Length of output: 3122
🏁 Script executed:
# Search for where upstream_epoch and translation_epoch are compared
grep -n "upstream_epoch\|translation_epoch" scripts/sync-translations.sh | head -20Repository: reactnativecn/react-native-website
Length of output: 567
🏁 Script executed:
# Let's look at the full context of how these variables are used
sed -n '63,95p' scripts/sync-translations.shRepository: reactnativecn/react-native-website
Length of output: 1429
Fix empty git log output handling to ensure fallback logic executes correctly.
When git log -1 --format="%ct" production -- "$target" finds no commits for a path on the production branch, it returns exit code 0 with empty output. The || echo 0 fallback does not execute because the command succeeds. The empty string then fails the -eq 0 comparison at line 67, silently skipping the intended fallback to the current branch. The same issue affects the -gt comparisons at lines 77 and 85, which treat empty epoch values as false, causing the script to incorrectly classify files as "up to date" when they should be flagged for resync. The date fallback at lines 73–74 is also affected.
Proposed fix
-upstream_epoch=$(git log -1 --format="%ct" upstream/main -- "$source" 2>/dev/null || echo 0)
-translation_epoch=$(git log -1 --format="%ct" production -- "$target" 2>/dev/null || echo 0)
+upstream_epoch=$(git log -1 --format="%ct" upstream/main -- "$source" 2>/dev/null || true)
+upstream_epoch=${upstream_epoch:-0}
+translation_epoch=$(git log -1 --format="%ct" production -- "$target" 2>/dev/null || true)
+translation_epoch=${translation_epoch:-0}
-# Fallback for translations not yet present on production.
-if [ "$translation_epoch" -eq 0 ] 2>/dev/null; then
- translation_epoch=$(git log -1 --format="%ct" -- "$target" 2>/dev/null || echo 0)
+# Fallback for translations not yet present on production.
+if [ "$translation_epoch" -eq 0 ]; then
+ translation_epoch=$(git log -1 --format="%ct" -- "$target" 2>/dev/null || true)
+ translation_epoch=${translation_epoch:-0}
fi📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| upstream_epoch=$(git log -1 --format="%ct" upstream/main -- "$source" 2>/dev/null || echo 0) | |
| translation_epoch=$(git log -1 --format="%ct" production -- "$target" 2>/dev/null || echo 0) | |
| # Fallback for translations not yet present on production. | |
| if [ "$translation_epoch" -eq 0 ] 2>/dev/null; then | |
| translation_epoch=$(git log -1 --format="%ct" -- "$target" 2>/dev/null || echo 0) | |
| fi | |
| upstream_epoch=$(git log -1 --format="%ct" upstream/main -- "$source" 2>/dev/null || true) | |
| upstream_epoch=${upstream_epoch:-0} | |
| translation_epoch=$(git log -1 --format="%ct" production -- "$target" 2>/dev/null || true) | |
| translation_epoch=${translation_epoch:-0} | |
| # Fallback for translations not yet present on production. | |
| if [ "$translation_epoch" -eq 0 ]; then | |
| translation_epoch=$(git log -1 --format="%ct" -- "$target" 2>/dev/null || true) | |
| translation_epoch=${translation_epoch:-0} | |
| fi |
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@scripts/sync-translations.sh` around lines 63 - 69, The script's git log
assignments (e.g., upstream_epoch and translation_epoch) can be empty even
though the command exits 0, so the numeric comparisons fail; change the capture
to explicitly default empty output to 0 (for example: run git log -1
--format="%ct" ... into a variable, then set variable=${variable:-0}) and apply
the same pattern to any other epoch captures and the date fallback so the
subsequent -eq and -gt numeric comparisons work correctly (update the usages
around upstream_epoch, translation_epoch and any other epoch/date variables in
sync-translations.sh).
Summary
Updated files
Notes
sync-translations.sh在改动合入production前,仍可能继续将这些文件列为候选,这是基于production分支时间戳的当前脚本行为。Test Plan
Summary by CodeRabbit
New Features
Documentation
Chores