Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…a-react into refactor-code
  • Loading branch information
amitojsingh committed Aug 29, 2022
2 parents 5dbabd0 + 90506f3 commit f4b25d7
Show file tree
Hide file tree
Showing 4 changed files with 178 additions and 158 deletions.
54 changes: 25 additions & 29 deletions screens/Reader.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@ class Reader extends React.Component {
}

componentWillUnmount() {
// this.setState = (state, callback) => {
// return;
// };
this.setState = (state, callback) => {
return;
};
}

handleBackPress = () => {
Expand Down Expand Up @@ -146,14 +146,13 @@ class Reader extends React.Component {
}

toggleHeader(state) {
const value = state === "hide" ? HEADER_POSITION : 0;
const { animationPosition } = this.state;
Animated.timing(animationPosition, {
duration: this.slideDuration,
useNativeDriver: false,
toValue: state === "hide" ? HEADER_POSITION : 0,
toValue: value,
}).start();

StatusBar.setHidden(state === "hide", "fade");
}

loadShabad() {
Expand Down Expand Up @@ -190,7 +189,7 @@ class Reader extends React.Component {
});
})
.catch((error) => {
console.log(error);
console.error(error);
});
}

Expand All @@ -209,7 +208,6 @@ class Reader extends React.Component {
if (data[i].id <= index) {
viewPosition = index;
}

if (data[i].id === index) {
break;
}
Expand Down Expand Up @@ -247,15 +245,15 @@ class Reader extends React.Component {
}`;

html +=
`"body { " + "background-color: "}${nightMode ? "#000" : "#fff"};` +
`${"body { " + "background-color: "}${nightMode ? "#000" : "#fff"};` +
`word-break: break-word;` +
`color: ${nightMode ? "#fff" : "#000"};` +
`padding-top: ${headerHeight}px; }`;

html += "* { -webkit-user-select: none; }";
html += `</style><script>${this.loadScrollJS()} </script>`;
html += "</head><body>";
data.forEach((item) => {
data.forEach(function (item) {
let textAlign = "left";
switch (item.header) {
case 0:
Expand Down Expand Up @@ -383,7 +381,7 @@ class Reader extends React.Component {
return (window.pageYOffset / (document.body.scrollHeight - window.innerHeight));
}
// Listen for scroll events
// Listen for scroll events
window.addEventListener('scroll', function ( event ) {
// Clear our timeout throughout the scroll
window.clearTimeout( isScrolling );
Expand Down Expand Up @@ -454,7 +452,7 @@ class Reader extends React.Component {
});
window.addEventListener('touchend', function() {
if(autoScrollSpeed != 0 && autoScrollTimeout == null) {
setAutoScroll();
setAutoScroll();
}
if(!dragging && !holding)
{
Expand All @@ -481,9 +479,7 @@ class Reader extends React.Component {
autoScrollSpeed = message.autoScroll;
scrollMultiplier = message.scrollMultiplier;
if(autoScrollTimeout == null) {
setAutoScroll();
}
}
}, false);
`;
Expand Down Expand Up @@ -557,14 +553,19 @@ class Reader extends React.Component {
backgroundColor: "transparent",
},
});
const {
READER_STATUS_BAR_COLOR_NIGHT_MODE,
READER_STATUS_BAR_COLOR,
READER_HEADER_COLOR,
TOOLBAR_TINT,
READER_FOOTER_COLOR,
} = GLOBAL.COLOR;
return (
<View
style={[styles.container, nightMode && { backgroundColor: "#000" }]}
// eslint-disable-next-line react/jsx-no-bind
onLayout={this.onLayout.bind(this)}
>
<LoadingIndicator isLoading={isLoading} />

<WebView
originWhitelist={["*"]}
style={nightMode && { backgroundColor: "#000" }}
Expand All @@ -579,28 +580,24 @@ class Reader extends React.Component {
// eslint-disable-next-line react/jsx-no-bind
onMessage={this.handleMessage.bind(this)}
/>

<Animated.View style={[styles.header, { position: "absolute", top: animationPosition }]}>
<StatusBar
backgroundColor={
nightMode
? GLOBAL.COLOR.READER_STATUS_BAR_COLOR_NIGHT_MODE
: GLOBAL.COLOR.READER_STATUS_BAR_COLOR
nightMode ? READER_STATUS_BAR_COLOR_NIGHT_MODE : READER_STATUS_BAR_COLOR
}
barStyle={nightMode || Platform.OS === "android" ? "light-content" : "dark-content"}
/>
<Header
backgroundColor={GLOBAL.COLOR.READER_HEADER_COLOR}
backgroundColor={READER_HEADER_COLOR}
containerStyle={[Platform.OS === "android" && { height: 86, paddingTop: 0 }]}
onLayout={(event) => {
this.headerHeight = event.nativeEvent.layout.height;
}}
leftComponent={
<Icon
name="arrow-back"
color={GLOBAL.COLOR.TOOLBAR_TINT}
color={TOOLBAR_TINT}
size={30}
// eslint-disable-next-line react/jsx-no-bind
onPress={this.handleBackPress.bind(this)}
/>
}
Expand All @@ -609,7 +606,7 @@ class Reader extends React.Component {
? this.truncate.apply(params.item.translit, [24])
: this.truncate.apply(params.item.gurmukhi, [25]),
style: {
color: GLOBAL.COLOR.TOOLBAR_TINT,
color: TOOLBAR_TINT,
fontFamily: transliteration ? null : fontFace,
fontSize: 20,
},
Expand All @@ -618,7 +615,7 @@ class Reader extends React.Component {
<View style={{ flexDirection: "row" }}>
<Icon
name="settings"
color={GLOBAL.COLOR.TOOLBAR_TINT}
color={TOOLBAR_TINT}
size={30}
onPress={() => {
const autoScrollSpeed = {
Expand All @@ -635,7 +632,7 @@ class Reader extends React.Component {
<Icon
style={{ paddingLeft: 15 }}
name="bookmark"
color={GLOBAL.COLOR.TOOLBAR_TINT}
color={TOOLBAR_TINT}
size={30}
onPress={() => {
this.trackScreenForShabad(params);
Expand All @@ -646,7 +643,6 @@ class Reader extends React.Component {
}
/>
</Animated.View>

{autoScroll && (
<Animated.View
style={[
Expand All @@ -655,7 +651,7 @@ class Reader extends React.Component {
position: "absolute",
bottom: animationPosition,
paddingBottom: 25,
backgroundColor: GLOBAL.COLOR.READER_FOOTER_COLOR,
backgroundColor: READER_FOOTER_COLOR,
},
]}
>
Expand Down
11 changes: 11 additions & 0 deletions utils/constant.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,15 @@ export default {
HOME_SCREEN: "Home Screen",
GURBANI_AKHAR_HEAVY_TRUE: "GurbaniAkharHeavyTrue",
SETTINGS: "Settings",
EXTRA_LONG: "EXTRA_LONG",
LONG: "LONG",
SHORT: "SHORT",
EXISTS_BUDDHA_DAL: "existsBuddhaDal",
EXISTS_TAKSAL: "existsTaksal",
EXISTS_MEDIUM: "existsMedium",
EXISTS_SGPS: "existsSGPC",
DB: "gutka.db",
VISHRAAM_GRADIENT: "VISHRAAM_GRADIENT",
VISHRAAM_COLORED: "VISHRAAM_COLORED",
MAST_SABH_MAST: "MAST_SABH_MAST",
};
Loading

0 comments on commit f4b25d7

Please sign in to comment.