|
|
@@ -3,7 +3,7 @@ import { ChooseScenarioBtn } from "@/features/common/SpecBtns";
|
|
|
import { jumpPage } from "@/features/trackTimeDuration/hooks/Common";
|
|
|
import { View, Text, Picker, ScrollView } from "@tarojs/components";
|
|
|
import { useDidShow, useRouter } from "@tarojs/taro";
|
|
|
-import { useEffect, useState } from "react";
|
|
|
+import { useEffect, useRef, useState } from "react";
|
|
|
import './ChooseScenario.scss';
|
|
|
import PickerViews from "@/components/input/PickerViews";
|
|
|
import { useDispatch, useSelector } from "react-redux";
|
|
|
@@ -15,6 +15,12 @@ import { IconCheck } from "@/components/basic/Icons";
|
|
|
import Rings2, { BgRing, RingCommon, TargetRing } from '@/features/trackTimeDuration/components/Rings';
|
|
|
import { useTranslation } from "react-i18next";
|
|
|
|
|
|
+let ScrollViewRN
|
|
|
+if (process.env.TARO_ENV === 'rn') {
|
|
|
+ ScrollViewRN = require('react-native').ScrollView
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
export default function Suggest() {
|
|
|
let router: any = null
|
|
|
var navigation: any = null
|
|
|
@@ -39,6 +45,7 @@ export default function Suggest() {
|
|
|
const [fastRecommendIndex, setFastRecommendIndex] = useState(-1)
|
|
|
const [fastLastIndex, setFastLastIndex] = useState(-1)
|
|
|
const { t } = useTranslation()
|
|
|
+ const scrollViewRef = useRef(null);
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
@@ -105,7 +112,11 @@ export default function Suggest() {
|
|
|
setSuggestItem(array)
|
|
|
setSuggestIndex(currentIndex)
|
|
|
setScrollTop(currentIndex * rpxToPx(244) + 50)
|
|
|
- // setScrollTop(currentIndex * 100-30)
|
|
|
+ if (process.env.TARO_ENV=='rn'){
|
|
|
+ setTimeout(()=>{
|
|
|
+ (scrollViewRef.current as any).scrollTo({x:0,y:currentIndex * rpxToPx(244)+20,animated:true})
|
|
|
+ },500)
|
|
|
+ }
|
|
|
}
|
|
|
else if (pageStep == 3) {
|
|
|
var obj = target.sleep.schedule.sleep
|
|
|
@@ -459,85 +470,100 @@ export default function Suggest() {
|
|
|
return (end - start) / 1440 * 2 * Math.PI
|
|
|
}
|
|
|
|
|
|
- function suggestList() {
|
|
|
- if (pageStep == 1) {
|
|
|
- return <ScrollView scrollY style={{ height: 400 }} scrollTop={scrollTop}>
|
|
|
- <View style={{ flexDirection: 'column', display: 'flex' }}>
|
|
|
- {
|
|
|
- suggestItems.map((item: any, index: number) => {
|
|
|
- return <View key={index} className={suggestIndex == index ? 'item1 item_sel1' : 'item1'} onClick={() => setSuggestIndex(index)}>
|
|
|
- <View style={{ flexShrink: 0, display: 'flex', width: 74, height: 74, marginRight: rpxToPx(24) }}>
|
|
|
- <Rings2 common={ringCommon()}
|
|
|
- bgRing={bgRing}
|
|
|
- targetRing={targetRing(item.time, target.fast.schedule.fast.end_time, true, suggestIndex == index)}
|
|
|
- dotList={point(true, index == suggestIndex)}
|
|
|
- canvasId={new Date().getTime() + index * 5} />
|
|
|
- </View>
|
|
|
- <View style={{flex:1}}>
|
|
|
-
|
|
|
- <View className="suggest_item_title">{item.hours} hours</View>
|
|
|
-
|
|
|
- <View className="suggest_item_desc">{index == suggestIndex ?
|
|
|
- t('feature.suggest.fast_desc', { start_time: item.hours, end_time: item.left }) :
|
|
|
- t('feature.suggest.intermitent_fast', { data: `${item.hours}/${item.left}` })
|
|
|
- }</View>
|
|
|
- {
|
|
|
- index == suggestIndex &&
|
|
|
- <View className="suggest_choose">
|
|
|
- <View style={{ color: ColorType.fast }}>{t('feature.suggest.start_fast_time', { time: item.time })}</View>
|
|
|
-
|
|
|
- </View>
|
|
|
- }
|
|
|
+ function scrollContent() {
|
|
|
+ return <View style={{ flexDirection: 'column', display: 'flex' }}>
|
|
|
+ {
|
|
|
+ suggestItems.map((item: any, index: number) => {
|
|
|
+ return <View key={index} className={suggestIndex == index ? 'item1 item_sel1' : 'item1'} onClick={() => setSuggestIndex(index)}>
|
|
|
+ <View style={{ flexShrink: 0, display: 'flex', width: 74, height: 74, marginRight: rpxToPx(24) }}>
|
|
|
+ <Rings2 common={ringCommon()}
|
|
|
+ bgRing={bgRing}
|
|
|
+ targetRing={targetRing(item.time, target.fast.schedule.fast.end_time, true, suggestIndex == index)}
|
|
|
+ dotList={point(true, index == suggestIndex)}
|
|
|
+ canvasId={new Date().getTime() + index * 5} />
|
|
|
+ </View>
|
|
|
+ <View style={{ flex: 1 }}>
|
|
|
+
|
|
|
+ <View className="suggest_item_title">{item.hours} hours</View>
|
|
|
+
|
|
|
+ <View className="suggest_item_desc">{index == suggestIndex ?
|
|
|
+ t('feature.suggest.fast_desc', { start_time: item.hours, end_time: item.left }) :
|
|
|
+ t('feature.suggest.intermitent_fast', { data: `${item.hours}/${item.left}` })
|
|
|
+ }</View>
|
|
|
+ {
|
|
|
+ index == suggestIndex &&
|
|
|
+ <View className="suggest_choose">
|
|
|
+ <View style={{ color: ColorType.fast }}>{t('feature.suggest.start_fast_time', { time: item.time })}</View>
|
|
|
|
|
|
</View>
|
|
|
- {
|
|
|
- index == suggestIndex && <View className="choose_item_check_bg">
|
|
|
- <IconCheck color={ColorType.fast} width={24} height={24} />
|
|
|
- </View>
|
|
|
- }
|
|
|
- <View className='suggest_fast_tag_bg'>
|
|
|
- {
|
|
|
- index == fastRecommendIndex &&
|
|
|
- <View className='suggest_fast_tag'>{t('feature.suggest.popular')}</View>
|
|
|
- }
|
|
|
- {
|
|
|
- index == fastLastIndex &&
|
|
|
- <View className='suggest_fast_tag'>{t('feature.suggest.recent')}</View>
|
|
|
- }
|
|
|
- </View>
|
|
|
+ }
|
|
|
+
|
|
|
+ </View>
|
|
|
+ {
|
|
|
+ index == suggestIndex && <View className="choose_item_check_bg">
|
|
|
+ <IconCheck color={ColorType.fast} width={24} height={24} />
|
|
|
</View>
|
|
|
+ }
|
|
|
+ <View className='suggest_fast_tag_bg'>
|
|
|
+ {
|
|
|
+ index == fastRecommendIndex &&
|
|
|
+ <View className='suggest_fast_tag'>{t('feature.suggest.popular')}</View>
|
|
|
+ }
|
|
|
+ {
|
|
|
+ index == fastLastIndex &&
|
|
|
+ <View className='suggest_fast_tag'>{t('feature.suggest.recent')}</View>
|
|
|
+ }
|
|
|
+ </View>
|
|
|
+ </View>
|
|
|
|
|
|
- // return <View onClick={() => {
|
|
|
- // setSuggestIndex(index)
|
|
|
- // }} key={index} className={index == suggestIndex ? 'item_choose_selected' : 'item_choose'}>
|
|
|
- // <View style={{ display: 'flex', flexDirection: 'row', alignItems: 'center' }}>
|
|
|
- // <View className="suggest_item_title">{item.hours} hours</View>
|
|
|
- // <View style={{ flex: 1 }} />
|
|
|
- // {
|
|
|
- // index == fastRecommendIndex &&
|
|
|
- // <View style={{ color: '#fff' }}>Popular</View>
|
|
|
- // }
|
|
|
- // {
|
|
|
- // index == fastLastIndex &&
|
|
|
- // <View style={{ color: '#fff', marginLeft: 5 }}>Recent</View>
|
|
|
- // }
|
|
|
- // </View>
|
|
|
-
|
|
|
- // <View className="suggest_item_desc">{index == suggestIndex ? `${item.hours} hours fasting / ${item.left} hours eating` : `${item.hours}/${item.left} Intermittent Fasting`}</View>
|
|
|
- // {
|
|
|
- // index == suggestIndex &&
|
|
|
- // <View className="suggest_choose">
|
|
|
- // <View style={{ color: ColorType.fast }}>Start fasting at {item.time}</View>
|
|
|
- // <IconCheck color={ColorType.fast} width={38} height={26} />
|
|
|
- // </View>
|
|
|
- // }
|
|
|
-
|
|
|
- // </View>
|
|
|
- })
|
|
|
- }
|
|
|
- </View>
|
|
|
+ // return <View onClick={() => {
|
|
|
+ // setSuggestIndex(index)
|
|
|
+ // }} key={index} className={index == suggestIndex ? 'item_choose_selected' : 'item_choose'}>
|
|
|
+ // <View style={{ display: 'flex', flexDirection: 'row', alignItems: 'center' }}>
|
|
|
+ // <View className="suggest_item_title">{item.hours} hours</View>
|
|
|
+ // <View style={{ flex: 1 }} />
|
|
|
+ // {
|
|
|
+ // index == fastRecommendIndex &&
|
|
|
+ // <View style={{ color: '#fff' }}>Popular</View>
|
|
|
+ // }
|
|
|
+ // {
|
|
|
+ // index == fastLastIndex &&
|
|
|
+ // <View style={{ color: '#fff', marginLeft: 5 }}>Recent</View>
|
|
|
+ // }
|
|
|
+ // </View>
|
|
|
+
|
|
|
+ // <View className="suggest_item_desc">{index == suggestIndex ? `${item.hours} hours fasting / ${item.left} hours eating` : `${item.hours}/${item.left} Intermittent Fasting`}</View>
|
|
|
+ // {
|
|
|
+ // index == suggestIndex &&
|
|
|
+ // <View className="suggest_choose">
|
|
|
+ // <View style={{ color: ColorType.fast }}>Start fasting at {item.time}</View>
|
|
|
+ // <IconCheck color={ColorType.fast} width={38} height={26} />
|
|
|
+ // </View>
|
|
|
+ // }
|
|
|
+
|
|
|
+ // </View>
|
|
|
+ })
|
|
|
+ }
|
|
|
+ </View>
|
|
|
+ }
|
|
|
+
|
|
|
+ function suggestList() {
|
|
|
+ if (pageStep == 1 && process.env.TARO_ENV === 'weapp') {
|
|
|
+ return <ScrollView scrollY style={{ height: 400 }} scrollTop={scrollTop}>
|
|
|
+ {
|
|
|
+ scrollContent()
|
|
|
+ }
|
|
|
</ScrollView>
|
|
|
}
|
|
|
+
|
|
|
+ if (pageStep == 1 && process.env.TARO_ENV === 'rn') {
|
|
|
+ return <ScrollViewRN style={{ height: 400 }} ref={scrollViewRef}>
|
|
|
+ {
|
|
|
+ scrollContent()
|
|
|
+ }
|
|
|
+ </ScrollViewRN>
|
|
|
+ }
|
|
|
+
|
|
|
return <View style={{ flex: 1, overflow: 'scroll' }}>
|
|
|
{
|
|
|
suggestItems.map((item: any, index: number) => {
|