Skip to content
This repository has been archived by the owner on Apr 2, 2021. It is now read-only.

tmp #208

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

tmp #208

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ configurations.all {
}

dependencies {
implementation project(':react-native-video')
implementation project(':react-native-webview')
implementation project(':react-native-rsa-native')
implementation fileTree(dir: "libs", include: ["*.jar"])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import android.content.Context;
import com.facebook.react.PackageList;
import com.facebook.react.ReactApplication;
import com.brentvatne.react.ReactVideoPackage;
import com.reactnativecommunity.webview.RNCWebViewPackage;
import com.RNRSA.RNRSAPackage;

Expand Down
2 changes: 2 additions & 0 deletions android/settings.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
rootProject.name = 'shockwallet'
include ':react-native-video'
project(':react-native-video').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-video/android')
include ':react-native-webview'
project(':react-native-webview').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-webview/android')
include ':react-native-rsa-native'
Expand Down
39 changes: 23 additions & 16 deletions app/components/Post/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react'
import { View, Text, StyleSheet, Dimensions } from 'react-native'
import { View, Text, StyleSheet } from 'react-native'
// @ts-ignore
import Carousel from 'react-native-smart-carousel'
import * as Common from 'shock-common'
Expand All @@ -10,16 +10,16 @@ import * as Common from 'shock-common'
import * as CSS from '../../res/css'

import UserInfo from './UserInfo'

const { width } = Dimensions.get('window')
import ShockWebView from '../ShockWebView'

/**
* @typedef {object} Props
* @prop {Common.Schema.User} author
* @prop {number} date
* @prop {{ id: string , text: string}[]} paragraphs
* @prop {{id: string , data: string }[]} images
* @prop {ScrollView} parentScrollViewRef
* @prop {{id: string , data: string,width:number,height:number }[]} images
* @prop {{id: string , data: string,width:number,height:number }[]} videos
* @prop {ScrollView=} parentScrollViewRef
*/

/**
Expand All @@ -30,13 +30,14 @@ const Post = ({
date,
paragraphs = [],
images = [],
parentScrollViewRef,
videos = [],
//parentScrollViewRef,
}) => {
const carouselWidth = Math.round(width) - 20
/*const carouselWidth = Math.round(width) - 20
const dataCarousel = images.map(image => ({
id: image.id,
imagePath: image.data,
}))
}))*/

return ((
<View style={styles.postContainer}>
Expand All @@ -46,14 +47,20 @@ const Post = ({
{paragraph.text}
</Text>
))}
{dataCarousel.length > 0 && (
<Carousel
width={carouselWidth}
data={dataCarousel}
navigationType="dots"
navigationColor={CSS.Colors.BUTTON_BLUE}
navigation
parentScrollViewRef={parentScrollViewRef}
{videos.length > 0 && (
<ShockWebView
type="video"
width={videos[0].width}
height={videos[0].height}
magnet={videos[0].data}
/>
)}
{videos.length === 0 && images.length > 0 && (
<ShockWebView
type="image"
width={images[0].width}
height={images[0].height}
magnet={images[0].data}
/>
)}
</View>
Expand Down
17 changes: 13 additions & 4 deletions app/components/ShockWebView/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,16 @@ import notificationService from '../../../notificationService'

export default class ShockWebView extends React.Component {
render() {
const { width, height, magnet } = this.props
const { width, height, magnet,type } = this.props
const playerString = type === 'video' ?
`<video id="player" style="width:100%"></video>` :
`<img id="player" style="width:100%"></img>`
const fileExtension = type === 'video' ?
`(file.name.endsWith('.mp4') || file.name.endsWith('.webm'))` :
`(file.name.endsWith('.jpg') || file.name.endsWith('.png'))`
const domID = type === 'video' ?
`video#player` :
`img#player`
return (
<WebView
// eslint-disable-next-line
Expand Down Expand Up @@ -32,7 +41,7 @@ export default class ShockWebView extends React.Component {
</head>
<body style="margin:0;padding:0">

<video id="player" style="width:100%"></video>
${playerString}

<script src="https://cdn.jsdelivr.net/npm/webtorrent@latest/webtorrent.min.js"></script>
<script type="text/javascript">
Expand All @@ -50,10 +59,10 @@ export default class ShockWebView extends React.Component {
client.add(torrentId, function (torrent) {
// Torrents can contain many files. Let's use the .mp4 file
var file = torrent.files.find(function (file) {
return file.name.endsWith('.mp4')
return ${fileExtension}
})
//file.appendTo('body') // append the file to the DOM
file.renderTo('video#player')
file.renderTo('${domID}')
})
</script>
</body>
Expand Down
Loading