Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 17 additions & 5 deletions packages/react-native/Libraries/Components/Button.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,22 +156,30 @@ type ButtonPropsCore = Readonly<{
accessibilityLanguage?: ?Stringish,
}>;

/** @build-types emit-as-interface Uniwind compatibility */
/**
* Button is deprecated and will be removed in a future release.
* Build your own button with `Pressable` instead.
* @see https://reactnative.dev/docs/pressable
* @deprecated
* @build-types emit-as-interface Uniwind compatibility
*/
export type ButtonProps = ButtonPropsCore;

const NativeTouchable:
typeof TouchableNativeFeedback | typeof TouchableOpacity =
Platform.OS === 'android' ? TouchableNativeFeedback : TouchableOpacity;

/**
* Button is deprecated and will be removed in a future release.
* Build your own button with `Pressable` instead.
* @deprecated
*/
export type ButtonInstance = React.ElementRef<typeof NativeTouchable>;

/**
* A basic button component that should render nicely on any platform. Supports a
* minimal level of customization.
*
* If this button doesn't look right for your app, you can build your own button
* using `Pressable`.
*
* Example:
*
* ```tsx
Expand All @@ -183,7 +191,11 @@ export type ButtonInstance = React.ElementRef<typeof NativeTouchable>;
* />
* ```
*
* @see https://reactnative.dev/docs/button
* Button is deprecated and will be removed in a future release.
* Build your own button with `Pressable` instead.
*
* @see https://reactnative.dev/docs/pressable
* @deprecated
*/
const Button: component(
ref?: React.RefSetter<ButtonInstance>,
Expand Down
11 changes: 11 additions & 0 deletions packages/react-native/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,19 @@ module.exports = {
return require('./Libraries/Components/ActivityIndicator/ActivityIndicator')
.default;
},
/**
* @deprecated Button is deprecated and will be removed in a future release.
* Build your own button with Pressable instead.
* See https://reactnative.dev/docs/pressable
*/
// $FlowFixMe[unsafe-getters-setters]
get Button() {
warnOnce(
'button-deprecated',
'Button is deprecated and will be removed in a future release. ' +
'Build your own button with Pressable instead. ' +
'See https://reactnative.dev/docs/pressable',
);
return require('./Libraries/Components/Button').default;
},
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@
import type {RNTesterModuleExample} from '../../types/RNTesterTypes';
import type {SafeAreaInsetsChangeEvent} from 'react-native';

import RNTesterButton from '../../components/RNTesterButton';
import RNTesterText from '../../components/RNTesterText';
import * as React from 'react';
import {useCallback, useState} from 'react';
import {
Button,
Modal,
Platform,
ScrollView,
Expand Down Expand Up @@ -105,13 +105,15 @@ function FullScreenModalContent({onClose}: {onClose: () => void}): React.Node {
the same frame, without the content jumping.
</RNTesterText>
{!applied ? (
<Button onPress={() => setApplied(true)} title="Apply insets" />
<RNTesterButton onPress={() => setApplied(true)}>
Apply insets
</RNTesterButton>
) : null}
<TextInput
placeholder="Focus to show the keyboard"
style={styles.keyboardProbe}
/>
<Button onPress={onClose} title="Close" />
<RNTesterButton onPress={onClose}>Close</RNTesterButton>
</View>
</View>
);
Expand All @@ -129,10 +131,9 @@ function FullScreenExample(): React.Node {
supportedOrientations={['portrait', 'landscape']}>
<FullScreenModalContent onClose={() => setModalVisible(false)} />
</Modal>
<Button
onPress={() => setModalVisible(true)}
title="Present a full screen modal"
/>
<RNTesterButton onPress={() => setModalVisible(true)}>
Present a full screen modal
</RNTesterButton>
</View>
);
}
Expand Down Expand Up @@ -174,9 +175,11 @@ function FeedbackLoopModalContent({
a second, once, while the counter keeps climbing.
</RNTesterText>
{!looping ? (
<Button onPress={() => setLooping(true)} title="Start the loop" />
<RNTesterButton onPress={() => setLooping(true)}>
Start the loop
</RNTesterButton>
) : null}
<Button onPress={onClose} title="Close" />
<RNTesterButton onPress={onClose}>Close</RNTesterButton>
</View>
</View>
);
Expand All @@ -194,10 +197,9 @@ function FeedbackLoopExample(): React.Node {
supportedOrientations={['portrait', 'landscape']}>
<FeedbackLoopModalContent onClose={() => setModalVisible(false)} />
</Modal>
<Button
onPress={() => setModalVisible(true)}
title="Present a view that loops"
/>
<RNTesterButton onPress={() => setModalVisible(true)}>
Present a view that loops
</RNTesterButton>
</View>
);
}
Expand Down Expand Up @@ -313,7 +315,7 @@ component GeometryModal(
bottom: (rootInsets?.bottom ?? 0) + 12,
right: 12,
}}>
<Button title="Close" onPress={onClose} />
<RNTesterButton onPress={onClose}>Close</RNTesterButton>
</View>
</View>
);
Expand All @@ -324,20 +326,20 @@ component GeometryExample() {
const [cancellingRotations, setCancellingRotations] = useState(false);
return (
<View>
<Button
title="Scale 2"
<RNTesterButton
onPress={() => {
setCancellingRotations(false);
setVisible(true);
}}
/>
<Button
title="Cancel rotations"
}}>
Scale 2
</RNTesterButton>
<RNTesterButton
onPress={() => {
setCancellingRotations(true);
setVisible(true);
}}
/>
}}>
Cancel rotations
</RNTesterButton>
<Modal
visible={visible}
statusBarTranslucent
Expand Down Expand Up @@ -398,22 +400,22 @@ function ScrollBenchmark(): React.Node {
<View style={styles.bench}>
<View style={styles.benchControls}>
{[0, 1, 50].map(count => (
<Button
<RNTesterButton
key={count}
title={`${count} observers`}
onPress={() => {
benchEventCount = 0;
setObserverCount(count);
}}
/>
}}>
{count} observers
</RNTesterButton>
))}
<Button
title="Read counters"
<RNTesterButton
onPress={() => {
setEventCount(benchEventCount);
setRenderCount(c => c + 1);
}}
/>
}}>
Read counters
</RNTesterButton>
</View>
<RNTesterText>
{`observers: ${observerCount}, inset events since change: ${eventCount} (read ${renderCount})`}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ it.each([
try {
const renderer = await create(<Example />);
mountedRenderer = renderer;
const button = renderer.root.findByProps({title});
const button = renderer.root.findByProps({children: title});
await TestRenderer.act(() => button.props.onPress());
const root = renderer.root.findByProps({
testID: 'safe-area-geometry-root',
Expand Down Expand Up @@ -145,7 +145,7 @@ it.each([
expect(StyleSheet.flatten(observer.props.style)).toEqual(
expectedObserverStyle,
);
const close = renderer.root.findByProps({title: 'Close'});
const close = renderer.root.findByProps({children: 'Close'});
await TestRenderer.act(() => close.props.onPress());
expect(renderer.root.findByType(Modal).props.visible).toBe(false);
} finally {
Expand Down
Loading