@ray-js/ipc-player-integration 0.0.35-beta.12 → 0.0.35-beta.13
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.
|
@@ -8,7 +8,7 @@ import { useStore } from '../ctx/store';
|
|
|
8
8
|
import { useComponentHideState } from './hooks';
|
|
9
9
|
import { TrialBadge, useTrialBadge } from '../widgets/trialBadge';
|
|
10
10
|
/** 右侧透明渐变宽度,用于提示横向可滑动 */
|
|
11
|
-
const FADE_MASK = 'linear-gradient(to right, #000 calc(100% -
|
|
11
|
+
const FADE_MASK = 'linear-gradient(to right, #000 calc(100% - 48px), transparent 100%)';
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
14
|
* 试用徽章在不同 screenType 下的容器样式。
|
|
@@ -58,15 +58,10 @@ const BottomLeftContent = _ref => {
|
|
|
58
58
|
const tryExp = bottomLeftContent === null || bottomLeftContent === void 0 ? void 0 : bottomLeftContent.find(item => item.id === 'TryExperience');
|
|
59
59
|
return (_trialRemainingSec = tryExp === null || tryExp === void 0 || (_tryExp$initProps2 = tryExp.initProps) === null || _tryExp$initProps2 === void 0 ? void 0 : _tryExp$initProps2.trialRemainingSec) !== null && _trialRemainingSec !== void 0 ? _trialRemainingSec : 0;
|
|
60
60
|
}, [bottomLeftContent]);
|
|
61
|
-
const refreshToken = useMemo(() => {
|
|
62
|
-
var _refreshToken, _tryExp$initProps3;
|
|
63
|
-
const tryExp = bottomLeftContent === null || bottomLeftContent === void 0 ? void 0 : bottomLeftContent.find(item => item.id === 'TryExperience');
|
|
64
|
-
return (_refreshToken = tryExp === null || tryExp === void 0 || (_tryExp$initProps3 = tryExp.initProps) === null || _tryExp$initProps3 === void 0 ? void 0 : _tryExp$initProps3.refreshToken) !== null && _refreshToken !== void 0 ? _refreshToken : 0;
|
|
65
|
-
}, [bottomLeftContent]);
|
|
66
61
|
const isLowPhone = useMemo(() => {
|
|
67
|
-
var _isLowPhone, _tryExp$
|
|
62
|
+
var _isLowPhone, _tryExp$initProps3;
|
|
68
63
|
const tryExp = bottomLeftContent === null || bottomLeftContent === void 0 ? void 0 : bottomLeftContent.find(item => item.id === 'TryExperience');
|
|
69
|
-
return (_isLowPhone = tryExp === null || tryExp === void 0 || (_tryExp$
|
|
64
|
+
return (_isLowPhone = tryExp === null || tryExp === void 0 || (_tryExp$initProps3 = tryExp.initProps) === null || _tryExp$initProps3 === void 0 ? void 0 : _tryExp$initProps3.isLowPhone) !== null && _isLowPhone !== void 0 ? _isLowPhone : false;
|
|
70
65
|
}, []);
|
|
71
66
|
const [shouldHide] = useComponentHideState();
|
|
72
67
|
const {
|
|
@@ -76,6 +71,13 @@ const BottomLeftContent = _ref => {
|
|
|
76
71
|
} = useTrialBadge(ctx.event, ctx.devId, trialRemainingSec);
|
|
77
72
|
const paddingLeftPx = screenType === 'vertical' ? 0 : 25;
|
|
78
73
|
const trialBadgeWrapStyle = screenType === 'vertical' ? TRIAL_BADGE_WRAP_STYLE_VERTICAL : TRIAL_BADGE_WRAP_STYLE_FULL;
|
|
74
|
+
const showBadge = showSmartImageQuality && showTrialBadge && canOpenSettings && !isLowPhone && trialRemainingSec > 0;
|
|
75
|
+
const containerHeight = (() => {
|
|
76
|
+
if (showBadge) {
|
|
77
|
+
return screenType === 'vertical' ? '40px' : '58px';
|
|
78
|
+
}
|
|
79
|
+
return screenType === 'vertical' ? shouldHide ? '41px' : '40px' : shouldHide ? '57px' : '58px';
|
|
80
|
+
})();
|
|
79
81
|
return /*#__PURE__*/React.createElement(CoverView, {
|
|
80
82
|
className: clsx('ipc-player-bottom-left-content-wrap')
|
|
81
83
|
// 注意:不要在这里覆盖 position,CSS 类已经设置 position: absolute; left: 0; bottom: 0
|
|
@@ -83,19 +85,17 @@ const BottomLeftContent = _ref => {
|
|
|
83
85
|
,
|
|
84
86
|
style: {
|
|
85
87
|
right: `${reservedRight}px`,
|
|
86
|
-
height:
|
|
88
|
+
height: containerHeight
|
|
87
89
|
}
|
|
88
|
-
},
|
|
90
|
+
}, showBadge && /*#__PURE__*/React.createElement(View, {
|
|
89
91
|
className: clsx('bottom-left-item-container'),
|
|
90
92
|
style: _objectSpread(_objectSpread({}, trialBadgeWrapStyle), {}, {
|
|
91
|
-
transform: shouldHide ? 'translateY(40px)' : 'translateY(0)',
|
|
92
93
|
opacity: shouldHide ? 0 : 1,
|
|
93
|
-
|
|
94
|
+
pointerEvents: shouldHide ? 'none' : 'auto'
|
|
94
95
|
})
|
|
95
96
|
}, /*#__PURE__*/React.createElement(TrialBadge, {
|
|
96
97
|
brandColor: brandColor,
|
|
97
98
|
trialRemainingSec: trialRemainingSec,
|
|
98
|
-
refreshToken: refreshToken,
|
|
99
99
|
onSubscribe: handleTrialSubscribe,
|
|
100
100
|
onCountdownEnd: handleCountdownEnd
|
|
101
101
|
})), /*#__PURE__*/React.createElement(View, {
|
package/lib/ui/ui.js
CHANGED
|
@@ -448,25 +448,22 @@ export const IPCPlayerIntegration = /*#__PURE__*/React.memo(props => {
|
|
|
448
448
|
setVerticalMic(verticalMic);
|
|
449
449
|
}, [brandColor, verticalMic]);
|
|
450
450
|
const refreshSmartImageQuality = useMemoizedFn(async () => {
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
//
|
|
454
|
-
//
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
};
|
|
462
|
-
}
|
|
451
|
+
const res = await getSmartImageQualityState(devId);
|
|
452
|
+
if (res === undefined) return;
|
|
453
|
+
// 可调试
|
|
454
|
+
// res = {
|
|
455
|
+
// isPurchase: false,
|
|
456
|
+
// buttonState: 0,
|
|
457
|
+
// trialRemainingSec: 20,
|
|
458
|
+
// canOpenSettings: true,
|
|
459
|
+
// };
|
|
460
|
+
console.log('res===refreshSmartImageQuality', res);
|
|
463
461
|
updatePlayerWidgetProps(instance, 'bottomLeft', 'TryExperience', {
|
|
464
462
|
isPurchase: res.isPurchase,
|
|
465
463
|
buttonState: res.buttonState,
|
|
466
464
|
trialRemainingSec: res.trialRemainingSec,
|
|
467
465
|
canOpenSettings: res.canOpenSettings,
|
|
468
|
-
isLowPhone: isLowPhoneRef.current
|
|
469
|
-
refreshToken: Date.now()
|
|
466
|
+
isLowPhone: isLowPhoneRef.current
|
|
470
467
|
});
|
|
471
468
|
});
|
|
472
469
|
useEffect(() => {
|
|
@@ -6,12 +6,10 @@ type Props = {
|
|
|
6
6
|
brandColor?: string;
|
|
7
7
|
/** 试看倒计时初始秒数,来源于 smartImageQualityState.trialRemainingSec */
|
|
8
8
|
trialRemainingSec?: number;
|
|
9
|
-
/** 刷新令牌,变化时重置倒计时状态 */
|
|
10
|
-
refreshToken?: number;
|
|
11
9
|
/** 点击「开通」按钮回调 */
|
|
12
10
|
onSubscribe?: () => void;
|
|
13
11
|
/** 倒计时归零时触发,本组件保证整个生命周期内只回调一次 */
|
|
14
12
|
onCountdownEnd?: () => void;
|
|
15
13
|
};
|
|
16
|
-
export declare const TrialBadge: ({ className, brandColor, trialRemainingSec,
|
|
14
|
+
export declare const TrialBadge: ({ className, brandColor, trialRemainingSec, onSubscribe, onCountdownEnd, }: Props) => React.JSX.Element;
|
|
17
15
|
export { useTrialBadge } from './useTrialBadge';
|
|
@@ -18,21 +18,25 @@ export const TrialBadge = _ref => {
|
|
|
18
18
|
className,
|
|
19
19
|
brandColor = FALLBACK_BRAND_COLOR,
|
|
20
20
|
trialRemainingSec = 0,
|
|
21
|
-
refreshToken,
|
|
22
21
|
onSubscribe,
|
|
23
22
|
onCountdownEnd
|
|
24
23
|
} = _ref;
|
|
25
24
|
const [remainingSec, setRemainingSec] = useState(Math.max(0, Math.floor(trialRemainingSec)));
|
|
26
|
-
/** 防止 onCountdownEnd 被重复触发;同时持有最新回调,避免依赖变化导致 effect 重跑 */
|
|
27
25
|
const endedRef = useRef(false);
|
|
28
26
|
const onCountdownEndRef = useRef(onCountdownEnd);
|
|
29
27
|
onCountdownEndRef.current = onCountdownEnd;
|
|
28
|
+
const startTimeRef = useRef(Date.now());
|
|
29
|
+
const initialSecRef = useRef(Math.max(0, Math.floor(trialRemainingSec)));
|
|
30
30
|
useEffect(() => {
|
|
31
|
+
console.log('res===trialRemainingSec', trialRemainingSec);
|
|
32
|
+
const sec = Math.max(0, Math.floor(trialRemainingSec));
|
|
31
33
|
endedRef.current = false;
|
|
32
|
-
|
|
33
|
-
|
|
34
|
+
initialSecRef.current = sec;
|
|
35
|
+
startTimeRef.current = Date.now();
|
|
36
|
+
setRemainingSec(sec);
|
|
37
|
+
}, [trialRemainingSec]);
|
|
34
38
|
useEffect(() => {
|
|
35
|
-
if (
|
|
39
|
+
if (trialRemainingSec <= 0) {
|
|
36
40
|
if (!endedRef.current) {
|
|
37
41
|
var _onCountdownEndRef$cu;
|
|
38
42
|
endedRef.current = true;
|
|
@@ -41,22 +45,20 @@ export const TrialBadge = _ref => {
|
|
|
41
45
|
return undefined;
|
|
42
46
|
}
|
|
43
47
|
const timer = setInterval(() => {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
return 0;
|
|
48
|
+
const elapsed = Math.floor((Date.now() - startTimeRef.current) / 1000);
|
|
49
|
+
const next = Math.max(0, initialSecRef.current - elapsed);
|
|
50
|
+
setRemainingSec(next);
|
|
51
|
+
if (next <= 0) {
|
|
52
|
+
clearInterval(timer);
|
|
53
|
+
if (!endedRef.current) {
|
|
54
|
+
var _onCountdownEndRef$cu2;
|
|
55
|
+
endedRef.current = true;
|
|
56
|
+
(_onCountdownEndRef$cu2 = onCountdownEndRef.current) === null || _onCountdownEndRef$cu2 === void 0 || _onCountdownEndRef$cu2.call(onCountdownEndRef);
|
|
54
57
|
}
|
|
55
|
-
|
|
56
|
-
});
|
|
58
|
+
}
|
|
57
59
|
}, 1000);
|
|
58
60
|
return () => clearInterval(timer);
|
|
59
|
-
}, [trialRemainingSec
|
|
61
|
+
}, [trialRemainingSec]);
|
|
60
62
|
const countdownText = formatCountdown(remainingSec);
|
|
61
63
|
return /*#__PURE__*/React.createElement(View, {
|
|
62
64
|
className: clsx('ipc-player-trial-badge', className)
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
2
2
|
import { View, Image, getSystemInfoSync, showToast } from '@ray-js/ray';
|
|
3
3
|
import clsx from 'clsx';
|
|
4
|
-
import React, { useState, useEffect, useCallback } from 'react';
|
|
4
|
+
import React, { useState, useEffect, useCallback, useRef } from 'react';
|
|
5
5
|
import { useStore } from '../../ctx/store';
|
|
6
6
|
import Strings from '../../i18n';
|
|
7
7
|
import { getAIFrameFeature, gotoAIDrawMiniProgram, setAIFrameFeature } from '../../utils';
|
|
@@ -60,6 +60,7 @@ export const TryExperience = props => {
|
|
|
60
60
|
recording: props.recording
|
|
61
61
|
});
|
|
62
62
|
const [imgSrc, setImgSrc] = useState();
|
|
63
|
+
const lockRef = useRef(false);
|
|
63
64
|
useEffect(() => {
|
|
64
65
|
updateImgSrc();
|
|
65
66
|
}, [buttonState]);
|
|
@@ -77,6 +78,7 @@ export const TryExperience = props => {
|
|
|
77
78
|
}
|
|
78
79
|
}, [buttonState]);
|
|
79
80
|
const onTryExperience = useCallback(async () => {
|
|
81
|
+
if (lockRef.current) return;
|
|
80
82
|
if (isLowPhone) {
|
|
81
83
|
showToast({
|
|
82
84
|
title: Strings.getLang('ipc_player_low_phone_not_support'),
|
|
@@ -91,6 +93,7 @@ export const TryExperience = props => {
|
|
|
91
93
|
});
|
|
92
94
|
return;
|
|
93
95
|
}
|
|
96
|
+
lockRef.current = true;
|
|
94
97
|
try {
|
|
95
98
|
const getAI = await getAIFrameFeature(devId);
|
|
96
99
|
if (buttonState === TryExperienceStatus.Open) {
|
|
@@ -134,6 +137,8 @@ export const TryExperience = props => {
|
|
|
134
137
|
}
|
|
135
138
|
} catch (error) {
|
|
136
139
|
//
|
|
140
|
+
} finally {
|
|
141
|
+
lockRef.current = false;
|
|
137
142
|
}
|
|
138
143
|
}, [buttonState, recording, isPurchase, trialRemainingSec]);
|
|
139
144
|
if (hideTryExperienceMenu) {
|