Skip to content

Instantly share code, notes, and snippets.

@shubhnik
shubhnik / healthy.test.js
Last active January 31, 2022 02:38
PL component for demonstration
it("should add a note", async () => {
const {
getByTestId,
getByText
} = render( < PaymentLink / > );
fireEvent.press(getByText("+Add"));
expect(getByTestId("note-title")).toBeTruthy();
expect(getByTestId("note-description")).toBeTruthy();
});
@shubhnik
shubhnik / conditionalStateToNavigator.js
Last active November 10, 2017 12:17
Here we are passing stateForLoggedIn if the user is logged in or stateForLoggedOut if the user is logged out.
// our navigationReducer which will feed AppNavigator with navigation state ---> https://gist.github.com/shubhnik/9f7bafd3145e66434705cd1e995d1356
// Don't forget to check the complete code here ---> https://github.com/shubhnik/redux-react-navigation/tree/authFlow
const AppNavigator = StackNavigator({
login: {
screen: Login
},
screen1: {
screen: Screen1
},
screen2: {
@shubhnik
shubhnik / loginReducer.js
Last active November 10, 2017 12:17
A demonstration of loginReducer.
// Don't forget to check the complete code here ---> https://github.com/shubhnik/redux-react-navigation/tree/authFlow
const initialState = { isLoggedIn: false };
const loginReducer = (state = initialState, action) => {
switch (action.type) {
case "LOGIN":
return { ...state, isLoggedIn: true };
case "LOGOUT":
return { ...state, isLoggedIn: false };
@shubhnik
shubhnik / navigationReducer.js
Last active January 15, 2018 10:45
Our new navigationReducer capable of handling authentication flow.
// Don't forget to check the complete code here ---> https://github.com/shubhnik/redux-react-navigation/tree/authFlow
import { NavigationActions } from "react-navigation";
// AppNavigator is the one defined in the start of PART-2 of this blog --> https://medium.com/@shubhnik/a-comprehensive-guide-for-integrating-react-navigation-with-redux-including-authentication-flow-cb7b90611adf
const ActionForLoggedOut = AppNavigator.router.getActionForPathAndParams("login");
const ActionForLoggedIn = AppNavigator.router.getActionForPathAndParams("screen1");
const stateForLoggedOut = AppNavigator.router.getStateForAction(ActionForLoggedOut);
const stateForLoggedIn = AppNavigator.router.getStateForAction(ActionForLoggedIn);
const initialState = { stateForLoggedOut, stateForLoggedIn };
// a simple demo screen1 to demonstrate dispatching actions to update navigation state and navigate to screen2.
// Don not forget to check the complete code here ---> https://github.com/shubhnik/redux-react-navigation
class Screen1 extends Component {
navigate = () => {
const navigateToScreen2 = NavigationActions.navigate({
routeName:'screen2',
params:{name:'Shubhnik'}
})
// navigateToscreen2 will look like this:
/*
@shubhnik
shubhnik / reduxReactNavigation.js
Last active November 10, 2017 17:10
Demonstration code on passing our own navigation prop (containing state calculated from navigationReducer and redux's dispatch) to the navigator(AppNavigator)
// our basic navigationReducer which will feed AppNavigator with navigation state ---> https://gist.github.com/shubhnik/b55602633aaeb5919f6f3c15552d1802
// Don not forget to check the complete code here ---> https://github.com/shubhnik/redux-react-navigation
const AppNavigator = StackNavigator({
screen1: {
screen: Screen1
},
screen2: {
screen: Screen2
}
});
@shubhnik
shubhnik / basicNavigationReducer.js
Last active November 10, 2017 12:12
Only a basic navigation reducer
// Don not forget to check the complete code here ---> https://github.com/shubhnik/redux-react-navigation
// The particular navigationReducer here ---> https://github.com/shubhnik/redux-react-navigation/blob/master/src/Reducers/navigationReducer.js
const AppNavigator = StackNavigator({
screen1: {
screen: Screen1
},
screen2: {
screen: Screen2
}
});
// Our Navigator:
const AppNavigator = StackNavigator({
login: {
screen: Login
},
screen1: {
screen: Screen1
},
screen2: {
screen: Logout
const AppNavigator = StackNavigator({
login: {
screen: login
},
screen1: {
screen: Screen1
},
screen2: {
screen: Logout
}