-
Notifications
You must be signed in to change notification settings - Fork 320
docs(cndocs): 同步最新上游 API 示例 #1043
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: production
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -136,13 +136,16 @@ export default App; | |
| <TabItem value="typescript"> | ||
|
|
||
| ```SnackPlayer name=Forwarding%20setNativeProps&ext=tsx | ||
| import {forwardRef, ElementRef} from 'react'; | ||
| import {Text, TouchableOpacity, View} from 'react-native'; | ||
|
|
||
| const MyButton = React.forwardRef<View, {label: string}>((props, ref) => ( | ||
| <View {...props} ref={ref} style={{marginTop: 50}}> | ||
| <Text>{props.label}</Text> | ||
| </View> | ||
| )); | ||
| const MyButton = forwardRef<ElementRef<typeof View>, {label: string}>( | ||
| (props, ref) => ( | ||
| <View {...props} ref={ref} style={{marginTop: 50}}> | ||
| <Text>{props.label}</Text> | ||
| </View> | ||
| ), | ||
| ); | ||
|
|
||
| const App = () => ( | ||
| <TouchableOpacity> | ||
|
|
@@ -224,8 +227,10 @@ import { | |
| View, | ||
| } from 'react-native'; | ||
|
|
||
| type TextInputInstance = React.ComponentRef<typeof TextInput>; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win Import Each block imports named values but no local 🤖 Prompt for AI Agents |
||
|
|
||
| const App = () => { | ||
| const inputRef = useRef<TextInput>(null); | ||
| const inputRef = useRef<TextInputInstance>(null); | ||
| const editText = useCallback(() => { | ||
| inputRef.current?.setNativeProps({text: 'Edited Text'}); | ||
| }, []); | ||
|
|
@@ -374,9 +379,12 @@ type Measurements = { | |
| height: number; | ||
| }; | ||
|
|
||
| type TextInstance = React.ComponentRef<typeof Text>; | ||
| type ViewInstance = React.ComponentRef<typeof View>; | ||
|
|
||
| const App = () => { | ||
| const textContainerRef = useRef<View>(null); | ||
| const textRef = useRef<Text>(null); | ||
| const textContainerRef = useRef<ViewInstance>(null); | ||
| const textRef = useRef<TextInstance>(null); | ||
| const [measure, setMeasure] = useState<Measurements | null>(null); | ||
|
|
||
| useEffect(() => { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
Repository: reactnativecn/react-native-website
Length of output: 11294
🌐 Web query:
site:reactnative.dev/docs/animations useNativeDriver width layout properties native driver Animated💡 Result:
In React Native, the Animated library's native driver (enabled via useNativeDriver: true) does not support animating layout properties, such as width, height, or other Flexbox and position-related styles [1][2][3]. The native driver is designed to run animations on the UI thread to ensure smooth performance by offloading work from the JavaScript thread [1][3]. Because of this architecture, it is currently limited to animating non-layout properties, primarily those that do not trigger a relayout of the component tree, such as transform (e.g., scale, rotation) and opacity [1][2][3]. If you need to animate layout properties like width or height, you have a few alternatives: 1. LayoutAnimation: This API is specifically designed for animating layout changes. It allows you to globally configure animations for the next render or layout cycle, making it ideal for Flexbox-based transitions without needing to manually calculate property changes [1][2]. 2. Animating via Transform: If possible, use the transform property (e.g., scaleX, scaleY) instead of changing the actual width or height. Animating transforms is supported by the native driver and is generally more performant than animating layout properties. 3. JavaScript-based Animations: If layout animation is strictly required and cannot be achieved via transforms or LayoutAnimation, you can perform the animation without useNativeDriver: true. Be aware that this runs on the JavaScript thread and may experience frame drops if the thread becomes blocked [1][2].
Citations:
Keep the carousel event on the JavaScript driver.
scrollXdrives the indicatorwidthstyle. The native driver does not support layout properties such aswidth, so the indicator cannot animate correctly withuseNativeDriver: true. KeepuseNativeDriver: false, or animate a supportedtransformoropacityproperty instead.Proposed fix
📝 Committable suggestion
🤖 Prompt for AI Agents