Comments (14)
@phpfalcon basically, there is a singleton that is imported to all components that are views needing to have "onBack" event. The singleton is named "onBackStack" which is just a simple array.
Each component needing an "onBack" would then push themselves into the onBackStack on their own componentWillMount. On componentWillUnmount, they remove themselves off the stack but then call the method of the last item in the list's onBack() so to fire the event of the component it is going back to. It's kind of like a cooperative chaining of components to accomplish this.
This can be put into a component class then inherited from which is probably a way better idea. I just made it very quickly as I don't care to make it more robust or friendly for what I am doing.
from react-native.
I was able to get a hacked onBack for these types of things using an array as singleton that each component wanting to get there onBack method called would use. The idea is like below.
// singleton onBackStack
export default [];
// example component
class ExampleComponent extends Component {
onBack() {
// do something
}
componentWillMount() {
onBackStack.push(this);
}
componentWillUnmount() {
onBackStack.pop();
if (onBackStack.length) onBackStack[onBackStack.length - 1].onBack();
}
render() {
return <View>example</View>
}
}
from react-native.
@sebringj your method is great but I couldn't understand it until your last comment I implanted a similar method which works for navigatorios :
constructor()
{
super();
this.state = {backapper:false}};
}
componentDidMount() {
var currentRoute = this.props.navigator.navigationContext.currentRoute;
this.props.navigator.navigationContext.addListener('willfocus', (event) => {
//didfocus emit in componentDidMount
if (currentRoute === event.data.route && this.state.backapper) {
console.log("me didAppear");
this.setState({backapper: false});
}
else if (currentRoute !== event.data.route)
{
this.setState({backapper: true});
console.log("me didDisappear, other didAppear");
}
//console.log(event.data.route);
});
}
from react-native.
cc @evv
from react-native.
@ericvicenti actually :p
from react-native.
@vjeux: So far I'm having a great time with react-native. I wrote a tumblr browser that uses the flux pattern heh. This is what it looks like: min-s-react-native-demo-gif. (I'm not inlining the gif because it's too distracting.)
from react-native.
Nice! Glad to hear :)
Hopefully we can get gif support soon so that you can have a fully functional app soon
from react-native.
Unfortunately, the default back button of UINavigationController does not provide an event. The way to get around it is to either set your custom back button on the left side, or to implement - viewWillDisappear:
in iOS. So I guess, this limitation is here to stay.
from react-native.
Since iOS doesn't support it, let's close this for now.
from react-native.
@paramaggarwal is it possible to be notified when any rote changes?
something like
<NavigatorIOS onChange={...}
initialRoute={...} />
I mean when someone do navigator.push(...)
from react-native.
@liubko please look into Navigator
instead, which is much more customisable. Docs are here: Navigator Comparison
from react-native.
i think you can wrap the route component with a wrapper and listen to the wrapper's componentWillUnmount
from react-native.
@sebringj thanks for sharing this can you please explain onBackStack
from react-native.
@phpfalcon Hmm I dont have a navigationContext? Are you using React Navigation? This Google returns no results... navigationContext site:reactnavigation.org
from react-native.
Related Issues (20)
- `fontVariant` doesn't work on iOS when using the new architecture
- UI problem with iOS floating keyboard in iPad. HOT 5
- TouchableWithoutFeedback does not support style HOT 1
- Cannot find EventEmitter for receivedTouches EventName[topTouchMove, topTouchEnd] on native library HOT 5
- RCTNativeAnimatedNodesManager.mm props is not a node HOT 1
- Unexpected scroll behaviors when using FlatList HOT 7
- When I integration react native with Existing Android Apps,I got a autolinking question. HOT 2
- Symbol not found: (_JSGlobalContextSetInspectable) HOT 1
- The directory ****/ios contains 2 projects HOT 3
- textInput props textAlign will cause long text to be cut off after the hyphen when out of focus and focus again
- close the first modal with animation, then open the second modal immediately, the second modal can't be showed HOT 2
- UI updates made from layout effect are flushed in separate UI transaction HOT 4
- Blob constructor is not spec compliant HOT 1
- [!] CocoaPods could not find compatible versions for pod "React-RCTAnimation": In Podfile: React-RCTAnimation (from `../node_modules/react-native/Libraries/NativeAnimation`) HOT 3
- Build error in 0.73.6 HOT 3
- Fatal error "available height is undefined" when editing textinput the app closes HOT 3
- Inverted Flatlist not working when scrolled HOT 5
- `TextInput` cursor lags behind text when component is controlled if Auto-Correction and Predictive Text are enabled HOT 3
- RNSVG same register view HOT 4
- Firestore encountered gRPC-C++ error while upgrading Firebase module to 19.2(iOS) HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from react-native.