Skip to content
This repository was archived by the owner on Dec 3, 2024. It is now read-only.

Commit b65d7af

Browse files
committed
Add support for react-navigation@5
1 parent d834bee commit b65d7af

File tree

3 files changed

+36
-16
lines changed

3 files changed

+36
-16
lines changed

src/Header.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,19 @@ import {
77
StyleSheet,
88
View,
99
} from 'react-native';
10-
import { withNavigation } from 'react-navigation';
11-
import { HeaderBackButton } from 'react-navigation-stack';
10+
11+
import { HeaderBackButton } from '@react-navigation/stack';
1212
import { getInset, getStatusBarHeight } from 'react-native-safe-area-view';
1313
import { isIphoneX } from 'react-native-iphone-x-helper';
14+
import { useNavigation } from '@react-navigation/native';
1415

1516
// @todo: make this work properly when in landscape
1617
const hasNotch = isIphoneX();
1718

1819
const APPBAR_HEIGHT = Platform.OS === 'ios' ? 50 : 56;
1920
const TITLE_OFFSET = Platform.OS === 'ios' ? 70 : 56;
2021

21-
@withNavigation
22-
export default class Header extends React.PureComponent {
22+
class Header extends React.PureComponent {
2323
constructor(props) {
2424
super(props);
2525

@@ -136,3 +136,11 @@ export default class Header extends React.PureComponent {
136136
);
137137
}
138138
}
139+
140+
export default function (props) {
141+
const navigation = useNavigation();
142+
143+
return (
144+
<Header {...props} navigation={navigation} />
145+
);
146+
}

src/SearchBar.ios.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ import {
1010
TouchableWithoutFeedback,
1111
View,
1212
} from 'react-native';
13-
import { withNavigation } from 'react-navigation';
1413
import Ionicons from 'react-native-vector-icons/Ionicons';
14+
import { useNavigation } from '@react-navigation/native';
1515

1616
const Layout = {
1717
window: {
@@ -28,7 +28,6 @@ const SearchIcon = () => (
2828
</View>
2929
);
3030

31-
@withNavigation
3231
class PlaceholderButtonSearchBar extends React.PureComponent {
3332
static defaultProps = {
3433
placeholder: 'Search',
@@ -62,8 +61,7 @@ class PlaceholderButtonSearchBar extends React.PureComponent {
6261
};
6362
}
6463

65-
@withNavigation
66-
export default class SearchBar extends React.PureComponent {
64+
class SearchBar extends React.PureComponent {
6765
state = {
6866
text: '',
6967
showCancelButton: false,
@@ -183,6 +181,14 @@ export default class SearchBar extends React.PureComponent {
183181
};
184182
}
185183

184+
export default function (props) {
185+
const navigation = useNavigation();
186+
187+
return (
188+
<SearchBar {...props} navigation={navigation} />
189+
);
190+
}
191+
186192
const styles = StyleSheet.create({
187193
container: {
188194
flex: 1,

src/SearchBar.js

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
import React from 'react';
2-
import { NativeModules, StyleSheet, TextInput, View } from 'react-native';
3-
import { withNavigation } from 'react-navigation';
4-
import Touchable from 'react-native-platform-touchable';
2+
import { NativeModules, StyleSheet, TextInput, TouchableNativeFeedback, View } from 'react-native';
53
import Ionicons from 'react-native-vector-icons/Ionicons';
4+
import { useNavigation } from '@react-navigation/native';
65

7-
@withNavigation
8-
export default class SearchBar extends React.PureComponent {
6+
class SearchBar extends React.PureComponent {
97
componentDidMount() {
108
requestAnimationFrame(() => {
119
this._textInput.focus();
@@ -42,17 +40,17 @@ export default class SearchBar extends React.PureComponent {
4240
<View
4341
style={{ width: 50, alignItems: 'center', justifyContent: 'center' }}>
4442
{this.state.text
45-
? <Touchable
43+
? <TouchableNativeFeedback
4644
onPress={this._handleClear}
4745
hitSlop={{top: 15, left: 10, right: 15, bottom: 15}}
4846
style={{ padding: 5 }}
49-
background={Touchable.Ripple(this.props.tintColor, true)}>
47+
background={TouchableNativeFeedback.Ripple(this.props.tintColor, true)}>
5048
<Ionicons
5149
name="md-close"
5250
size={25}
5351
color={this.props.tintColor}
5452
/>
55-
</Touchable>
53+
</TouchableNativeFeedback>
5654
: null}
5755
</View>
5856
</View>
@@ -74,6 +72,14 @@ export default class SearchBar extends React.PureComponent {
7472
};
7573
}
7674

75+
export default function (props) {
76+
const navigation = useNavigation();
77+
78+
return (
79+
<SearchBar {...props} navigation={navigation} />
80+
);
81+
}
82+
7783
const styles = StyleSheet.create({
7884
container: {
7985
flex: 1,

0 commit comments

Comments
 (0)