question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

cannot use custom font from local file

See original GitHub issue

@iou90

Hello ! I am using your library on ios

I have this component

import React,{Component} from 'react';
import {View,ActivityIndicator,Dimensions} from 'react-native';
import AutoHeightWebView from 'react-native-autoheight-webview';

class DynamicWebView extends Component
    {
        constructor(props)
            {
                super(props);
                this.state = 
                    {
                        height: 0
                    }
                this.mycontext = this.props.context;
            }
        onWebViewMessage = (size) =>
            {
                if(size.height > 0)
                    {
                        this.mycontext.setState({height: parseInt(size.height)});
                        this.setState({height: parseInt(size.height)})
                    }
            }
        render()
            {
                let wrapperStyle = this.props.wrapperStyle || " style='direction:rtl;font-size: 19px;font-family: ae_AlArabiya;color: #666666;padding: 7px;'";
                let content = this.props.content || '';
                let style = this.props.style || {};
                let height = this.state.height && parseInt(this.state.height)>=0?this.state.height:200;
                let css = `<style type="text/css"> @font-face {font-family: ae_AlArabiya; src:url(file:///assets/fonts/ae_AlArabiya.ttf);} *{font-family: ae_AlArabiya}</style>`;
                return(<AutoHeightWebView
                    style={[{ width: Dimensions.get('window').width, marginTop: 35,backgroundColor: '#ffffff'},style]}
                    customStyle={`@font-face {font-family: ae_AlArabiya;src:url(file:///assets/fonts/ae_AlArabiya.ttf);} * {font-family: ae_AlArabiya;}`}
                    onSizeUpdated={(size) => {this.onWebViewMessage(size);}}
                    source={{html:  css + "<div" + wrapperStyle + ">"+ content + "</div>"}}
                    zoomable={false}
                    baseUrl=""
                    startInLoadingState={true}
                    renderLoading={() => <ActivityIndicator />}
                    />);
            }
    }
export default DynamicWebView;

i tried all ways to make my webview use font ae_AlArabiya but without any success.

Note : This was succeeded for normal react-native -webview

I attached a zip file that contains the font

Hope that their is any solution

Thank you in advance for any regards !

ae_AlArabiya.ttf.zip

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
iou90commented, Dec 2, 2019

@tapannathvani @sislovesmedotcom Now the local custom font example is included within the demo.

2reactions
lamaj411commented, Sep 10, 2020

anybody can share some example code here, i checked the demo, but i cant understand bcz i am not an expert, please help me…

Read more comments on GitHub >

github_iconTop Results From Across the Web

How To Load and Use Custom Fonts with CSS | DigitalOcean
Once you have downloaded the file, extract the fonts directory contained in the zip file and place it in the same directory as...
Read more >
Cannot embed custom font from local file · Issue #372 - GitHub
Hi, I'm trying to set a custom font from a local file as it was shown in examples. ... Cannot embed custom font...
Read more >
Custom font (fontface) not working when published
If the font works locally but not when on the server then you need to check the path to the font file. Inspect...
Read more >
How to use @font-face in CSS
The @font-face rule allows custom fonts to be loaded on a webpage. Once added to a stylesheet, the rule instructs the browser to...
Read more >
font-face - CSS: Cascading Style Sheets - MDN Web Docs
Chrome Edge @font‑face Full support. Chrome1. Toggle history Full support... OpenType CBDT and CBLC rendering Full support. Chrome66. Toggle history Full support... OpenType COLRv0 rendering Full...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found