mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Summary: Add explicit annotations to React hook callbacks as required for Flow's Local Type Inference project. This codemod prepares the codebase to match Flow's new typechecking algorithm. The new algorithm will make Flow more reliable and predictable. This diff adds `any` or `$FlowFixMe` in cases where more precise types could not be determined. Details: - Codemod script: `.facebook/flowd codemod annotate-react-hooks ../../xplat/js --default-any --write` - Local Type Inference announcement: [post](https://fb.workplace.com/groups/flowlang/posts/788206301785035) - Support group: [Flow Support](https://fb.workplace.com/groups/flow) drop-conflicts bypass-lint Reviewed By: SamChou19815 Differential Revision: D41231214 fbshipit-source-id: d5f5ce8d61020baa1138292c9e9f1c69dffd324c
98 lines
2.1 KiB
JavaScript
98 lines
2.1 KiB
JavaScript
/**
|
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*
|
|
* @flow strict-local
|
|
* @format
|
|
*/
|
|
|
|
import * as React from 'react';
|
|
import {
|
|
Button,
|
|
Pressable,
|
|
ScrollView,
|
|
StyleSheet,
|
|
Text,
|
|
View,
|
|
} from 'react-native';
|
|
|
|
function StickyHeader() {
|
|
const [backgroundColor, setBackgroundColor] = React.useState('blue');
|
|
return (
|
|
<View
|
|
key={0}
|
|
style={{
|
|
backgroundColor: backgroundColor,
|
|
margin: 10,
|
|
width: 500,
|
|
height: 100,
|
|
}}>
|
|
<Pressable
|
|
style={{flex: 1}}
|
|
onPress={() => {
|
|
setBackgroundColor(backgroundColor === 'blue' ? 'yellow' : 'blue');
|
|
}}
|
|
testID="pressable_header">
|
|
<Text>Press to change color</Text>
|
|
</Pressable>
|
|
</View>
|
|
);
|
|
}
|
|
|
|
function renderComponent1(i: number) {
|
|
return (
|
|
<View
|
|
key={i}
|
|
style={{backgroundColor: 'red', margin: 10, width: 500, height: 100}}
|
|
/>
|
|
);
|
|
}
|
|
|
|
export default function ScrollViewPressableStickyHeaderExample(): React.Node {
|
|
const scrollRef = React.useRef<$FlowFixMe>(null);
|
|
const components = [];
|
|
for (var i = 1; i < 10; i++) {
|
|
components.push(renderComponent1(i));
|
|
}
|
|
return (
|
|
<View style={styles.container}>
|
|
<ScrollView
|
|
nestedScrollEnabled={true}
|
|
ref={scrollRef}
|
|
style={{flex: 1}}
|
|
stickyHeaderIndices={[0]}
|
|
showsVerticalScrollIndicator={false}
|
|
testID="scroll_pressable_sticky_header">
|
|
<StickyHeader />
|
|
{components}
|
|
</ScrollView>
|
|
<View>
|
|
<Button
|
|
title="scroll to top"
|
|
onPress={() => {
|
|
scrollRef.current?.scrollTo({y: 0});
|
|
}}
|
|
testID="scroll_to_top_button"
|
|
/>
|
|
<Button
|
|
title="scroll to bottom"
|
|
onPress={() => {
|
|
scrollRef.current?.scrollToEnd();
|
|
}}
|
|
testID="scroll_to_bottom_button"
|
|
/>
|
|
</View>
|
|
</View>
|
|
);
|
|
}
|
|
|
|
const styles = StyleSheet.create({
|
|
container: {
|
|
padding: 10,
|
|
paddingTop: 30,
|
|
flex: 1,
|
|
},
|
|
});
|