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 4 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
22 changes: 16 additions & 6 deletions packages/drawer/src/views/Drawer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,11 @@ const SPRING_CONFIG = {
restSpeedThreshold: 0.01,
};

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

const PROGRESS_EPSILON = 0.05;

type Binary = 0 | 1;

type Renderer = (props: { progress: Animated.Node<number> }) => React.ReactNode;
Expand Down Expand Up @@ -103,7 +106,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 @@ -489,7 +495,9 @@ export default class DrawerView extends React.Component<Props> {
// Check if the drawer width is available to avoid division by zero
eq(this.drawerWidth, 0),
0,
abs(divide(this.translateX, this.drawerWidth))
Platform.OS === 'windows' || Platform.OS === 'macos'
kaiguo marked this conversation as resolved.
Show resolved Hide resolved
? max(PROGRESS_EPSILON, abs(divide(this.translateX, this.drawerWidth)))
: abs(divide(this.translateX, this.drawerWidth))
);

private handleGestureEvent = event([
Expand Down Expand Up @@ -577,19 +585,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 +657,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 './GestureHandlerCompat';
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 './GestureHandlerCompat';
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 './GestureHandlerCompat';
export type { PanGestureHandlerGestureEvent } from 'react-native-gesture-handler';
31 changes: 31 additions & 0 deletions packages/drawer/src/views/GestureHandlerCompat.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import * as React from 'react';
kaiguo marked this conversation as resolved.
Show resolved Hide resolved
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';
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 './GestureHandlerCompat';
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 './GestureHandlerCompat';
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 './GestureHandlerCompat';
export type { PanGestureHandlerGestureEvent } from 'react-native-gesture-handler';
24 changes: 24 additions & 0 deletions packages/stack/src/views/GestureHandlerCompat.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import * as React from 'react';
kaiguo marked this conversation as resolved.
Show resolved Hide resolved
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';
3 changes: 3 additions & 0 deletions packages/stack/src/views/MaskedView.macos.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import StubbedMaskedView from './MaskedView';
kaiguo marked this conversation as resolved.
Show resolved Hide resolved

export default StubbedMaskedView;
3 changes: 3 additions & 0 deletions packages/stack/src/views/MaskedView.windows.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import StubbedMaskedView from './MaskedView';

export default StubbedMaskedView;
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;