Skip to content
This repository has been archived by the owner on Jul 28, 2023. It is now read-only.

Commit

Permalink
Add trigger callback for highlight animation
Browse files Browse the repository at this point in the history
Pass the callback to the child method up the component hierarchy, via a
"trigger method", so the mobile banner can call the method for the
animation when it shows the fullpage banner.

Add explicitly evaluated spaces to TextHighlight child text to
circumvent [JSX space-eating behavior][1].

[1]: facebook/react#4134
  • Loading branch information
gbirke committed Oct 21, 2019
1 parent 07da0a4 commit 3d95c16
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 19 deletions.
13 changes: 7 additions & 6 deletions wikipedia.de_prototype/TODO.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
# TODOs

- [ ] Highlight animation only in mobile banner
- [ ] Scroll in from top
- [ ] Lightbox
- [ ] Lightbox for Application of Funds (on Desktop)
- [ ] Adjust mobile slides accoring to the criteria for CTRL in https://phabricator.wikimedia.org/T235728

## For Usage on wp.org:
- [ ] Make CSS localized by prepending all CSS with ID, or using
[newfangled stuff](https://github.com/css-modules/css-modules),
[CSS modules](https://github.com/css-modules/css-modules),
see [this article](https://medium.com/trabe/using-bem-conventions-in-css-modules-leveraging-custom-webpack-loaders-fd985f72bcb2)
to learn how to combine BEM notation and CSS modules
- [ ] Progress bar
- [ ] Mediawiki-Skin dependent banner space reservation (see `shared/skin` classes)
- [ ] Mediawiki-Skin dependent banner space reservation (see `shared/skin` classes)
- [ ] initial delay and scroll-in. For that, maybe the `bannerVisible` property needs to be split in two: One for actual visibility and one for when the banner is "ready" (i.e. completely scrolled down). This will become important for when animations should start when the banner is fully in view (e.g. progress bar)
- [ ] Progress bar. (starting only when `bannerVisible` property switches from false to true)

12 changes: 9 additions & 3 deletions wikipedia.de_prototype/banners/MobileBanner.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import MobileBannerFullpage from './MobileBannerFullpage';
export default class MobileBanner extends Component {
constructor(props) {
super(props);
this.state = { isFullPageVisible: false }
this.state = { isFullPageVisible: false };
this.animateHighLight = null;
}

componentDidMount() {
Expand All @@ -19,9 +20,14 @@ export default class MobileBanner extends Component {

showForm = e => {
this.props.trackingData.eventTracker.trackEvent( 'mobile-mini-banner-expanded', this.props.trackingData.bannerClickTrackRatio );
this.setState( { isFullPageVisible: true } )
this.setState( { isFullPageVisible: true } );
if ( this.animateHighLight ) {
this.animateHighLight();
}
};

animateHighlightTrigger = cb => { this.animateHighLight = cb };

render( props, state, context ) {
return <Fragment>
<div className={ classNames('mini-banner', { 'is-hidden': this.state.isFullPageVisible || !props.bannerVisible } ) }>
Expand Down Expand Up @@ -67,7 +73,7 @@ export default class MobileBanner extends Component {
</div>
</div>
</div>
<MobileBannerFullpage {...props} isFullPageVisible={this.state.isFullPageVisible}/>
<MobileBannerFullpage {...props} isFullPageVisible={this.state.isFullPageVisible} animateHighlightTrigger={ this.animateHighlightTrigger }/>
</Fragment>
}

Expand Down
4 changes: 3 additions & 1 deletion wikipedia.de_prototype/banners/MobileBannerFullpage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ export default function MobileBannerFullpage( props ) {
numberOfDonors={props.numberOfDonors}
campaignDaySentence={props.campaignDaySentence}
weekdayPrepPhrase={props.weekdayPrepPhrase}
currentDayName={props.currentDayName}/>
currentDayName={props.currentDayName}
animateHighlightTrigger={props.animateHighlightTrigger}
/>
<div className="call-to-action">
Jetzt sind Sie <span className="call-to-action__optional-text">in Deutschland</span> gefragt.
</div>
Expand Down
7 changes: 5 additions & 2 deletions wikipedia.de_prototype/components/Infobox.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ function capitalizeFirstLetter( message ) {
return message.charAt( 0 ).toUpperCase() + message.slice( 1 );
}

export default function Infobox( { weekdayPrepPhrase, currentDayName, amountBannerImpressionsInMillion, numberOfDonors, campaignDaySentence } ) {
export default function Infobox( props ) {
const { weekdayPrepPhrase, currentDayName, amountBannerImpressionsInMillion, numberOfDonors, campaignDaySentence, animateHighlightTrigger } = props;
return <div className="infobox__text">
<p className="text__headline">
<span className="text__headline--bold">Liebe Leserinnen und Leser,</span>
Expand All @@ -19,7 +20,9 @@ export default function Infobox( { weekdayPrepPhrase, currentDayName, amountBann
{campaignDaySentence} Wikipedia wird durch Spenden von durchschnittlich 21,48&nbsp;€ finanziert, aber
99&nbsp;% der Leserinnen und Leser spenden nicht.

<TextHighlight>Wenn alle, die das jetzt lesen, einen kleinen Beitrag leisten, wäre unser Spendenziel bereits am heutigen { currentDayName } erreicht.</TextHighlight>
<TextHighlight animateHighlightTrigger={animateHighlightTrigger}>
{' '}Wenn alle, die das jetzt lesen, einen kleinen Beitrag leisten, wäre unser Spendenziel bereits am heutigen { currentDayName } erreicht.{' '}
</TextHighlight>

Schon der Preis einer Tasse Kaffee würde genügen.
Über {amountBannerImpressionsInMillion} Millionen Mal wird unser Spendenaufruf täglich angezeigt,
Expand Down
5 changes: 1 addition & 4 deletions wikipedia.de_prototype/components/Infobox.pcss
Original file line number Diff line number Diff line change
Expand Up @@ -106,17 +106,14 @@
margin: 0;
padding: 0;
display: inline;
/* TODO move to highlight.pcss and make it responsive */
&--highlight {
font-weight: bold;
padding: 0 .3em;
.marked {
border: 0 none;
background: $color-text-highlight;
font-weight: bold;
color: $color-dark;
margin: 0 -0.3em;
padding: 0 0.3em;

}
}
&--italic {
Expand Down
12 changes: 9 additions & 3 deletions wikipedia.de_prototype/components/TextHighlight.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,14 @@ export default class TextHighlight extends Component {
componentDidMount() {
const plainText = toChildArray( this.props.children ).reduce( ( t, child ) => typeof child === 'string' ? t + child : t, '' );
this.setState( { highlightedText: '', plainText } );
if ( this.props.animateHighlightTrigger ) {
this.props.animateHighlightTrigger( this.animateHighlight.bind(this) );
}
}

// TODO watch bannerIsVisible property and start animation when banner is visible (instead of when it's mounted)
animateHighlight() {
const plainText = this.state.plainText;
const initialDelay = 1000; // should be synchronized with the CSS animation that drops down the banner
const duration = 1500;
const millisecondsPerChar = Math.max( 10, duration / plainText.length );
// TODO When duration / plainTextlength < 10, find slice size based on millisecondsPerChar
Expand All @@ -19,8 +25,8 @@ export default class TextHighlight extends Component {
if ( plainText ) {
this.highlightAnimation = setTimeout( animateSlice, millisecondsPerChar );
}
}
this.highlightAnimation = setTimeout( animateSlice, millisecondsPerChar )
};
this.highlightAnimation = setTimeout( animateSlice, initialDelay )
}

componentWillUnmount() {
Expand Down

0 comments on commit 3d95c16

Please sign in to comment.