@nakamura-123/pages 1.3.8 → 1.3.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -18,6 +18,11 @@ const stores_1 = require("@nakamura-123/stores");
18
18
  // 00.メイン関数
19
19
  exports.coinCheckFnc = (0, toolkit_1.createAsyncThunk)("coin/check", (allFreeId_1, _a) => __awaiter(void 0, [allFreeId_1, _a], void 0, function* (allFreeId, { dispatch }) {
20
20
  const receipts = yield (0, CoinFnc_1.restorePurchases)(dispatch, false);
21
+ // null=取得失敗(通信・StoreKitエラー)。未購入と区別し、状態を変えない。
22
+ // ここで降格すると、課金者が通信不良だけで購入を失った上に
23
+ // useIsLockedの再レンダーでクラッシュしていた(2026-09-26)
24
+ if (receipts === null)
25
+ return;
21
26
  const isExistedId = hasPurchasedItems(receipts, allFreeId);
22
27
  if (!isExistedId) {
23
28
  // 返金などをされていて、flaseの場合、このIDのアイテムを削除し、store更新
@@ -0,0 +1,3 @@
1
+ import React from "react";
2
+ declare const KeyboardCloseBar: React.FC;
3
+ export default KeyboardCloseBar;
@@ -0,0 +1,83 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ const react_1 = __importStar(require("react"));
27
+ const react_native_1 = require("react-native");
28
+ const native_1 = require("@react-navigation/native");
29
+ const react_native_safe_area_context_1 = require("react-native-safe-area-context");
30
+ const common_1 = require("@nakamura-123/common");
31
+ const lib_1 = require("@nakamura-123/lib");
32
+ // Androidは戻る操作でキーボードを閉じられるので、このバーはiOS専用
33
+ const isIOS = react_native_1.Platform.OS === "ios";
34
+ // iPadの分割・フローティングキーボードは画面下端に接しておらず、位置を合わせられない。
35
+ // 閉じるときのイベントも「画面外に出たキーボード」として同じ条件で弾かれる
36
+ const isDocked = (metrics) => {
37
+ const screenHeight = react_native_1.Dimensions.get("screen").height;
38
+ return Math.abs(metrics.screenY + metrics.height - screenHeight) < 1;
39
+ };
40
+ const KeyboardCloseBar = () => {
41
+ const insets = (0, react_native_safe_area_context_1.useSafeAreaInsets)();
42
+ const isFocused = (0, native_1.useIsFocused)();
43
+ const [keyboardHeight, setKeyboardHeight] = (0, react_1.useState)(null);
44
+ (0, react_1.useEffect)(() => {
45
+ if (!isIOS)
46
+ return;
47
+ const apply = (metrics) => {
48
+ if (!metrics || !isDocked(metrics))
49
+ return setKeyboardHeight(null);
50
+ setKeyboardHeight(metrics.height);
51
+ };
52
+ // 他画面から戻ったときはイベントを取りこぼすので、現在の状態から作る
53
+ apply(react_native_1.Keyboard.metrics());
54
+ const subs = [
55
+ react_native_1.Keyboard.addListener("keyboardWillShow", (e) => apply(e.endCoordinates)),
56
+ // 絵文字キーボードへの切替や変換候補バーの出入りでは willShow が再発火しない
57
+ react_native_1.Keyboard.addListener("keyboardWillChangeFrame", (e) => apply(e.endCoordinates)),
58
+ react_native_1.Keyboard.addListener("keyboardWillHide", () => apply()),
59
+ ];
60
+ return () => subs.forEach((sub) => sub.remove());
61
+ }, []);
62
+ if (!isIOS || keyboardHeight === null || !isFocused)
63
+ return null;
64
+ // 画面全体がSafeAreaViewの内側にあるぶん、このバーの座標系は画面下端より insets.bottom 高い
65
+ const bottom = Math.max(0, keyboardHeight - insets.bottom);
66
+ return (<react_native_1.TouchableOpacity style={[styles.container, { bottom }]} activeOpacity={0.7} onPress={() => react_native_1.Keyboard.dismiss()}>
67
+ <common_1.MyText fsize="sm">キーボードを閉じる ▼</common_1.MyText>
68
+ </react_native_1.TouchableOpacity>);
69
+ };
70
+ const styles = react_native_1.StyleSheet.create({
71
+ container: {
72
+ position: "absolute",
73
+ left: 0,
74
+ right: 0,
75
+ alignItems: "flex-end",
76
+ paddingVertical: 8,
77
+ paddingHorizontal: 15,
78
+ backgroundColor: lib_1.colors.bkBeige,
79
+ borderTopWidth: 1,
80
+ borderTopColor: lib_1.colors.ltBlack,
81
+ },
82
+ });
83
+ exports.default = KeyboardCloseBar;
@@ -12,6 +12,7 @@ const ExitQuizHook_1 = require("../hooks/ExitQuizHook");
12
12
  const Guide_1 = __importDefault(require("../component/Guide"));
13
13
  const QuizContentsDrill_1 = __importDefault(require("../quiz/QuizContentsDrill"));
14
14
  const QuizContentsJLPT_1 = __importDefault(require("../quiz/QuizContentsJLPT"));
15
+ const KeyboardCloseBar_1 = __importDefault(require("../component/KeyboardCloseBar"));
15
16
  const QuizPage = ({ navigation }) => {
16
17
  // スワイプの動作処理
17
18
  const mode = (0, quizHook_1.useGetMode)();
@@ -40,6 +41,8 @@ const QuizPage = ({ navigation }) => {
40
41
  <Check_1.default navigation={navigation}/>
41
42
  </Guide_1.default>
42
43
  </react_native_1.View>)}
44
+ {/* 記述解答欄のキーボードを閉じるバー。ScrollViewの外でないと画面下端に固定できない */}
45
+ <KeyboardCloseBar_1.default />
43
46
  </react_native_1.View>);
44
47
  };
45
48
  const styles = react_native_1.StyleSheet.create({
@@ -20,6 +20,7 @@ const InputBox = ({ index, text, baseText, isSave, }) => {
20
20
  const fsize = (0, react_redux_1.useSelector)((state) => state.quizCfg.inQuizOption.fsize);
21
21
  const fontSize = ((_a = lib_1.infoFontSize.find((data) => data.size === fsize)) === null || _a === void 0 ? void 0 : _a.fsize) || 14;
22
22
  const fontWeight = (0, react_redux_1.useSelector)((state) => state.quizCfg.inQuizOption.fWeight);
23
+ // メモ
23
24
  return (<react_native_1.View style={styles.container}>
24
25
  <common_1.GrowTextInput value={text} onChangeText={(writeTxt) => onChangeText(writeTxt)} multiline={true} style={styles.input} fontSize={fontSize} fontWeight={fontWeight}/>
25
26
  </react_native_1.View>);
@@ -1,2 +1,14 @@
1
+ import type { Store } from "@nakamura-123/types";
2
+ type InputData = {
3
+ isSave: boolean;
4
+ saveText: string;
5
+ };
1
6
  export declare const createBaseText: (baseTexts: string[]) => string;
2
7
  export declare const createTabTexts: (length: number) => string[];
8
+ export declare const getLastMode: (mode: Store.Mode, turn: number, activeTurn: number) => Store.Mode;
9
+ export declare const createLeaveData: (input: InputData[], lastMode: Store.Mode, isAnswered: boolean) => {
10
+ draftText: string | null;
11
+ saveInputs: string[];
12
+ };
13
+ export declare const isSameSaves: (before: readonly string[], after: readonly string[]) => boolean;
14
+ export {};
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createTabTexts = exports.createBaseText = void 0;
3
+ exports.isSameSaves = exports.createLeaveData = exports.getLastMode = exports.createTabTexts = exports.createBaseText = void 0;
4
4
  const createBaseText = (baseTexts) => {
5
5
  let baseText = "";
6
6
  const afterTexts = "】\n\n\n";
@@ -19,3 +19,32 @@ const createTabTexts = (length) => {
19
19
  return [...texts, "閉"]; // "閉" を追加して新しい配列を返す
20
20
  };
21
21
  exports.createTabTexts = createTabTexts;
22
+ // 離れる時点のstoreから、その問題を表示していたときのモードを求める(useGetModeと同じ計算)
23
+ const getLastMode = (mode, turn, activeTurn) => {
24
+ if (mode === "result")
25
+ return "result";
26
+ if (turn === activeTurn)
27
+ return mode;
28
+ if (turn < activeTurn)
29
+ return "check";
30
+ return "quiz";
31
+ };
32
+ exports.getLastMode = getLastMode;
33
+ // 画面を離れるときに、退避する書きかけとDBに保存する内容を決める
34
+ const createLeaveData = (input, lastMode, isAnswered) => {
35
+ // 回答欄をDBに入れないのは、クイズを解いている途中でまだ回答していないときだけ。
36
+ // 予習(結果モードで始まる)やパス・見直しでは、回答欄に書いたものも保存する
37
+ const isBeforeAnswer = lastMode === "quiz" && !isAnswered;
38
+ const answer = input[0];
39
+ const draftText = isBeforeAnswer && (answer === null || answer === void 0 ? void 0 : answer.isSave) ? answer.saveText : null;
40
+ const targets = isBeforeAnswer ? input.slice(1) : input;
41
+ const saveInputs = targets
42
+ .filter((data) => data.isSave)
43
+ .map((data) => data.saveText);
44
+ return { draftText, saveInputs };
45
+ };
46
+ exports.createLeaveData = createLeaveData;
47
+ // 中身が変わっていないなら書き込まないための比較
48
+ const isSameSaves = (before, after) => before.length === after.length &&
49
+ before.every((text, i) => text === after[i]);
50
+ exports.isSameSaves = isSameSaves;
@@ -94,21 +94,15 @@ const InputNav = ({ question }) => {
94
94
  if (!isLoadedRef.current)
95
95
  return;
96
96
  const { quiz } = store.getState();
97
- const input = quiz.currentInfo.input;
97
+ const { mode, activeTurn } = quiz.currentInfo.state;
98
+ const lastMode = (0, InputFnc_1.getLastMode)(mode, turn, activeTurn);
98
99
  const isAnswered = ((_a = quiz.quizList[turn]) === null || _a === void 0 ? void 0 : _a.isCorrected) !== undefined;
99
- // 未回答なら回答欄の書きかけを退避して戻ったときに復元する。回答済みなら書きかけは役目を終えるので消す
100
- const answer = input[0];
101
- const draftText = !isAnswered && (answer === null || answer === void 0 ? void 0 : answer.isSave) ? answer.saveText : null;
100
+ const { draftText, saveInputs } = (0, InputFnc_1.createLeaveData)(quiz.currentInfo.input, lastMode, isAnswered);
101
+ // 回答前なら書きかけを退避して戻ったときに復元する。それ以外では書きかけは役目を終えるので消す
102
102
  dispatch({ type: "quiz/setInputDraft", payload: { turn, text: draftText } });
103
- const targets = isAnswered ? input : input.slice(1);
104
- const saveInputs = targets
105
- .filter((data) => data.isSave)
106
- .map((data) => data.saveText);
107
103
  // 中身が変わっていないなら書き込まない
108
104
  const before = ((_b = db_1.InputModel.getInput(realm, inputId)) === null || _b === void 0 ? void 0 : _b.saveInputs) || [];
109
- const isSame = before.length === saveInputs.length &&
110
- before.every((text, i) => text === saveInputs[i]);
111
- if (isSame)
105
+ if ((0, InputFnc_1.isSameSaves)(before, saveInputs))
112
106
  return;
113
107
  db_1.InputModel.updateSaveText(realm, [{ id: inputId, saveInputs }]);
114
108
  };