Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
a04fcd8
Upgraded material components to v1.4.0
grahammendick Sep 4, 2021
3a83c2d
MaterialContainerTransform'ed the shared element
grahammendick Sep 4, 2021
3f6ce7f
Removed redundant import
grahammendick Sep 4, 2021
d0142e2
Made SharedElementView the shared element
grahammendick Sep 4, 2021
0931921
Deleted redundant transition
grahammendick Sep 4, 2021
1a4b608
Always ran custom animations, even for shared els
grahammendick Sep 4, 2021
8c02465
Loaded using just shared element name
grahammendick Sep 4, 2021
c6bf9e3
Removed redundant enter and exit props
grahammendick Sep 4, 2021
b553464
Removed redundant transition prop
grahammendick Sep 4, 2021
e0891cb
Removed complier warnings
grahammendick Sep 4, 2021
7f104b2
Removed redundant imports
grahammendick Sep 4, 2021
14ee21e
Removed compiler warnings
grahammendick Sep 4, 2021
59e28a9
Loaded shared els same when returning as going
grahammendick Sep 4, 2021
0b1265b
Passed shared element view to transitioner
grahammendick Sep 4, 2021
5384e2f
Tweaked format
grahammendick Sep 4, 2021
7fe6482
Created transition in shared element view
grahammendick Sep 5, 2021
d2a001e
Added duration, fadeMode and drawingView props
grahammendick Sep 5, 2021
ea2e4fc
Deleted redundant transition
grahammendick Sep 5, 2021
dc7551e
Corrected string comparisons
grahammendick Sep 5, 2021
a880e4f
Renamed for clarity
grahammendick Sep 5, 2021
6f912f1
Removed class level field for clarity
grahammendick Sep 5, 2021
4937acd
Removed shared el from scene when detached
grahammendick Sep 5, 2021
4ec6604
Removed drawing view id prop for simplicity
grahammendick Sep 5, 2021
4c446be
Removed redundant import
grahammendick Sep 5, 2021
66eddf3
Typed the shared element props
grahammendick Sep 5, 2021
6709e42
Copied shared el typings to npm package
grahammendick Sep 5, 2021
d8d4407
Added for clarity
grahammendick Sep 5, 2021
d99cda1
Allowed only one shared element transition
grahammendick Sep 6, 2021
3015714
Renamed from transitioner to motion for clarity
grahammendick Sep 6, 2021
b85c592
Renamed variable to match class name
grahammendick Sep 6, 2021
b116fd4
Removed compiler warnings
grahammendick Sep 6, 2021
2a5ddb2
Removed variable now only used twice
grahammendick Sep 6, 2021
27a8d41
Renamed because no clash anymore
grahammendick Sep 6, 2021
36a572e
Typed sharedElement function on stack
grahammendick Sep 6, 2021
7cb08cc
Copied sharedElement typings to npm package
grahammendick Sep 6, 2021
b83521b
Asserted to remove compiler warnings
grahammendick Sep 6, 2021
b39ff05
Animated screens during shared element
grahammendick Sep 6, 2021
fd19edf
Tweaked format
grahammendick Sep 6, 2021
0372b07
Styled search results as drop down
grahammendick Sep 6, 2021
d97ee20
Moved styles to stylesheet for consistency
grahammendick Sep 6, 2021
078db62
Added text to the shared element
grahammendick Sep 6, 2021
61a3e5b
Tweaked format
grahammendick Sep 6, 2021
a477f91
Provided sharedElement prop default
grahammendick Sep 6, 2021
d4ca976
Updated material comp to v1.4 in twitter sample
grahammendick Sep 6, 2021
36ef391
Rendered sharedEl (view) children on ios
grahammendick Sep 6, 2021
ca2fab0
Rendered shared el children on android
grahammendick Sep 6, 2021
a649b09
Tweaked format
grahammendick Sep 6, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ dependencies {
implementation "com.facebook.react:react-native:+" // From node_modules

implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.0.0"
implementation 'com.google.android.material:material:1.1.0'
implementation 'com.google.android.material:material:1.4.0'

debugImplementation("com.facebook.flipper:flipper:${FLIPPER_VERSION}") {
exclude group:'com.facebook.fbjni'
Expand Down
5 changes: 4 additions & 1 deletion NavigationReactNative/sample/zoom/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@ Linking.addEventListener('url', ({url}) => openLink(url));

const App = () => (
<NavigationHandler stateNavigator={stateNavigator}>
<NavigationStack sharedElements={(_, {name}) => name && [name]} />
<NavigationStack
sharedElement={(_, {color, search}) => !search ? color : null}
crumbStyle={from => from ? 'enter_crumb' : 'exit_crumb'}
unmountStyle={from => from ? 'enter_mount' : 'exit_mount'} />
</NavigationHandler>
);
export default App;
38 changes: 17 additions & 21 deletions NavigationReactNative/sample/zoom/Detail.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {Platform, StyleSheet, ScrollView, Text, View, TouchableHighlight} from '
import {NavigationContext} from 'navigation-react';
import {NavigationBar, RightBar, BarButton, TitleBar, SharedElement} from 'navigation-react-native';

const Detail = ({colors, color, name, filter, search}) => {
const Detail = ({colors, color, search}) => {
const {stateNavigator} = useContext(NavigationContext);
return (
<>
Expand All @@ -21,28 +21,23 @@ const Detail = ({colors, color, name, filter, search}) => {
</RightBar>
</NavigationBar>
<ScrollView contentInsetAdjustmentBehavior="automatic">
<SharedElement name={name} style={styles.color} transition="overshoot">
<SharedElement name={color} style={styles.color} duration={250}>
<View style={{backgroundColor: color, flex: 1}} />
<Text style={styles.text}>{color}</Text>
</SharedElement>
<Text style={styles.text}>{color}</Text>
<View style={styles.colors}>
{[1,2,3].map(i => colors[(colors.indexOf(color) + i) % 15])
.map(subcolor => {
const suffix = search ? '_search' : '';
const matched = !filter || subcolor.indexOf(filter.toLowerCase()) !== -1;
const name = matched ? subcolor + suffix : null;
return (
<TouchableHighlight
key={subcolor}
style={[styles.subcolor, {backgroundColor: subcolor}]}
underlayColor={subcolor}
onPress={() => {
stateNavigator.navigate('detail', {color: subcolor, name, filter, search});
}}>
<View />
</TouchableHighlight>
)
}
.map(subcolor => (
<TouchableHighlight
key={subcolor}
style={[styles.subcolor, {backgroundColor: subcolor}]}
underlayColor={subcolor}
onPress={() => {
stateNavigator.navigate('detail', {color: subcolor, search});
}}>
<View />
</TouchableHighlight>
)
)}
</View>
</ScrollView>
Expand Down Expand Up @@ -70,16 +65,17 @@ const styles = StyleSheet.create({
paddingTop: 10,
},
color: {
height: 300,
height: 400,
marginTop: 10,
marginLeft: 15,
marginRight: 15,
marginRight: 15
},
text:{
fontSize: 80,
color: '#000',
textAlign:'center',
fontWeight: 'bold',
backgroundColor: 'white'
},
colors: {
flexDirection: 'row',
Expand Down
94 changes: 62 additions & 32 deletions NavigationReactNative/sample/zoom/Grid.js
Original file line number Diff line number Diff line change
@@ -1,47 +1,46 @@
import React, {useContext, useState} from 'react';
import {Platform, StyleSheet, ScrollView, View, TouchableHighlight} from 'react-native';
import {Platform, StyleSheet, ScrollView, View, TouchableHighlight, Text} from 'react-native';
import {NavigationContext} from 'navigation-react';
import {SharedElement, NavigationBar, SearchBar, RightBar, BarButton} from 'navigation-react-native';

const Colors = ({colors, children, filter}) => {
const Container = (props) => (
Platform.OS === 'ios' ? <ScrollView {...props}/> : <View {...props} />
);

const SearchResults = ({colors, text}) => {
const {stateNavigator} = useContext(NavigationContext);
const suffix = filter != null ? '_search' : '';
const matchedColors = colors.filter(color => (
!filter || color.indexOf(filter.toLowerCase()) !== -1
));
return (
<ScrollView
style={styles.scene}
contentInsetAdjustmentBehavior="automatic">
<View style={styles.colors}>
{matchedColors.map(color => (
<TouchableHighlight
key={color}
style={styles.color}
underlayColor={color}
onPress={() => {
stateNavigator.navigate('detail', {
color, name: color + suffix, filter, search: filter != null
});
}}>
<SharedElement name={color + suffix} style={{flex: 1}}>
<View style={{backgroundColor: color, flex: 1}} />
</SharedElement>
</TouchableHighlight>
))}
{children}
<View>
{colors
.filter(color => (
!text || color.indexOf(text.toLowerCase()) !== -1
))
.map(color => (
<TouchableHighlight
key={color}
style={styles.result}
underlayColor="white"
onPress={() => {
stateNavigator.navigate('detail', {color, search: true});
}}>
<>
<View style={{backgroundColor: color, width: 100, height: 50}} />
<Text style={{fontSize: 25, marginLeft: 10}}>{color}</Text>
</>
</TouchableHighlight>
))}
</View>
</ScrollView>
);
)
}

const Container = (props) => (
Platform.OS === 'ios' ? <ScrollView {...props}/> : <View {...props} />
);

const Grid = ({colors}) => {
const [text, setText] = useState('');
return (
const {stateNavigator} = useContext(NavigationContext);
return (
<Container
style={styles.scene}
collapsable={false}
Expand All @@ -55,13 +54,32 @@ const Grid = ({colors}) => {
autoCapitalize="none"
obscureBackground={false}
onChangeText={text => setText(text)}>
<Colors colors={colors} filter={text} />
<SearchResults colors={colors} text={text} />
</SearchBar>
<RightBar>
<BarButton title="search" show="always" search={true} />
</RightBar>
</NavigationBar>
<Colors colors={colors} />
<ScrollView
style={styles.scene}
contentInsetAdjustmentBehavior="automatic">
<View style={styles.colors}>
{colors.map(color => (
<TouchableHighlight
key={color}
style={styles.color}
underlayColor="transparent"
onPress={() => {
stateNavigator.navigate('detail', {color});
}}>
<SharedElement name={color} style={{flex: 1}} duration={250}>
<View style={{backgroundColor: color, flex: 1}} />
<Text style={styles.text}>{color}</Text>
</SharedElement>
</TouchableHighlight>
))}
</View>
</ScrollView>
</Container>
);
};
Expand All @@ -86,4 +104,16 @@ const styles = StyleSheet.create({
marginRight: 10,
marginBottom: 20,
},
});
text: {
fontSize: 25,
textAlign: 'center',
fontWeight: 'bold',
backgroundColor: 'white'
},
result: {
flex: 1,
flexDirection: 'row',
margin: 10,
alignItems: 'center'
}
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<scale android:fromXScale="80%p"
android:toXScale="100%p"
android:fromYScale="80%p"
android:toYScale="100%p"
android:pivotX="50%p"
android:pivotY="50%p"
android:duration="250" />
<alpha android:fromAlpha="0"
android:toAlpha="1.0"
android:duration="250"/>
</set>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<alpha android:fromAlpha="0"
android:toAlpha="1.0"
android:duration="250"/>
</set>
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<scale android:fromXScale="100%p"
android:toXScale="80%p"
android:fromYScale="100%p"
android:toYScale="80%p"
android:pivotX="50%p"
android:pivotY="50%p"
android:duration="250" />
<alpha android:fromAlpha="1"
android:toAlpha="0"
android:duration="250"/>
</set>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<alpha android:fromAlpha="1"
android:toAlpha="0"
android:duration="250"/>
</set>

This file was deleted.

12 changes: 6 additions & 6 deletions NavigationReactNative/src/NavigationStack.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Crumb, State } from 'navigation';
import { NavigationContext, AsyncStateNavigator } from 'navigation-react';
import PopSync from './PopSync';
import Scene from './Scene';
type NavigationStackProps = {stateNavigator: AsyncStateNavigator, title: (state: State, data: any) => string, crumbStyle: any, unmountStyle: any, hidesTabBar: any, sharedElements: any, renderScene: (state: State, data: any) => ReactNode};
type NavigationStackProps = {stateNavigator: AsyncStateNavigator, title: (state: State, data: any) => string, crumbStyle: any, unmountStyle: any, hidesTabBar: any, sharedElement: any, renderScene: (state: State, data: any) => ReactNode};
type NavigationStackState = {stateNavigator: AsyncStateNavigator, keys: string[]};

class NavigationStack extends React.Component<NavigationStackProps, NavigationStackState> {
Expand All @@ -22,7 +22,7 @@ class NavigationStack extends React.Component<NavigationStackProps, NavigationSt
unmountStyle: () => null,
crumbStyle: () => null,
hidesTabBar: () => false,
sharedElements: () => null
sharedElement: () => null
}
static getDerivedStateFromProps({stateNavigator}: NavigationStackProps, {keys: prevKeys, stateNavigator: prevStateNavigator}: NavigationStackState) {
if (stateNavigator === prevStateNavigator)
Expand Down Expand Up @@ -62,7 +62,7 @@ class NavigationStack extends React.Component<NavigationStackProps, NavigationSt
stateNavigator.navigateBack(crumbs.length);
}
getAnimation() {
var {stateNavigator, unmountStyle, crumbStyle, sharedElements: getSharedElements} = this.props;
var {stateNavigator, unmountStyle, crumbStyle, sharedElement: getSharedElement} = this.props;
var {state, data, oldState, oldData, oldUrl, crumbs, nextCrumb} = stateNavigator.stateContext;
if (!oldState)
return null;
Expand All @@ -71,20 +71,20 @@ class NavigationStack extends React.Component<NavigationStackProps, NavigationSt
var {state: nextState, data: nextData} = crumbs.concat(nextCrumb)[oldCrumbs.length + 1];
var enterAnim = unmountStyle(true, state, data, crumbs);
var exitAnim = crumbStyle(false, oldState, oldData, oldCrumbs, nextState, nextData);
var sharedElements = getSharedElements(state, data, crumbs);
var sharedElement = getSharedElement(state, data, crumbs);
}
if (crumbs.length < oldCrumbs.length) {
var nextCrumb = new Crumb(oldData, oldState, null, null, false);
var {state: nextState, data: nextData} = oldCrumbs.concat(nextCrumb)[crumbs.length + 1];
var enterAnim = crumbStyle(true, state, data, crumbs, nextState, nextData);
var exitAnim = unmountStyle(false, oldState, oldData, oldCrumbs);
var oldSharedElements = getSharedElements(oldState, oldData, oldCrumbs);
var oldSharedElement = getSharedElement(oldState, oldData, oldCrumbs);
}
if (crumbs.length === oldCrumbs.length) {
var enterAnim = unmountStyle(true, state, data, crumbs);
var exitAnim = unmountStyle(false, oldState, oldData, oldCrumbs, state, data);
}
return {enterAnim, exitAnim, sharedElements, oldSharedElements};
return {enterAnim, exitAnim, sharedElement, oldSharedElement};
}
render() {
var {keys} = this.state;
Expand Down
11 changes: 4 additions & 7 deletions NavigationReactNative/src/SharedElement.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
import React from 'react';
import { requireNativeComponent, Platform, View } from 'react-native';

var SharedElement = ({transition, ...props}) => (
Platform.OS == 'android' ? (
<NVSharedElement
enterTransition={typeof transition !== 'function' ? transition : transition(true)}
exitTransition={typeof transition !== 'function' ? transition : transition(false)}
{...props} />
) : <View {...props} />
var SharedElement = ({ style, children, ...props }) => (
Platform.OS == 'android'
? <NVSharedElement {...props} style={style}>{children}</NVSharedElement>
: <View style={style}>{children}</View>
);

var NVSharedElement = requireNativeComponent<any>('NVSharedElement', null);
Expand Down
2 changes: 1 addition & 1 deletion NavigationReactNative/src/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ repositories {

dependencies {
implementation 'com.facebook.react:react-native:+'
implementation 'com.google.android.material:material:1.1.0'
implementation 'com.google.android.material:material:1.4.0'
implementation 'androidx.viewpager2:viewpager2:1.0.0'
}

Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@ public void setExitAnim(NavigationStackView view, String exitAnim) {
view.exitAnim = exitAnim;
}

@ReactProp(name = "sharedElements")
public void setSharedElements(NavigationStackView view, ReadableArray sharedElements) {
view.sharedElementNames = sharedElements;
@ReactProp(name = "sharedElement")
public void setSharedElement(NavigationStackView view, String sharedElement) {
view.sharedElementName = sharedElement;
}

@ReactProp(name = "oldSharedElements")
public void setOldSharedElements(NavigationStackView view, ReadableArray oldSharedElements) {
view.oldSharedElementNames = oldSharedElements;
@ReactProp(name = "oldSharedElement")
public void setOldSharedElement(NavigationStackView view, String oldSharedElement) {
view.oldSharedElementName = oldSharedElement;
}

@Nonnull
Expand Down
Loading