Skip to content

Commit

Permalink
- 支持 @magma 提供的第三方OSS域名
Browse files Browse the repository at this point in the history
  • Loading branch information
czy0729 committed May 9, 2022
1 parent 5f561fc commit a295613
Show file tree
Hide file tree
Showing 14 changed files with 404 additions and 268 deletions.
10 changes: 3 additions & 7 deletions android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -222,15 +222,11 @@ dependencies {
implementation 'com.umeng.umsdk:analytics:8.0.0' // 统计

// 如果你需要支持GIF动图
// implementation "com.facebook.fresco:animated-gif:2.0.0"
implementation "com.facebook.fresco:animated-gif:2.0.0"

// 如果你需要支持WebP格式,包括WebP动图
// implementation "com.facebook.fresco:animated-webp:2.1.0"
// implementation "com.facebook.fresco:webpsupport:2.0.0"

// implementation project(':react-native-fs')
// implementation project(':rn-fetch-blob')
// implementation project(':@react-native-community_cameraroll')
implementation "com.facebook.fresco:animated-webp:2.1.0"
implementation "com.facebook.fresco:webpsupport:2.0.0"

debugImplementation("com.facebook.flipper:flipper:${FLIPPER_VERSION}") {
exclude group:'com.facebook.fbjni'
Expand Down
20 changes: 14 additions & 6 deletions config.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,26 @@
/*
* 开发调试时用配置
* @Author: czy0729
* @Date: 2019-06-02 14:42:28
* @Last Modified by: czy0729
* @Last Modified time: 2022-04-28 19:45:57
* @Last Modified time: 2022-05-10 07:25:34
*/
export const INIT_DEV_DARK = '' // '' 不控制 | true 强制黑暗 | false 强制白天
/** 强制主题模式: '' => 不控制 | true => 强制黑暗 | false => 强制白天 */
export const INIT_DEV_DARK = ''

/** <BottomTabNavigator> 初始路由 */
export const INIT_ROUTE = 'Home'
export const RERENDER_SHOW = /ZZZ/
// export const RERENDER_SHOW = /Rakuen\.(.+?)\.Main/

// 是否开发模式
/** 观察组件 re-render 用 */
export const RERENDER_SHOW = /ZZZ/ // /Rakuen\.(.+?)\.Main/

/** 是否开发模式 */
export const DEV = global.__DEV__
export const TEXT_ONLY = DEV

/** 开发模式中是否不显示图片 */
export const TEXT_ONLY = DEV ? !DEV : false

/** 路由覆盖配置 */
export default {
initialRouteName: 'HomeTab', // HomeTab Discovery Subject Tinygrail BilibiliSync
initialRouteParams: {
Expand Down
81 changes: 40 additions & 41 deletions src/components/@/react-native-render-html/src/HTML.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@
* @Author: czy0729
* @Date: 2019-08-14 16:25:55
* @Last Modified by: czy0729
* @Last Modified time: 2021-10-23 10:51:02
* @Last Modified time: 2022-05-09 13:27:11
*/
import React, { PureComponent } from 'react'
import PropTypes from 'prop-types'
import { View, Text, ViewPropTypes, ActivityIndicator, Dimensions } from 'react-native'
import { View, Text, ActivityIndicator, Dimensions } from 'react-native'
import {
cssStringToRNStyle,
_getElementClassStyles,
Expand All @@ -34,39 +33,39 @@ import { IOS } from '@constants'
import * as HTMLRenderers from './HTMLRenderers'

export default class HTML extends PureComponent {
static propTypes = {
renderers: PropTypes.object.isRequired,
ignoredTags: PropTypes.array.isRequired,
ignoredStyles: PropTypes.array.isRequired,
allowedStyles: PropTypes.array,
decodeEntities: PropTypes.bool.isRequired,
debug: PropTypes.bool.isRequired,
listsPrefixesRenderers: PropTypes.object,
ignoreNodesFunction: PropTypes.func,
alterData: PropTypes.func,
alterChildren: PropTypes.func,
alterNode: PropTypes.func,
html: PropTypes.string,
uri: PropTypes.string,
tagsStyles: PropTypes.object,
classesStyles: PropTypes.object,
containerStyle: ViewPropTypes ? ViewPropTypes.style : View.propTypes.style,
customWrapper: PropTypes.func,
onLinkPress: PropTypes.func,
onParsed: PropTypes.func,
imagesMaxWidth: PropTypes.number,
staticContentMaxWidth: PropTypes.number,
imagesInitialDimensions: PropTypes.shape({
width: PropTypes.number,
height: PropTypes.number
}),
emSize: PropTypes.number.isRequired,
ptSize: PropTypes.number.isRequired,
baseFontStyle: PropTypes.object.isRequired,
textSelectable: PropTypes.bool,
renderersProps: PropTypes.object,
allowFontScaling: PropTypes.bool
}
// static propTypes = {
// renderers: PropTypes.object.isRequired,
// ignoredTags: PropTypes.array.isRequired,
// ignoredStyles: PropTypes.array.isRequired,
// allowedStyles: PropTypes.array,
// decodeEntities: PropTypes.bool.isRequired,
// debug: PropTypes.bool.isRequired,
// listsPrefixesRenderers: PropTypes.object,
// ignoreNodesFunction: PropTypes.func,
// alterData: PropTypes.func,
// alterChildren: PropTypes.func,
// alterNode: PropTypes.func,
// html: PropTypes.string,
// uri: PropTypes.string,
// tagsStyles: PropTypes.object,
// classesStyles: PropTypes.object,
// containerStyle: ViewPropTypes ? ViewPropTypes.style : View.propTypes.style,
// customWrapper: PropTypes.func,
// onLinkPress: PropTypes.func,
// onParsed: PropTypes.func,
// imagesMaxWidth: PropTypes.number,
// staticContentMaxWidth: PropTypes.number,
// imagesInitialDimensions: PropTypes.shape({
// width: PropTypes.number,
// height: PropTypes.number
// }),
// emSize: PropTypes.number.isRequired,
// ptSize: PropTypes.number.isRequired,
// baseFontStyle: PropTypes.object.isRequired,
// textSelectable: PropTypes.bool,
// renderersProps: PropTypes.object,
// allowFontScaling: PropTypes.bool
// }

static defaultProps = {
renderers: HTMLRenderers,
Expand Down Expand Up @@ -142,7 +141,7 @@ export default class HTML extends PureComponent {
loadingRemoteURL: true,
errorLoadingRemoteURL: false
})
let response = await fetch(uri)
const response = await fetch(uri)
this.setState({ dom: response._bodyText, loadingRemoteURL: false })
} catch (err) {
console.warn(err)
Expand Down Expand Up @@ -238,11 +237,11 @@ export default class HTML extends PureComponent {
TEXT_TAGS_IGNORING_ASSOCIATION.indexOf(child.parent.name) === -1)
) {
// Texts outside <p> or not <p> themselves (with siblings)
let wrappedTexts = []
const wrappedTexts = []
for (let j = i; j < children.length; j++) {
// Loop on its next siblings and store them in an array
// until we encounter a block or a <p>
let nextSibling = children[j]
const nextSibling = children[j]
if (
nextSibling.wrapper !== 'Text' ||
TEXT_TAGS_IGNORING_ASSOCIATION.indexOf(nextSibling.tagName) !== -1
Expand Down Expand Up @@ -292,7 +291,7 @@ export default class HTML extends PureComponent {
tagsStyles,
classesStyles
} = props
let RNElements = DOMNodes.map((node, nodeIndex) => {
const RNElements = DOMNodes.map((node, nodeIndex) => {
let { children, data } = node
if (ignoreNodesFunction && ignoreNodesFunction(node, parentTag) === true) {
return false
Expand Down Expand Up @@ -436,7 +435,7 @@ export default class HTML extends PureComponent {
...cssStringToObject(attribs.style || '')
}

let textChildrenInheritedStyles = {}
const textChildrenInheritedStyles = {}
Object.keys(wrapperStyles).forEach(styleKey => {
// Extract text-only styles
if (TextOnlyPropTypes.indexOf(styleKey) !== -1) {
Expand Down
80 changes: 59 additions & 21 deletions src/components/image/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@
* 5. 错误处理
* 6. 自动选择Bangumi图片质量
* 7. 联动ImageViewer
* 8. 支持 @magma 提供的 [bgm_poster] 后缀
*
* @Author: czy0729
* @Date: 2019-03-15 06:17:18
* @Last Modified by: czy0729
* @Last Modified time: 2022-05-08 01:41:21
* @Last Modified time: 2022-05-09 17:08:02
*/
import React from 'react'
import { View, Image as RNImage } from 'react-native'
Expand All @@ -31,11 +33,13 @@ import { Text } from '../text'
import CompImage from './image'
import { memoStyles } from './styles'
import { Props } from './types'
import { getTimestamp } from '@utils'

const defaultHeaders = {
const DEFAULT_HEADERS = {
Referer: `${HOST}/`
}
const maxErrorCount = 2 // 最大失败重试次数
const MAX_ERROR_COUNT = 4 // 最大失败重试次数
const RETRY_DISTANCE = 4000 // 重试间隔

export const Image = observer(
class extends React.Component<Props> {
Expand Down Expand Up @@ -153,24 +157,32 @@ export const Image = observer(
}

res = CacheManager.get(_src, {
// @ts-ignore
headers: this.headers
}).getPath()
const path = await res
this.setState({
uri: path || _src
})

/**
* magma的cdn要单独对第一次对象存储镜像做延迟处理
* 需要再重新请求一遍
* @date 202205009
*/
if (
typeof _src === 'string' &&
_src.includes('/bgm_poster') &&
path === undefined
) {
setTimeout(() => {
this.retry(src)
}, RETRY_DISTANCE)
} else {
this.setState({
uri: path || _src
})
}
}
} catch (error) {
// 图片是不是会下载失败, 当错误次数大于maxErrorCount就认为是错误
if (this.errorCount < maxErrorCount) {
this.timeoutId = setTimeout(() => {
this.errorCount += 1
this.cache(src)
}, 400)
} else {
this.timeoutId = null
this.onError()
}
this.retry(src)
}
} else {
uri = src
Expand All @@ -192,6 +204,21 @@ export const Image = observer(
return res
}

/**
* 图片是不是会下载失败, 当错误次数大于MAX_ERROR_COUNT就认为是错误
*/
retry = src => {
if (this.errorCount < MAX_ERROR_COUNT) {
this.timeoutId = setTimeout(() => {
this.errorCount += 1
this.cache(src)
}, 400)
} else {
this.timeoutId = null
this.onError()
}
}

/**
* 选择图片质量
*/
Expand Down Expand Up @@ -236,6 +263,14 @@ export const Image = observer(
* 加载失败
*/
onError = () => {
const { src } = this.props
if (!IOS && typeof src === 'string' && src.includes('/bgm_poster')) {
setTimeout(() => {
this.retry(`${src}?ts=${getTimestamp()}`)
}, RETRY_DISTANCE)
return
}

this.setState(
{
error: true
Expand All @@ -247,17 +282,20 @@ export const Image = observer(
)
}

get headers() {
get headers(): {} {
const { src, headers } = this.props
if (headers) {
return {
...defaultHeaders,
...headers
if (typeof src === 'string' && src.includes('lain.')) {
return {
...DEFAULT_HEADERS,
...(headers || {})
}
}
return headers
}

if (typeof src === 'string' && src.includes('lain.')) {
return defaultHeaders
return DEFAULT_HEADERS
}

return {}
Expand Down
39 changes: 16 additions & 23 deletions src/components/switch-pro/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,37 +4,30 @@
* @Author: czy0729
* @Date: 2020-06-24 22:32:09
* @Last Modified by: czy0729
* @Last Modified time: 2022-05-07 13:06:06
* @Last Modified time: 2022-05-09 13:26:17
*/
import React, { Component } from 'react'
import PropTypes from 'prop-types'
import {
ViewPropTypes,
ColorPropType,
Animated,
Easing,
PanResponder
} from 'react-native'
import { Animated, Easing, PanResponder } from 'react-native'
import { observer } from 'mobx-react'
import { _ } from '@stores'

const SCALE = 6 / 5

class SwitchProComp extends Component<any, any> {
static propTypes = {
style: ViewPropTypes.style,
circleStyle: ViewPropTypes.style,
width: PropTypes.number,
height: PropTypes.number,
value: PropTypes.bool,
disabled: PropTypes.bool,
circleColorActive: ColorPropType,
circleColorInactive: ColorPropType,
backgroundActive: ColorPropType,
backgroundInactive: ColorPropType,
onAsyncPress: PropTypes.func,
onSyncPress: PropTypes.func
}
// static propTypes = {
// style: ViewPropTypes.style,
// circleStyle: ViewPropTypes.style,
// width: PropTypes.number,
// height: PropTypes.number,
// value: PropTypes.bool,
// disabled: PropTypes.bool,
// circleColorActive: ColorPropType,
// circleColorInactive: ColorPropType,
// backgroundActive: ColorPropType,
// backgroundInactive: ColorPropType,
// onAsyncPress: PropTypes.func,
// onSyncPress: PropTypes.func
// }

static defaultProps = {
width: 52,
Expand Down
Loading

0 comments on commit a295613

Please sign in to comment.