Skip to content

Commit

Permalink
[change] Deprecate Touchables and Button components
Browse files Browse the repository at this point in the history
These components have been replaced by Pressable and will be removed
from React Native.

Fix #2382
  • Loading branch information
necolas committed Sep 1, 2022
1 parent 234a114 commit 87d35b4
Show file tree
Hide file tree
Showing 15 changed files with 51 additions and 277 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,15 @@ import * as ReactNativeModules from 'react-native-web/dist/cjs/index';
exports[`Rewrite react-native to react-native-web import from "react-native-web": import from "react-native-web" 1`] = `
import { unstable_createElement } from 'react-native-web';
import { StyleSheet, View, TouchableOpacity, processColor } from 'react-native-web';
import { StyleSheet, View, Pressable, processColor } from 'react-native-web';
import * as ReactNativeModules from 'react-native-web';
↓ ↓ ↓ ↓ ↓ ↓
import unstable_createElement from 'react-native-web/dist/exports/createElement';
import StyleSheet from 'react-native-web/dist/exports/StyleSheet';
import View from 'react-native-web/dist/exports/View';
import TouchableOpacity from 'react-native-web/dist/exports/TouchableOpacity';
import Pressable from 'react-native-web/dist/exports/Pressable';
import processColor from 'react-native-web/dist/exports/processColor';
import * as ReactNativeModules from 'react-native-web/dist/index';
Expand All @@ -90,7 +90,7 @@ exports[`Rewrite react-native to react-native-web require "react-native": requir
const ReactNative = require('react-native');
const { View } = require('react-native');
const { StyleSheet, TouchableOpacity } = require('react-native');
const { StyleSheet, Pressable } = require('react-native');
↓ ↓ ↓ ↓ ↓ ↓
Expand All @@ -100,8 +100,7 @@ const View = require('react-native-web/dist/exports/View').default;
const StyleSheet = require('react-native-web/dist/exports/StyleSheet').default;
const TouchableOpacity =
require('react-native-web/dist/exports/TouchableOpacity').default;
const Pressable = require('react-native-web/dist/exports/Pressable').default;
`;
Expand All @@ -110,7 +109,7 @@ exports[`Rewrite react-native to react-native-web require "react-native": requir
const ReactNative = require('react-native');
const { View } = require('react-native');
const { StyleSheet, TouchableOpacity } = require('react-native');
const { StyleSheet, Pressable } = require('react-native');
↓ ↓ ↓ ↓ ↓ ↓
Expand All @@ -121,8 +120,8 @@ const View = require('react-native-web/dist/cjs/exports/View').default;
const StyleSheet =
require('react-native-web/dist/cjs/exports/StyleSheet').default;
const TouchableOpacity =
require('react-native-web/dist/cjs/exports/TouchableOpacity').default;
const Pressable =
require('react-native-web/dist/cjs/exports/Pressable').default;
`;
Expand All @@ -131,7 +130,7 @@ exports[`Rewrite react-native to react-native-web require "react-native-web": re
const ReactNative = require('react-native-web');
const { unstable_createElement } = require('react-native-web');
const { StyleSheet, View, TouchableOpacity, processColor } = require('react-native-web');
const { StyleSheet, View, Pressable, processColor } = require('react-native-web');
↓ ↓ ↓ ↓ ↓ ↓
Expand All @@ -144,8 +143,7 @@ const StyleSheet = require('react-native-web/dist/exports/StyleSheet').default;
const View = require('react-native-web/dist/exports/View').default;
const TouchableOpacity =
require('react-native-web/dist/exports/TouchableOpacity').default;
const Pressable = require('react-native-web/dist/exports/Pressable').default;
const processColor =
require('react-native-web/dist/exports/processColor').default;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import * as ReactNativeModules from 'react-native';`,
{
title: 'import from "react-native-web"',
code: `import { unstable_createElement } from 'react-native-web';
import { StyleSheet, View, TouchableOpacity, processColor } from 'react-native-web';
import { StyleSheet, View, Pressable, processColor } from 'react-native-web';
import * as ReactNativeModules from 'react-native-web';`,
snapshot: true
},
Expand All @@ -45,22 +45,22 @@ export { StyleSheet, Text, unstable_createElement } from 'react-native-web';`,
title: 'require "react-native"',
code: `const ReactNative = require('react-native');
const { View } = require('react-native');
const { StyleSheet, TouchableOpacity } = require('react-native');`,
const { StyleSheet, Pressable } = require('react-native');`,
snapshot: true
},
{
title: 'require "react-native"',
code: `const ReactNative = require('react-native');
const { View } = require('react-native');
const { StyleSheet, TouchableOpacity } = require('react-native');`,
const { StyleSheet, Pressable } = require('react-native');`,
snapshot: true,
pluginOptions: { commonjs: true }
},
{
title: 'require "react-native-web"',
code: `const ReactNative = require('react-native-web');
const { unstable_createElement } = require('react-native-web');
const { StyleSheet, View, TouchableOpacity, processColor } = require('react-native-web');`,
const { StyleSheet, View, Pressable, processColor } = require('react-native-web');`,
snapshot: true
}
];
Expand Down
16 changes: 5 additions & 11 deletions packages/benchmarks/src/app/App.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
import Benchmark from './Benchmark';
import {
Picker,
StyleSheet,
ScrollView,
TouchableOpacity,
View
} from 'react-native';
import { Picker, StyleSheet, ScrollView, Pressable, View } from 'react-native';
import React, { Component } from 'react';
import Button from './Button';
import { IconClear, IconEye } from './Icons';
Expand Down Expand Up @@ -100,9 +94,9 @@ export default class App extends Component {
<View style={styles.grow}>
<View style={styles.listBar}>
<View style={styles.iconClearContainer}>
<TouchableOpacity onPress={this._handleClear}>
<Pressable onPress={this._handleClear}>
<IconClear />
</TouchableOpacity>
</Pressable>
</View>
</View>
<ScrollView ref={this._setScrollRef} style={styles.grow}>
Expand Down Expand Up @@ -134,9 +128,9 @@ export default class App extends Component {
viewPanel={
<View style={styles.viewPanel}>
<View style={styles.iconEyeContainer}>
<TouchableOpacity onPress={this._handleVisuallyHideBenchmark}>
<Pressable onPress={this._handleVisuallyHideBenchmark}>
<IconEye style={styles.iconEye} />
</TouchableOpacity>
</Pressable>
</View>

<Provider>
Expand Down
3 changes: 3 additions & 0 deletions packages/benchmarks/src/app/Button.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import { StyleSheet, TouchableHighlight, Text } from 'react-native';
import React, { Component } from 'react';
import { warnOnce } from '../../modules/warnOnce';

export default class Button extends Component<*> {
static displayName = '@app/Button';

render() {
warnOnce('Button', 'Button is deprecated. Please use Pressable.');

const {
accessibilityLabel,
color,
Expand Down
58 changes: 0 additions & 58 deletions packages/react-native-web-docs/src/pages/docs/components/button.md

This file was deleted.

This file was deleted.

36 changes: 0 additions & 36 deletions packages/react-native-web-examples/pages/button/index.js

This file was deleted.

6 changes: 3 additions & 3 deletions packages/react-native-web-examples/pages/flatlist/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import { StyleSheet } from 'react-native';
import Example from '../../shared/example';
import { FlatList, Text, TouchableOpacity, View } from 'react-native-web';
import { FlatList, Text, Pressable, View } from 'react-native-web';

const multiSelectData = ['First', 'Second', 'Third'].map((title, id) => ({
id,
Expand All @@ -18,13 +18,13 @@ class MyListItem extends React.PureComponent {
render() {
const textColor = this.props.selected ? 'red' : 'black';
return (
<TouchableOpacity onPress={this._onPress}>
<Pressable onPress={this._onPress}>
<View>
<Text style={[styles.listItemText, { color: textColor }]}>
{this.props.title}
</Text>
</View>
</TouchableOpacity>
</Pressable>
);
}
}
Expand Down
6 changes: 3 additions & 3 deletions packages/react-native-web-examples/pages/scroll-view/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
ScrollView,
StyleSheet,
Text,
TouchableOpacity,
Pressable,
View
} from 'react-native';
import Example from '../../shared/example';
Expand All @@ -13,9 +13,9 @@ const ITEMS = [...Array(12)].map((_, i) => `Item ${i}`);

function createItemRow(msg, index) {
return (
<TouchableOpacity key={index} style={[styles.item]}>
<Pressable key={index} style={[styles.item]}>
<Text style={styles.text}>{msg}</Text>
</TouchableOpacity>
</Pressable>
);
}

Expand Down
Loading

0 comments on commit 87d35b4

Please sign in to comment.