Files
react-native/packages/rn-tester/js/examples/DrawerLayoutAndroid/DrawerLayoutAndroidExample.js
T
Mike Vitousek 8c2a4d0d26 Annotate React hooks in xplat, defaulting to any
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
2022-11-11 17:04:38 -08:00

102 lines
2.3 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.
*
* @format
* @flow
*/
'use strict';
import type {Node} from 'react';
import React, {useRef, useState} from 'react';
import {
Button,
DrawerLayoutAndroid,
StyleSheet,
Text,
View,
} from 'react-native';
const Drawer = () => {
const drawer = useRef<null | React$ElementRef<any>>(null);
const [drawerPosition, setDrawerPosition] = useState('left');
const changeDrawerPosition = () => {
if (drawerPosition === 'left') {
setDrawerPosition('right');
} else {
setDrawerPosition('left');
}
};
const navigationView = () => (
<View style={[styles.container, styles.navigationContainer]}>
<Text style={styles.paragraph}>I'm in the Drawer!</Text>
<Button
title="Close drawer"
/* $FlowFixMe */
onPress={() => drawer.current.closeDrawer()}
/>
</View>
);
return (
<DrawerLayoutAndroid
/* $FlowFixMe */
ref={drawer}
accessibilityRole="drawerlayout"
drawerWidth={300}
drawerPosition={drawerPosition}
renderNavigationView={navigationView}>
<View style={styles.container}>
<Text style={styles.paragraph}>Drawer on the {drawerPosition}!</Text>
<Button
title="Change Drawer Position"
onPress={() => changeDrawerPosition()}
/>
<Text style={styles.paragraph}>
Swipe from the side or press button below to see it!
</Text>
<Button
title="Open drawer"
/* $FlowFixMe */
onPress={() => drawer.current.openDrawer()}
/>
</View>
</DrawerLayoutAndroid>
);
};
const styles = StyleSheet.create({
container: {
flex: 1,
alignItems: 'center',
justifyContent: 'center',
padding: 16,
},
navigationContainer: {
backgroundColor: '#ecf0f1',
},
paragraph: {
padding: 16,
fontSize: 15,
textAlign: 'center',
},
});
exports.title = 'DrawerLayoutAndroid';
exports.documentationURL =
'https://reactnative.dev/docs/next/drawerlayoutandroid';
exports.description = 'Drawer Example';
exports.examples = [
{
title: 'Drawer Example',
render(): Node {
return <Drawer />;
},
},
];