Skip to content

Commit

Permalink
feat: add preventDefault functionality in material bottom tabs
Browse files Browse the repository at this point in the history
  • Loading branch information
satya164 committed Jan 22, 2020
1 parent 63988e0 commit 3dede31
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 10 deletions.
2 changes: 1 addition & 1 deletion example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"react-dom": "~16.9.0",
"react-native": "~0.61.5",
"react-native-gesture-handler": "~1.5.3",
"react-native-paper": "^3.4.0",
"react-native-paper": "^3.5.0",
"react-native-reanimated": "^1.4.0",
"react-native-safe-area-context": "^0.6.2",
"react-native-screens": "^2.0.0-alpha.25",
Expand Down
4 changes: 2 additions & 2 deletions packages/material-bottom-tabs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,15 @@
"del-cli": "^3.0.0",
"react": "~16.9.0",
"react-native": "~0.61.5",
"react-native-paper": "^3.4.0",
"react-native-paper": "^3.5.0",
"react-native-vector-icons": "^6.6.0",
"typescript": "^3.7.4"
},
"peerDependencies": {
"@react-navigation/native": "^5.0.0-alpha.0",
"react": "*",
"react-native": "*",
"react-native-paper": "^3.0.0",
"react-native-paper": "^3.5.0",
"react-native-vector-icons": "^6.0.0"
},
"@react-native-community/bob": {
Expand Down
2 changes: 1 addition & 1 deletion packages/material-bottom-tabs/src/types.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export type MaterialBottomTabNavigationEventMap = {
/**
* Event which fires on tapping on the tab in the tab bar.
*/
tabPress: { data: undefined };
tabPress: { data: undefined; canPreventDefault: true };
};

export type MaterialBottomTabNavigationHelpers = NavigationHelpers<
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,16 @@ export default function MaterialBottomTabView({
descriptors[route.key].options.tabBarAccessibilityLabel
}
getTestID={({ route }) => descriptors[route.key].options.tabBarTestID}
onTabPress={({ route }) => {
navigation.emit({
onTabPress={({ route, preventDefault }) => {
const event = navigation.emit({
type: 'tabPress',
target: route.key,
canPreventDefault: true,
});

if (event.defaultPrevented) {
preventDefault();
}
}}
/>
);
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -13555,10 +13555,10 @@ react-native-iphone-x-helper@^1.2.1:
resolved "https://registry.yarnpkg.com/react-native-iphone-x-helper/-/react-native-iphone-x-helper-1.2.1.tgz#645e2ffbbb49e80844bb4cbbe34a126fda1e6772"
integrity sha512-/VbpIEp8tSNNHIvstuA3Swx610whci1Zpc9mqNkqn14DkMbw+ORviln2u0XyHG1kPvvwTNGZY6QpeFwxYaSdbQ==

react-native-paper@^3.4.0:
version "3.4.0"
resolved "https://registry.yarnpkg.com/react-native-paper/-/react-native-paper-3.4.0.tgz#b8d3643b33177ff41a2505aaa801d313defaf707"
integrity sha512-QVd6vZ4iJbUqp1OI1DY/0HwBS4y0SVixa2IeBIVyYM4ZZeoeOOlWCXdgtQk7tlf1ju5t1MJunyRGPOXOXTLGNg==
react-native-paper@^3.5.0:
version "3.5.0"
resolved "https://registry.yarnpkg.com/react-native-paper/-/react-native-paper-3.5.0.tgz#d74db26fa1714911ec1c9187c430726c680f4b52"
integrity sha512-W347plzhV/EsVzC8aT8se6s/jmIx1kSF7E4fpbptA950OHxb4gPFFruHZkffHTByLUiZEgKl3nXKqXkRDDp1UA==
dependencies:
"@callstack/react-theme-provider" "^3.0.5"
color "^3.1.2"
Expand Down

0 comments on commit 3dede31

Please sign in to comment.