如何返回嵌套导航器的初始状态?

时间:2019-09-01 02:23:59

标签: react-native react-navigation

我有以下导航树:

public class IslandsMentallurg {

    private static class Cell {

        int col;

        int row;

        Cell(int row, int col) {
            this.row = row;
            this.col = col;
        }

        @Override
        public String toString() {
            return "(" + row + "," + col + ")";
        }

    }

    private static int[][] matrix = { //
            { 1, 1, 0, 0, 0 }, //
            { 0, 1, 0, 0, 1 }, //
            { 1, 0, 0, 1, 1 }, //
            { 0, 0, 0, 0, 0 }, //
            { 1, 0, 1, 1, 0 } //
    };

    private static boolean[][] visited;

    private static Cell findNewCell(Cell currentCell) {
        for (int i = -1; i <= 1; i++) {
            int row = currentCell.row + i;
            if (row < 0 || row >= matrix.length) {
                continue;
            }
            for (int j = -1; j <= 1; j++) {
                int col = currentCell.col + j;
                if (col < 0 || col >= matrix[row].length) {
                    continue;
                }
                if (!visited[row][col] && matrix[row][col] == 1) {
                    return new Cell(row, col);
                }
            }
        }

        return null;
    }

    public static void main(String[] args) {
        visited = new boolean[matrix.length][matrix.length];
        for (int i = 0; i < visited.length; i++) {
            for (int j = 0; j < visited[i].length; j++) {
                visited[i][j] = false;
            }
        }

        List<List<Cell>> islands = new ArrayList<>();

        for (int i = 0; i < visited.length; i++) {
            for (int j = 0; j < visited[i].length; j++) {
                if (!visited[i][j] && matrix[i][j] == 1) {
                    List<Cell> island = new ArrayList<>();
                    islands.add(island);
                    island.add(new Cell(i, j));
                    visited[i][j] = true;
                    int currentCellIndex = 0;
                    do {
                        Cell currentCell = island.get(currentCellIndex);
                        Cell newCell = findNewCell(currentCell);
                        if (newCell != null) {
                            island.add(newCell);
                            visited[newCell.row][newCell.col] = true;
                            currentCellIndex = island.size() - 1;
                            continue;
                        }
                        currentCellIndex--;
                    } while (currentCellIndex >= 0);
                }
            }
        }

        System.out.printf("Number of 1-islands:   %d\n", islands.size());

        for (int i = 0; i < islands.size(); i++) {
            System.out.printf("Island %d:   ", i + 1);
            List<Cell> island = islands.get(i);
            for (Cell cell : island) {
                System.out.printf("%s, ", cell);
            }
            System.out.printf("\n");
        }
    }

}

说我在Screen2上,然后导航到“主页”。现在,当我返回到配置文件导航器时,我希望显示的是Screen1,而不是Screen2。我该如何实现?

0 个答案:

没有答案