Skip to content

Commit

Permalink
improved application loading performance
Browse files Browse the repository at this point in the history
  • Loading branch information
JulesG10 committed Jun 26, 2023
1 parent 711faca commit 9e9bc7c
Show file tree
Hide file tree
Showing 15 changed files with 228 additions and 124 deletions.
22 changes: 22 additions & 0 deletions android/app/src/main/java/com/fouflix/julesg10/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;
import android.view.Window;
import android.view.WindowManager;
import android.webkit.CookieManager;
import android.webkit.WebSettings;
import android.webkit.WebView;
Expand All @@ -12,6 +15,7 @@
import androidx.core.content.pm.ShortcutInfoCompat;
import androidx.core.content.pm.ShortcutManagerCompat;
import androidx.core.graphics.drawable.IconCompat;
import androidx.core.view.WindowCompat;

import com.getcapacitor.BridgeActivity;
import com.getcapacitor.JSObject;
Expand All @@ -29,8 +33,26 @@ public class MainActivity extends BridgeActivity {
protected void onCreate(Bundle savedInstanceState) {
this.registerPlugin(FlouFlixPlugin.class);
super.onCreate(savedInstanceState);

int darkBg = Color.rgb(20,20,20);
this.getBridge().getWebView().setBackgroundColor(Color.TRANSPARENT);


Window window = this.getWindow();
window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
window.setStatusBarColor(darkBg);

WindowCompat.setDecorFitsSystemWindows(window, false);
window.setNavigationBarColor(Color.TRANSPARENT);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
window.setNavigationBarContrastEnforced(false);
}
window.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);

CastContext.getSharedInstance(this);


Intent intent = getIntent();
if(intent == null)
{
Expand Down
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@
</head>
<body>
<div id="root"></div>
<script type="module" src="/src/main.tsx" defer></script>
<script type="module" src="/src/main.tsx"></script>
</body>
</html>
101 changes: 100 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"type": "module",
"scripts": {
"dev": "vite",
"build": "vite build",
"build": "vite build && npx cap sync",
"preview": "vite preview"
},
"dependencies": {
Expand Down Expand Up @@ -33,6 +33,7 @@
"@types/react": "^18.0.27",
"@types/react-dom": "^18.0.10",
"@vitejs/plugin-react": "^3.1.0",
"vite": "^4.1.0"
"vite": "^4.1.0",
"vite-plugin-compression": "^0.5.1"
}
}
2 changes: 1 addition & 1 deletion src/components/CardDrawer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ const CardDrawer: React.FC<CardDrawerProps> = ({
<Image
src={item.image}
onError={(evt: any) => {
evt.target.src = "https://picsum.photos/720/480";
evt.target.src = "https://picsum.photos/420/280";
}}
w="100%"
h={"280px"}
Expand Down
3 changes: 2 additions & 1 deletion src/components/CardItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,11 @@ const CardItem: React.FC<CardItemProps> = ({ item, delay, openCard }) => {
}}
onLoad={(evt: any)=>{
setShowImage(true);

}}
filter={imageShow ? "blur(0px)" : "blur(100px)"}
borderRadius="lg"
transition={"300ms"}
transition={"600ms"}
w="100%"
h={"280px"}
objectFit={"cover"}
Expand Down
6 changes: 6 additions & 0 deletions src/components/CreateDrawer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ const EditDrawer: React.FC<EditDrawerProps> = ({
url: undefined,
index: -1,
});
const [imageShow, setShowImage] = React.useState<boolean>(false);

React.useEffect(() => {
if (!isCreateOpen) {
Expand Down Expand Up @@ -183,7 +184,12 @@ const EditDrawer: React.FC<EditDrawerProps> = ({
onError={(evt: any) => {
evt.target.src = "https://picsum.photos/720/480";
}}
onLoad={(evt: any) => {
setShowImage(true);
}}
filter={imageShow ? "blur(0px)" : "blur(100px)"}
borderRadius="lg"
transition={"300ms"}
w="100%"
h={"280px"}
objectFit={"cover"}
Expand Down
12 changes: 0 additions & 12 deletions src/components/Loading.tsx

This file was deleted.

30 changes: 16 additions & 14 deletions src/components/ScrollCards.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
import React from "react";
import { Box } from "@chakra-ui/react";
import { FlouFlix } from '../plugin/index';
import { useNetwork } from '../hooks/useNetwork';
import { Item, storage } from '../api/storage';
import { useNavigate } from "react-router-dom";
import { Box } from "@chakra-ui/react";
import { Capacitor } from "@capacitor/core";
import { StatusBar } from "@capacitor/status-bar";
import { NavigationBar } from "@hugotomazi/capacitor-navigation-bar";

import CardItem from "./CardItem";
import { FlouFlix } from '../plugin/index';

import { useNetwork } from '../hooks/useNetwork';
import { Item, storage } from '../api/storage';


const CardItem = React.lazy(() => import("./CardItem"));

type ScrollCardsProps ={
type ScrollCardsProps = {
setShowBorder: (show: boolean) => void;
setCardOpen: (open: boolean) => void;
setCreateOpen: (open: boolean) => void;
Expand Down Expand Up @@ -60,22 +63,21 @@ const ScrollCards: React.FC<ScrollCardsProps> = ({

FlouFlix.addListener("onTextDataShared", (data) => {
setCreateOpen(false);
if (data.text != null)
{
if (data.text != null) {
storage.extractVideo(data.text).then(async video => {
await storage.createItem({
title: data.text,
videos: [storage.createVideoItem(data.text ?? "", video)]
})
storage.getItems().then((items) => setItems(items))
}).catch(() => { })

} else if (data.file != null) {

storage.parseFile(data.file.split("\n")).then(() => {
storage.getItems().then((items) => setItems(items))
}).catch(() => { })

}
})

Expand Down Expand Up @@ -112,7 +114,7 @@ const ScrollCards: React.FC<ScrollCardsProps> = ({
}
}}
>
<React.Fragment>
<React.Suspense>
{items.map((it, index) => (
<CardItem
key={index}
Expand All @@ -124,11 +126,11 @@ const ScrollCards: React.FC<ScrollCardsProps> = ({
}}
/>
))}
</React.Fragment>
</React.Suspense>

<Box w="100%" h="40px"></Box>
</Box>
);
}

export default ScrollCards;
export default ScrollCards;
1 change: 1 addition & 0 deletions src/components/Topbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const Topbar: React.FC<TopBarProps> = ({ title, showBorder, icons }) => {
return (
<Flex
padding={5}
paddingTop={10}
columnGap={5}
justifyContent="space-between"
borderBottom={"2px solid"}
Expand Down
24 changes: 8 additions & 16 deletions src/main.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,12 @@
import React from 'react';
import ReactDOM from 'react-dom/client';

import { ChakraProvider, extendTheme } from '@chakra-ui/react';
import App from './pages/App';

const theme= extendTheme({})

const root = document.getElementById('root');
if(root)
{
ReactDOM.createRoot(root).render(
<React.StrictMode>
<ChakraProvider theme={theme}>
<App />
</ChakraProvider>
</React.StrictMode>,
)
}
import('./pages/App').then((app)=>{
ReactDOM.createRoot(document.getElementById('root') ?? document.createElement("div"))
.render(
<React.StrictMode>
<app.default />
</React.StrictMode>,
)
})

Loading

0 comments on commit 9e9bc7c

Please sign in to comment.