mirror of
https://github.com/zhigang1992/react-navigation.git
synced 2026-04-25 04:55:30 +08:00
Compare commits
11 Commits
2.0.0-alph
...
2.0.0-alph
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ce819f6356 | ||
|
|
1ac742610b | ||
|
|
28f57240c2 | ||
|
|
ca6319d26e | ||
|
|
2b1b726723 | ||
|
|
4ce9469571 | ||
|
|
cef9b8f393 | ||
|
|
ecc4056559 | ||
|
|
71a02af309 | ||
|
|
c88da09348 | ||
|
|
9aac0b89f2 |
@@ -105,6 +105,14 @@ public class ScreenContainer<T extends ScreenFragment> extends ViewGroup {
|
||||
markUpdated();
|
||||
}
|
||||
|
||||
protected void removeAllScreens() {
|
||||
for (int i = 0, size = mScreenFragments.size(); i < size; i++) {
|
||||
mScreenFragments.get(i).getScreen().setContainer(null);
|
||||
}
|
||||
mScreenFragments.clear();
|
||||
markUpdated();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startViewTransition(View view) {
|
||||
super.startViewTransition(view);
|
||||
@@ -235,10 +243,24 @@ public class ScreenContainer<T extends ScreenFragment> extends ViewGroup {
|
||||
return mScreenFragments.contains(screenFragment);
|
||||
}
|
||||
|
||||
protected void ensureFragmentManager() {
|
||||
if (mFragmentManager != null && mFragmentManager.isDestroyed()) {
|
||||
// When fragmentManager is destroyed, try to remove current fragment's views
|
||||
for (int i = 0, size = mScreenFragments.size(); i < size; i++) {
|
||||
ScreenFragment screenFragment = mScreenFragments.get(i);
|
||||
removeView(screenFragment.getScreenRootView());
|
||||
}
|
||||
mFragmentManager = null;
|
||||
mActiveScreenFragments.clear();
|
||||
mNeedUpdate = true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onAttachedToWindow() {
|
||||
super.onAttachedToWindow();
|
||||
mIsAttached = true;
|
||||
ensureFragmentManager();
|
||||
updateIfNeeded();
|
||||
}
|
||||
|
||||
|
||||
@@ -34,6 +34,11 @@ public class ScreenContainerViewManager extends ViewGroupManager<ScreenContainer
|
||||
parent.removeScreenAt(index);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeAllViews(ScreenContainer parent) {
|
||||
parent.removeAllScreens();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getChildCount(ScreenContainer parent) {
|
||||
return parent.getScreenCount();
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
package com.swmansion.rnscreens;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.fragment.app.Fragment;
|
||||
|
||||
@@ -33,6 +35,10 @@ public class ScreenFragment extends Fragment {
|
||||
return mScreenView;
|
||||
}
|
||||
|
||||
protected ViewGroup getScreenRootView() {
|
||||
return mScreenView;
|
||||
}
|
||||
|
||||
public Screen getScreen() {
|
||||
return mScreenView;
|
||||
}
|
||||
|
||||
@@ -97,6 +97,12 @@ public class ScreenStack extends ScreenContainer<ScreenStackFragment> {
|
||||
super.removeScreenAt(index);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void removeAllScreens() {
|
||||
mDismissed.clear();
|
||||
super.removeAllScreens();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean hasScreen(ScreenFragment screenFragment) {
|
||||
return super.hasScreen(screenFragment) && !mDismissed.contains(screenFragment);
|
||||
|
||||
@@ -96,6 +96,11 @@ public class ScreenStackFragment extends ScreenFragment {
|
||||
return mScreenRootView;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ViewGroup getScreenRootView() {
|
||||
return mScreenRootView;
|
||||
}
|
||||
|
||||
public boolean isDismissable() {
|
||||
View child = mScreenView.getChildAt(0);
|
||||
if (child instanceof ScreenStackHeaderConfig) {
|
||||
|
||||
@@ -243,6 +243,11 @@ public class ScreenStackHeaderConfig extends ViewGroup {
|
||||
maybeUpdate();
|
||||
}
|
||||
|
||||
public void removeAllConfigSubviews() {
|
||||
mConfigSubviews.clear();
|
||||
maybeUpdate();
|
||||
}
|
||||
|
||||
public void addConfigSubview(ScreenStackHeaderSubview child, int index) {
|
||||
mConfigSubviews.add(index, child);
|
||||
maybeUpdate();
|
||||
|
||||
@@ -32,6 +32,11 @@ public class ScreenStackHeaderConfigViewManager extends ViewGroupManager<ScreenS
|
||||
parent.addConfigSubview((ScreenStackHeaderSubview) child, index);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeAllViews(ScreenStackHeaderConfig parent) {
|
||||
parent.removeAllConfigSubviews();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeViewAt(ScreenStackHeaderConfig parent, int index) {
|
||||
parent.removeConfigSubview(index);
|
||||
|
||||
@@ -30,7 +30,8 @@ class StackView extends React.Component {
|
||||
this.props.navigation.dispatch(StackActions.pop({ key: route.key }));
|
||||
};
|
||||
|
||||
_onSceneFocus = route => {
|
||||
_onSceneFocus = (route, descriptor) => {
|
||||
descriptor.options && descriptor.options.onAppear && descriptor.options.onAppear()
|
||||
this.props.navigation.dispatch(
|
||||
StackActions.completeTransition({ toChildKey: route.key })
|
||||
);
|
||||
@@ -96,7 +97,10 @@ class StackView extends React.Component {
|
||||
|
||||
if (options.backButtonImage) {
|
||||
children.push(
|
||||
<ScreenStackHeaderBackButtonImage source={options.backButtonImage} />
|
||||
<ScreenStackHeaderBackButtonImage
|
||||
key="backImage"
|
||||
source={options.backButtonImage}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -175,7 +179,7 @@ class StackView extends React.Component {
|
||||
}
|
||||
}
|
||||
|
||||
let stackAnimation;
|
||||
let stackAnimation = options.stackAnimation;
|
||||
if (options.animationEnabled === false) {
|
||||
stackAnimation = 'none';
|
||||
}
|
||||
@@ -187,7 +191,7 @@ class StackView extends React.Component {
|
||||
style={options.cardStyle}
|
||||
stackAnimation={stackAnimation}
|
||||
stackPresentation={stackPresentation}
|
||||
onAppear={() => this._onSceneFocus(route)}
|
||||
onAppear={() => this._onSceneFocus(route, descriptor)}
|
||||
onDismissed={() => this._removeScene(route)}>
|
||||
{this._renderHeaderConfig(index, route, descriptor)}
|
||||
<SceneView
|
||||
@@ -218,7 +222,6 @@ const styles = StyleSheet.create({
|
||||
|
||||
function createStackNavigator(routeConfigMap, stackConfig = {}) {
|
||||
const router = StackRouter(routeConfigMap, stackConfig);
|
||||
|
||||
// Create a navigator with StackView as the view
|
||||
let Navigator = createNavigator(StackView, router, stackConfig);
|
||||
// if (!stackConfig.disableKeyboardHandling) {
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
NSMutableArray<RNSScreenView *> *_reactSubviews;
|
||||
NSMutableSet<RNSScreenView *> *_dismissedScreens;
|
||||
NSMutableArray<UIViewController *> *_presentedModals;
|
||||
__weak UIViewController* recentPopped;
|
||||
__weak RNSScreenStackManager *_manager;
|
||||
}
|
||||
|
||||
@@ -69,6 +70,10 @@
|
||||
[_dismissedScreens addObject:[_reactSubviews objectAtIndex:i - 1]];
|
||||
}
|
||||
}
|
||||
if (recentPopped != nil) {
|
||||
recentPopped.view = nil;
|
||||
recentPopped = nil;
|
||||
}
|
||||
}
|
||||
|
||||
- (id<UIViewControllerAnimatedTransitioning>)navigationController:(UINavigationController *)navigationController animationControllerForOperation:(UINavigationControllerOperation)operation fromViewController:(UIViewController *)fromVC toViewController:(UIViewController *)toVC
|
||||
@@ -77,7 +82,8 @@
|
||||
if (operation == UINavigationControllerOperationPush) {
|
||||
screen = (RNSScreenView *) toVC.view;
|
||||
} else if (operation == UINavigationControllerOperationPop) {
|
||||
screen = (RNSScreenView *) fromVC.view;
|
||||
screen = (RNSScreenView *) fromVC.view;
|
||||
recentPopped = fromVC;
|
||||
}
|
||||
if (screen != nil && (screen.stackAnimation == RNSScreenStackAnimationFade || screen.stackAnimation == RNSScreenStackAnimationNone)) {
|
||||
return [[RNSScreenStackAnimator alloc] initWithOperation:operation];
|
||||
@@ -137,12 +143,16 @@
|
||||
|
||||
- (void)setModalViewControllers:(NSArray<UIViewController *> *)controllers
|
||||
{
|
||||
// when there is no change we return immediately. This check is important because sometime we may
|
||||
// accidently trigger modal dismiss if we don't verify to run the below code only when an actual
|
||||
// change in the list of presented modal was made.
|
||||
if ([_presentedModals isEqualToArray:controllers]) {
|
||||
return;
|
||||
}
|
||||
|
||||
NSMutableArray<UIViewController *> *newControllers = [NSMutableArray arrayWithArray:controllers];
|
||||
[newControllers removeObjectsInArray:_presentedModals];
|
||||
|
||||
NSMutableArray<UIViewController *> *controllersToRemove = [NSMutableArray arrayWithArray:_presentedModals];
|
||||
[controllersToRemove removeObjectsInArray:controllers];
|
||||
|
||||
// find bottom-most controller that should stay on the stack for the duration of transition
|
||||
NSUInteger changeRootIndex = 0;
|
||||
UIViewController *changeRootController = _controller;
|
||||
@@ -173,9 +183,6 @@
|
||||
completion:nil];
|
||||
previous = next;
|
||||
}
|
||||
|
||||
[self->_presentedModals removeAllObjects];
|
||||
[self->_presentedModals addObjectsFromArray:controllers];
|
||||
};
|
||||
|
||||
if (changeRootController.presentedViewController) {
|
||||
@@ -185,10 +192,16 @@
|
||||
} else {
|
||||
finish();
|
||||
}
|
||||
[_presentedModals setArray:controllers];
|
||||
}
|
||||
|
||||
- (void)setPushViewControllers:(NSArray<UIViewController *> *)controllers
|
||||
{
|
||||
// when there is no change we return immediately
|
||||
if ([_controller.viewControllers isEqualToArray:controllers]) {
|
||||
return;
|
||||
}
|
||||
|
||||
UIViewController *top = controllers.lastObject;
|
||||
UIViewController *lastTop = _controller.viewControllers.lastObject;
|
||||
|
||||
@@ -198,7 +211,7 @@
|
||||
// controller is still there
|
||||
BOOL firstTimePush = ![lastTop isKindOfClass:[RNSScreen class]];
|
||||
|
||||
BOOL shouldAnimate = !firstTimePush && ((RNSScreenView *) lastTop.view).stackAnimation != RNSScreenStackAnimationNone;
|
||||
BOOL shouldAnimate = !firstTimePush && ((RNSScreenView *) lastTop.view).stackAnimation != RNSScreenStackAnimationNone && !_controller.presentedViewController;
|
||||
|
||||
if (firstTimePush) {
|
||||
// nothing pushed yet
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "react-native-screens",
|
||||
"version": "2.0.0-alpha.21",
|
||||
"version": "2.0.0-alpha.24",
|
||||
"description": "First incomplete navigation solution for your react-native app.",
|
||||
"scripts": {
|
||||
"start": "node node_modules/react-native/local-cli/cli.js start",
|
||||
|
||||
125
src/screens.d.ts
vendored
125
src/screens.d.ts
vendored
@@ -3,21 +3,140 @@
|
||||
|
||||
declare module 'react-native-screens' {
|
||||
import { ComponentClass } from 'react';
|
||||
import { ViewProps, Animated } from 'react-native';
|
||||
import { ViewProps, Animated, NativeSyntheticEvent, NativeTouchEvent, ImageProps } from 'react-native';
|
||||
|
||||
export function useScreens(shouldUseScreens?: boolean): void;
|
||||
export function enableScreens(shouldEnableScreens?: boolean): void;
|
||||
export function screensEnabled(): boolean;
|
||||
|
||||
export type StackPresentationTypes = 'push' | 'modal' | 'transparentModal';
|
||||
export type StackAnimationTypes = 'default' | 'fade' | 'flip' | 'none';
|
||||
|
||||
export interface ScreenProps extends ViewProps {
|
||||
active?: 0 | 1 | Animated.AnimatedInterpolation;
|
||||
onComponentRef?: (view: any) => void;
|
||||
children?: React.ReactNode;
|
||||
onAppear?: (e: NativeSyntheticEvent<NativeTouchEvent>) => void;
|
||||
/**
|
||||
*@description A callback that gets called when the current screen is dismissed by hardware back (on Android) or dismiss gesture (swipe back or down). The callback takes no arguments.
|
||||
*/
|
||||
onDismissed?: (e: NativeSyntheticEvent<NativeTouchEvent>) => void;
|
||||
/**
|
||||
* @type "push" – the new screen will be pushed onto a stack which on iOS means that the default animation will be slide from the side, the animation on Android may vary depending on the OS version and theme.
|
||||
* @type "modal" – the new screen will be presented modally. In addition this allow for a nested stack to be rendered inside such screens
|
||||
* @type "transparentModal" – the new screen will be presented modally but in addition the second to last screen will remain attached to the stack container such that if the top screen is non opaque the content below can still be seen. If "modal" is used instead the below screen will get unmounted as soon as the transition ends.
|
||||
*/
|
||||
stackPresentation: StackPresentationTypes;
|
||||
/**
|
||||
*@description Allows for the customization of how the given screen should appear/dissapear when pushed or popped at the top of the stack. The followin values are currently supported:
|
||||
* @type "default" – uses a platform default animation
|
||||
* @type "fade" – fades screen in or out
|
||||
* @type "flip" – flips the screen, requires stackPresentation: "modal" (iOS only)
|
||||
* @type "none" – the screen appears/dissapears without an animation
|
||||
*/
|
||||
stackAnimation?: StackAnimationTypes;
|
||||
}
|
||||
export const Screen: ComponentClass<ScreenProps>;
|
||||
|
||||
|
||||
export type ScreenContainerProps = ViewProps;
|
||||
export const ScreenContainer: ComponentClass<ScreenContainerProps>;
|
||||
|
||||
export interface ScreenStackProps extends ViewProps {
|
||||
transitioning?: number;
|
||||
progress?: number;
|
||||
}
|
||||
|
||||
export interface ScreenStackHeaderConfigProps extends ViewProps {
|
||||
/**
|
||||
*@description String that representing screen title that will get rendered in the middle section of the header. On iOS the title is centered on the header while on Android it is aligned to the left and placed next to back button (if one is present).
|
||||
*/
|
||||
title?: string;
|
||||
/**
|
||||
*@description When set to true the header will be hidden while the parent Screen is on the top of the stack. The default value is false.
|
||||
*/
|
||||
hidden?: boolean;
|
||||
/**
|
||||
*@description Controls the color of items rendered on the header. This includes back icon, back text (iOS only) and title text. If you want the title to have different color use titleColor property.
|
||||
*/
|
||||
color?: string;
|
||||
/**
|
||||
*@description Customize font family to be used for the title.
|
||||
*/
|
||||
titleFontFamily?: string;
|
||||
/**
|
||||
*@description Customize the size of the font to be used for the title.
|
||||
*/
|
||||
titleFontSize?: number;
|
||||
/**
|
||||
*@description Allows for setting text color of the title.
|
||||
*/
|
||||
titleColor?: string;
|
||||
/**
|
||||
*@description Controlls the color of the navigation header.
|
||||
*/
|
||||
backgroundColor?: string;
|
||||
/**
|
||||
* @description Boolean that allows for disabling drop shadow under navigation header. The default value is true.
|
||||
*/
|
||||
hideShadow?: boolean;
|
||||
/**
|
||||
* @description If set to true the back button will not be rendered as a part of navigation header.
|
||||
*/
|
||||
hideBackButton?: boolean;
|
||||
/**
|
||||
* @description When set to false the back swipe gesture will be disabled when the parent Screen is on top of the stack. The default value is true.
|
||||
*/
|
||||
gestureEnabled?: boolean;
|
||||
/**
|
||||
* @host (iOS only)
|
||||
* @description When set to true, it makes native navigation bar on iOS semi transparent with blur effect. It is a common way of presenting navigation bar introduced in iOS 11. The default value is false
|
||||
*/
|
||||
translucent?: boolean;
|
||||
/**
|
||||
* @host (iOS only)
|
||||
* @description Allows for controlling the string to be rendered next to back button. By default iOS uses the title of the previous screen.
|
||||
*/
|
||||
backTitle?: string;
|
||||
/**
|
||||
* @host (iOS only)
|
||||
* @description Allows for customizing font family to be used for back button title on iOS.
|
||||
*/
|
||||
backTitleFontFamily?: string;
|
||||
/**
|
||||
* @host (iOS only)
|
||||
* @description Allows for customizing font size to be used for back button title on iOS.
|
||||
*/
|
||||
backTitleFontSize?: number;
|
||||
/**
|
||||
* @host (iOS only)
|
||||
* @description When set to true it makes the title display using the large title effect.
|
||||
*/
|
||||
largeTitle?: boolean;
|
||||
/**
|
||||
* @host (iOS only)
|
||||
* @description Customize font family to be used for the large title.
|
||||
*/
|
||||
largeTitleFontFamily?: string;
|
||||
/**
|
||||
* @host (iOS only)
|
||||
* @description Customize the size of the font to be used for the large title.
|
||||
*/
|
||||
largeTitleFontSize?: number;
|
||||
/**
|
||||
* Pass HeaderLeft, HeaderRight and HeaderTitle
|
||||
*/
|
||||
children?: React.ReactNode;
|
||||
}
|
||||
|
||||
export const Screen: ComponentClass<ScreenProps>;
|
||||
export const ScreenContainer: ComponentClass<ScreenContainerProps>;
|
||||
export const NativeScreen: ComponentClass<ScreenProps>;
|
||||
export const NativeScreenContainer: ComponentClass<ScreenContainerProps>;
|
||||
export const ScreenStack: ComponentClass<ScreenStackProps>;
|
||||
export const ScreenStackHeaderBackButtonImage: ComponentClass<ImageProps>;
|
||||
export const ScreenStackHeaderLeftView: ComponentClass<ViewProps>;
|
||||
export const ScreenStackHeaderRightView: ComponentClass<ViewProps>;
|
||||
export const ScreenStackHeaderTitleView: ComponentClass<ViewProps>;
|
||||
export const ScreenStackHeaderConfig: ComponentClass<
|
||||
ScreenStackHeaderConfigProps
|
||||
>;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user