Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add Windows and macOS support #8570

Merged
merged 5 commits into from
Jul 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 11 additions & 5 deletions packages/drawer/src/views/Drawer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ const SPRING_CONFIG = {
restSpeedThreshold: 0.01,
};

const ANIMATED_ZERO = new Animated.Value(0);
const ANIMATED_ONE = new Animated.Value(1);

type Binary = 0 | 1;
Expand Down Expand Up @@ -103,7 +104,10 @@ export default class DrawerView extends React.Component<Props> {
drawerPosition: I18nManager.isRTL ? 'left' : 'right',
drawerType: 'front',
gestureEnabled: true,
swipeEnabled: Platform.OS !== 'web',
swipeEnabled:
Platform.OS !== 'web' &&
Platform.OS !== 'windows' &&
Platform.OS !== 'macos',
swipeEdgeWidth: 32,
swipeVelocityThreshold: 500,
keyboardDismissMode: 'on-drag',
Expand Down Expand Up @@ -577,19 +581,19 @@ export default class DrawerView extends React.Component<Props> {

const contentTranslateX =
drawerType === 'front' || drawerType === 'permanent'
? 0
? ANIMATED_ZERO
: this.translateX;

const drawerTranslateX =
drawerType === 'permanent'
? 0
? ANIMATED_ZERO
: drawerType === 'back'
? I18nManager.isRTL
? multiply(
sub(this.containerWidth, this.drawerWidth),
isRight ? 1 : -1
)
: 0
: ANIMATED_ZERO
: this.translateX;

const offset =
Expand Down Expand Up @@ -649,7 +653,9 @@ export default class DrawerView extends React.Component<Props> {
</View>
{
// Disable overlay if sidebar is permanent
drawerType === 'permanent' ? null : Platform.OS === 'web' ? (
drawerType === 'permanent' ? null : Platform.OS === 'web' ||
Platform.OS === 'windows' ||
Platform.OS === 'macos' ? (
<TouchableWithoutFeedback
onPress={
gestureEnabled ? () => this.toggleDrawer(false) : undefined
Expand Down
7 changes: 7 additions & 0 deletions packages/drawer/src/views/GestureHandler.macos.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export {
PanGestureHandler,
TapGestureHandler,
GestureHandlerRootView,
GestureState,
} from './GestureHandlerStub';
export type { PanGestureHandlerGestureEvent } from 'react-native-gesture-handler';
36 changes: 6 additions & 30 deletions packages/drawer/src/views/GestureHandler.tsx
Original file line number Diff line number Diff line change
@@ -1,31 +1,7 @@
import * as React from 'react';
import { View } from 'react-native';
import type {
PanGestureHandlerProperties,
TapGestureHandlerProperties,
} from 'react-native-gesture-handler';

const Dummy: any = ({ children }: { children: React.ReactNode }) => (
<>{children}</>
);

export const PanGestureHandler = Dummy as React.ComponentType<
PanGestureHandlerProperties
>;

export const TapGestureHandler = Dummy as React.ComponentType<
TapGestureHandlerProperties
>;

export const GestureHandlerRootView = View;

export const GestureState = {
UNDETERMINED: 0,
FAILED: 1,
BEGAN: 2,
CANCELLED: 3,
ACTIVE: 4,
END: 5,
};

export {
PanGestureHandler,
TapGestureHandler,
GestureHandlerRootView,
GestureState,
} from './GestureHandlerStub';
export type { PanGestureHandlerGestureEvent } from 'react-native-gesture-handler';
7 changes: 7 additions & 0 deletions packages/drawer/src/views/GestureHandler.windows.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export {
PanGestureHandler,
TapGestureHandler,
GestureHandlerRootView,
GestureState,
} from './GestureHandlerStub';
export type { PanGestureHandlerGestureEvent } from 'react-native-gesture-handler';
31 changes: 31 additions & 0 deletions packages/drawer/src/views/GestureHandlerStub.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import * as React from 'react';
import { View } from 'react-native';
import type {
PanGestureHandlerProperties,
TapGestureHandlerProperties,
} from 'react-native-gesture-handler';

const Dummy: any = ({ children }: { children: React.ReactNode }) => (
<>{children}</>
);

export const PanGestureHandler = Dummy as React.ComponentType<
PanGestureHandlerProperties
>;

export const TapGestureHandler = Dummy as React.ComponentType<
TapGestureHandlerProperties
>;

export const GestureHandlerRootView = View;

export const GestureState = {
UNDETERMINED: 0,
FAILED: 1,
BEGAN: 2,
CANCELLED: 3,
ACTIVE: 4,
END: 5,
};

export type { PanGestureHandlerGestureEvent } from 'react-native-gesture-handler';
9 changes: 8 additions & 1 deletion packages/drawer/src/views/Overlay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,14 @@ const Overlay = React.forwardRef(function Overlay(
) {
const animatedStyle = {
opacity: interpolate(progress, {
inputRange: [PROGRESS_EPSILON, 1],
// Default input range is [PROGRESS_EPSILON, 1]
// On Windows, the output value is 1 when input value is out of range for some reason
// The default value 0 will be interpolated to 1 in this case, which is not what we want.
// Therefore changing input range on Windows to [0,1] instead.
inputRange:
Platform.OS === 'windows' || Platform.OS === 'macos'
? [0, 1]
: [PROGRESS_EPSILON, 1],
outputRange: [0, 1],
}),
// We don't want the user to be able to press through the overlay when drawer is open
Expand Down
5 changes: 4 additions & 1 deletion packages/stack/src/navigators/createStackNavigator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ function StackNavigator({
}: Props) {
const defaultOptions = {
gestureEnabled: Platform.OS === 'ios',
animationEnabled: Platform.OS !== 'web',
animationEnabled:
Platform.OS !== 'web' &&
Platform.OS !== 'windows' &&
Platform.OS !== 'macos',
};

const { state, descriptors, navigation } = useNavigationBuilder<
Expand Down
6 changes: 6 additions & 0 deletions packages/stack/src/views/GestureHandler.macos.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export {
PanGestureHandler,
GestureHandlerRootView,
GestureState,
} from './GestureHandlerStub';
export type { PanGestureHandlerGestureEvent } from 'react-native-gesture-handler';
28 changes: 5 additions & 23 deletions packages/stack/src/views/GestureHandler.tsx
Original file line number Diff line number Diff line change
@@ -1,24 +1,6 @@
import * as React from 'react';
import { View } from 'react-native';
import type { PanGestureHandlerProperties } from 'react-native-gesture-handler';

const Dummy: any = ({ children }: { children: React.ReactNode }) => (
<>{children}</>
);

export const PanGestureHandler = Dummy as React.ComponentType<
PanGestureHandlerProperties
>;

export const GestureHandlerRootView = View;

export const GestureState = {
UNDETERMINED: 0,
FAILED: 1,
BEGAN: 2,
CANCELLED: 3,
ACTIVE: 4,
END: 5,
};

export {
PanGestureHandler,
GestureHandlerRootView,
GestureState,
} from './GestureHandlerStub';
export type { PanGestureHandlerGestureEvent } from 'react-native-gesture-handler';
6 changes: 6 additions & 0 deletions packages/stack/src/views/GestureHandler.windows.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export {
PanGestureHandler,
GestureHandlerRootView,
GestureState,
} from './GestureHandlerStub';
export type { PanGestureHandlerGestureEvent } from 'react-native-gesture-handler';
24 changes: 24 additions & 0 deletions packages/stack/src/views/GestureHandlerStub.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import * as React from 'react';
import { View } from 'react-native';
import type { PanGestureHandlerProperties } from 'react-native-gesture-handler';

const Dummy: any = ({ children }: { children: React.ReactNode }) => (
<>{children}</>
);

export const PanGestureHandler = Dummy as React.ComponentType<
PanGestureHandlerProperties
>;

export const GestureHandlerRootView = View;

export const GestureState = {
UNDETERMINED: 0,
FAILED: 1,
BEGAN: 2,
CANCELLED: 3,
ACTIVE: 4,
END: 5,
};

export type { PanGestureHandlerGestureEvent } from 'react-native-gesture-handler';
1 change: 1 addition & 0 deletions packages/stack/src/views/MaskedView.macos.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from './MaskedViewStub';
11 changes: 1 addition & 10 deletions packages/stack/src/views/MaskedView.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1 @@
import type * as React from 'react';

type Props = {
maskElement: React.ReactElement;
children: React.ReactElement;
};

export default function MaskedView({ children }: Props) {
return children;
}
export { default } from './MaskedViewStub';
1 change: 1 addition & 0 deletions packages/stack/src/views/MaskedView.windows.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from './MaskedViewStub';
10 changes: 10 additions & 0 deletions packages/stack/src/views/MaskedViewStub.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import type * as React from 'react';

type Props = {
maskElement: React.ReactElement;
children: React.ReactElement;
};

export default function MaskedView({ children }: Props) {
return children;
}
3 changes: 3 additions & 0 deletions packages/stack/src/views/TouchableItem.macos.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { TouchableOpacity } from 'react-native';

export const TouchableItem = (TouchableOpacity as any) as typeof import('./TouchableItem.native').TouchableItem;
3 changes: 3 additions & 0 deletions packages/stack/src/views/TouchableItem.windows.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { TouchableOpacity } from 'react-native';

export const TouchableItem = (TouchableOpacity as any) as typeof import('./TouchableItem.native').TouchableItem;