From f19600a3af8a37f025eaaee04eb3acd087beaba4 Mon Sep 17 00:00:00 2001 From: harukin-expo-dev-env Date: Mon, 23 Mar 2026 06:21:26 +0000 Subject: [PATCH] =?UTF-8?q?fix:=20ProgressStyle=20Point=E4=BD=8D=E7=BD=AE?= =?UTF-8?q?=E8=A8=88=E7=AE=97=E3=82=92=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Point(0) は @IntRange(from=1) 違反 → coerceIn(1, max) で修正 - Segment length を均等固定値(100)にして丸め誤差を排除 - progressMax = numSegments * 100 で座標系を統一 - Point position = stationIndex * 100 で全駅等分に忠実に配置 - デバッグログにpointPositionsを追加(Metroコンソールで確認可能) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../TrainFollowNotificationBuilder.kt | 33 +++++++++++-------- modules/expo-live-activity/src/index.ts | 5 +++ 2 files changed, 24 insertions(+), 14 deletions(-) diff --git a/modules/expo-live-activity/android/src/main/java/expo/modules/liveactivity/TrainFollowNotificationBuilder.kt b/modules/expo-live-activity/android/src/main/java/expo/modules/liveactivity/TrainFollowNotificationBuilder.kt index a4973bc..6b990cc 100644 --- a/modules/expo-live-activity/android/src/main/java/expo/modules/liveactivity/TrainFollowNotificationBuilder.kt +++ b/modules/expo-live-activity/android/src/main/java/expo/modules/liveactivity/TrainFollowNotificationBuilder.kt @@ -7,7 +7,6 @@ import android.graphics.Color import android.os.Build import androidx.annotation.RequiresApi import androidx.core.app.NotificationCompat -import kotlin.math.roundToInt object TrainFollowNotificationBuilder { fun build( @@ -102,10 +101,12 @@ object TrainFollowNotificationBuilder { val numSegments = total - 1 val curIdx = currentIndex.coerceIn(0, total - 1) - // 各駅の位置を0~10000の範囲で計算(全駅等分) - val positions = (0 until total).map { i -> - if (numSegments == 0) 0 - else (i * 10000.0 / numSegments).roundToInt().coerceIn(0, 10000) + if (numSegments == 0) { + return NotificationCompat.ProgressStyle() + .setProgressSegments(listOf( + NotificationCompat.ProgressStyle.Segment(1).setColor(trainColor) + )) + .setProgress(1) } val dimColor = Color.argb( @@ -115,31 +116,35 @@ object TrainFollowNotificationBuilder { Color.blue(trainColor) ) + // 各セグメントの長さを均等に(合計 = numSegments * 100) + val segmentLength = 100 + val progressMax = numSegments * segmentLength + // セグメント: 通過済み=trainColor, 未通過=dimColor val segments = (0 until numSegments).map { i -> - val length = positions[i + 1] - positions[i] val segColor = if (i < curIdx) trainColor else dimColor - NotificationCompat.ProgressStyle.Segment(length).setColor(segColor) + NotificationCompat.ProgressStyle.Segment(segmentLength).setColor(segColor) } - // ポイント: 停車駅のみ表示(通過駅はポイントなし) + // ポイント位置: 駅 i → i * segmentLength (ただし最小値 1) val stopPoints = mutableListOf() stations.forEachIndexed { i, station -> if (station.isStop) { + val pos = (i * segmentLength).coerceIn(1, progressMax) val ptColor = if (i <= curIdx) trainColor else dimColor stopPoints.add( - NotificationCompat.ProgressStyle.Point(positions[i]).setColor(ptColor) + NotificationCompat.ProgressStyle.Point(pos).setColor(ptColor) ) } } - // 現在地 = 駅位置に対応する進捗値 - val progressValue = positions[curIdx] + // 現在地の進捗値 + val progressValue = (curIdx * segmentLength).coerceIn(0, progressMax) android.util.Log.d("ProgressStyle", - "total=$total stops=${stopPoints.size} curIdx=$curIdx progressValue=$progressValue " + - "stopPositions=${stopPoints.map { "?" }} " + - "stationNames=${stations.filter { it.isStop }.map { it.name }}" + "total=$total stops=${stopPoints.size} curIdx=$curIdx " + + "progressMax=$progressMax progressValue=$progressValue " + + "pointPositions=${stopPoints.joinToString(",") { "${it.position}" }}" ) return NotificationCompat.ProgressStyle() diff --git a/modules/expo-live-activity/src/index.ts b/modules/expo-live-activity/src/index.ts index d6f1001..6309644 100644 --- a/modules/expo-live-activity/src/index.ts +++ b/modules/expo-live-activity/src/index.ts @@ -284,6 +284,11 @@ export async function updateTrainFollowActivity( const totalStations = state.allStations?.length ?? state.stationStops?.length ?? 0; const stopsJson = JSON.stringify(state.stationStops ?? []); const allStationsJson = JSON.stringify(state.allStations ?? []); + const stopCount = state.allStations?.filter(s => s.isStop).length ?? 0; + console.log(`[LiveActivity] update: currentIdx=${currentIdx} total=${totalStations} stops=${stopCount} allStations=${state.allStations?.length ?? 0} currentStation=${state.currentStation} nextStation=${state.nextStation}`); + if (state.allStations && state.allStations.length > 0) { + console.log(`[LiveActivity] first5=${JSON.stringify(state.allStations.slice(0, 5))} around_cur=${JSON.stringify(state.allStations.slice(Math.max(0, currentIdx - 1), currentIdx + 3))}`); + } await ExpoLiveActivityModule.updateTrainFollowNotification({ title, body, color, progressCurrent: currentIdx,